In Gloo Mesh Gateway, you can surface multiple APIs into one unified service by creating a Gloo GraphQLStitchedSchema custom resource. Gloo Mesh Gateway uses this resource to generate a stitched schema, which incorporates all the types and fields from each subschema. When clients query the route for the stitched schema, Gloo Mesh Gateway creates requests to the individual services, and then stitches the responses back together into one response to the client. For more information, see What is GraphQL stitching?.

Merge GraphQL schema

For each API, define schema and select resolver services in your Gloo environment. Then, you can merge the GraphQL APIs together in a GraphQLStitchedSchema, and set up routing to this merged resolver.

  1. For each subschema, use the following guides to create individual CRs for each API that define its schema and resolvers.

    1. Define subschema in separate ApiDoc CRs. For the Bookinfo example, you might define three CRs for the product, reviews, and ratings services.
    2. Choose how GraphQL requests are executed, and follow the guides to either proxy requests to existing GraphQL backends or define REST, gRPC, or mock resolvers for each schema.
  2. Create one GraphQLStitchedSchema CR that references each GraphQL subschema. This example stitched schema for Bookinfo merges the GraphQL schema for each of the three APIs:

      apiVersion: apimanagement.gloo.solo.io/v2
    kind: GraphQLStitchedSchema
    metadata:
      name: bookinfo-stitched-schema
      namespace: bookinfo
    spec:
      subschemas:
      - schema:
          clusterName: $CLUSTER_NAME
          name: products-graphql-schema
          namespace: bookinfo
      - schema:
          clusterName: $CLUSTER_NAME
          name: ratings-graphql-schema
          namespace: bookinfo
      - schema:
          clusterName: $CLUSTER_NAME
          name: reviews-graphql-schema
          namespace: bookinfo
      
  3. Create a route table that routes to a graphql.stitchedSchema destination. Specify your stitched schema resoure name in the graphql.stitchedSchema.name field, such as stitched-graphql-schema in the following examples.

  4. Test routing to your stitched resolver setup.

Reference

For more information, see the Gloo Mesh Gateway API reference for the GraphQLStitchedSchema CR.