HomeToolsAbout a20k

Resolver Type

Query

query should define the entry point for any arbitrary graph node

  • This is located in the 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

Type Resolver

When an entire type is backed by a resolver, then we can conclude that each field is backed by a resolver.

Field Resolver

Field level resolvers are needed when the type resolver doesn't return data for all required fields.

  • Which fields are required would be defined by the client side query

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

Resolver Chain

GraphQL engine is responsible for collecting all data required for all fields.

  • Additional resolvers would be needed when the main resolver (type resolver) does not contain the field queried 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:

  • types input/return on client is different than server
  • default resolvers = entry point to query (base resolver)

you can create new query on the client side, but use the same entry point on server

© VincentVanKoh