How to define type for object in graphql schema?

by tressie.damore , in category: Javascript , 8 months ago

How to define type for object in graphql schema?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by dedrick , 8 months ago

@tressie.damore 

In GraphQL, you can define a custom object type using the following syntax in your schema definition file:

1
2
3
4
5
6
type MyObjectType {
  id: ID!
  name: String!
  age: Int!
  email: String
}


In the above example, MyObjectType is a custom object type that has four fields: id, name, age, and email. The ! after a type indicates that the field is required. You can also define nested object types by referencing other custom object types within the schema definition.


Once you have defined the object type in your schema, you can then use it in your queries and mutations to retrieve or manipulate data of that type.

Related Threads:

How to define an empty object type in a graphql schema?
How to define nested enum type in graphql schema?
How to add existing custom type to graphql schema?
How to use 'decimal' as a field type in graphql schema?
How to pass object type argument in query in graphql?
How to return complex object as scalar type in graphql?