...

/

Schema with Object Types and Fields

Schema with Object Types and Fields

Learn how the GraphQL server and the client communicate through object types and fields.

GraphQL object types and fields

Object types are the building blocks of GraphQL schema. They reflect available objects and fields from our server. Let’s check out our first GraphQL schema language.

Press + to interact
type Pizza {
id: Int!
pizza: String!
stock: Int!
toppings: [Topping!]!
}
type Topping {
id: Int!
topping: String!
}
  • Pizza is a GraphQL Object Type, which means that it’s a type with some fields. We’ll be dealing with object types the most.

  • id, name, stock, and toppings are fields on the Pizza type. These are the fields that are allowed to appear in a GraphQL query that operates on the Pizza type.

  • Int and String are the built-in scalar types in GraphQL. These are types that resolve to a scalar value and can’t have sub-selections in the query. We’ll go over scalar types later.

  • String! means that the field is non-nullable, meaning that the GraphQL service promises to always give us a value when we query ...