How to define type for object in graphql schema?

by tressie.damore , in category: Javascript , a month ago

How to define type for object in graphql schema?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by dedrick , a month 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.