After you define the fields for your API schema, you can use GraphQL services that are deployed locally to the clusters in your Gloo environment to resolve these fields.

Define resolver servers in a GraphQLResolverMap

Recall that in the ApiDoc resource, you defined your schema, such as query and object types and their respective fields. Next, you must define the services you want to call to actually execute queries to these defined fields. However, because resolvers cannot be included in the GraphQL schema language, you define your field resolver services separately in a GraphQLResolverMap CR.

A GraphQLResolverMap configuration contains a mapping between each GraphQL field to a resolver configuration. A resolver is responsible for returning results from the backing service for the field that the resolver is mapped to. In Gloo Mesh Gateway, you can specify REST, gRPC, or mock resolver services to return data for each field. You can also apply any additional transformations to the query requests and responses. For example, you might define gRPC resolver services that exist in your Gloo Mesh Gateway cluster, and apply a JQ transformation to the response from one of the gRPC services.

Map schema fields to resolvers in a GraphQLSchema

After you define how resolvers should handle requests for each field, you can then map your schema in the ApiDoc to the resolvers in the GraphQLResolverMap by creating a GraphQLSchema Gloo CR. The GraphQLSchema creates the full picture of your GraphQL API as it is represented in Gloo Mesh Gateway.

Get started

To get started with resolvers, choose one of the following types of resolvers:

  • REST: Define REST resolvers in your Gloo environment to resolve each GraphQL schema field.
  • gRPC: Define schema in a gRPC ApiDoc, define gRPC resolvers in your Gloo environment to resolve schema fields, and map schema to resolvers.
  • Mock: For testing scenarios, configure a mock resolver that immediately returns a mocked response to queries.