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.
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
, andtoppings
are fields on thePizza
type. These are the fields that are allowed to appear in a GraphQL query that operates on thePizza
type. -
Int
andString
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 ...