query
should define the entry point for any arbitrary graph node
index.ts
schema { query: MyQuery mutation: MyMutation } type MyQuery { field1(id: ID!):Field field2: Field } type MyMutation { createField(field: UserInput!): Field! } type Field { id: ID! value: String! } input UserInput { text: String! }
Field resolver
vs Type resolver
Prefer the type resolver
pattern over field resolver
When an entire type is backed by a resolver, then we can conclude that each field is backed by a resolver.
Field level resolvers are needed when the type resolver
doesn't return data for all required fields.
It is important to note that field resolver
of the same field name may have a different type.
For example, User.name
may have a resolver type of Name
, but Pet.name
may have a resolver type of PetName
which has different shape than Name
type
GraphQL engine is responsible for collecting all data required for all fields.
undefined
These undefined
fields are then attempted to be resolved by field resolvers (if they are defined for missing fields)
All fields default to null
when neither the type resolver nor the field resolvers satisfy.
Because GQL separates the software layers and the query is flexible:
you can create new query on the client side, but use the same entry point on server