Skip to main content

GraphQL Schema

Each GraphQLSchema requires a GraphQLObjectType as the root query type and optional GraphQLObjectTypes for the mutation and subscription roots.

You can provide a list of directive definitions (GraphQLDirectives) that can be used within the schema or by documents executed by the schema. The directives will be extended if any of the types or fields have a ToDirectiveValue attachment.

A GraphQLSchema has an optional description String that can be used as documentation and a SerdeCtx for deserialization of input types. The astNode (SchemaDefinitionNode) will be set when the schema is created with buildSchema.

To validate the schema definition, following the specification, you can use the validateSchema(GraphQLSchema) function which returns the List<GraphQLError> found during validation.

Resolvers

Each field in an object type can provide a resolve callback to return the value when a GraphQL operation is executed over the schema.

final nameField = field(
'name',
graphQLString,
resolve: (Object parentObject, Ctx ctx) => 'Example Name',
// or pass the subscribe parameter if it is a subscription.
// The return type should be a Stream
)

For a more thorough discussion about resolvers please see the resolvers section in the main Documentation.