Schema with Object Types and Fields
Explore how to build GraphQL schemas focusing on object types and fields. Understand the role of Apollo Server in setting up a GraphQL API, creating type definitions, resolvers, and running queries. This lesson guides you through a practical hands-on implementation of a GraphQL server using Node.js.
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.
-
Pizzais 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, andtoppingsare fields on thePizzatype. These are the fields that are allowed to appear in a GraphQL query that operates on thePizzatype. -
IntandStringare 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 this field. In the type language, we’ll represent this with an exclamation mark (!). -
[Topping!]!...