On this page

Introduction

Introduction — Schema Stitching documentation.

flowchart TD
  client["<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 120 66' width='64' height='36' aria-hidden='true'><path fill='currentColor' fill-rule='evenodd' d='M26 2h68a4 4 0 0 1 4 4v34a4 4 0 0 1-4 4H26a4 4 0 0 1-4-4V6a4 4 0 0 1 4-4zM32 8h56a2 2 0 0 1 2 2v26a2 2 0 0 1-2 2H32a2 2 0 0 1-2-2V10a2 2 0 0 1 2-2zM8 46h104l6 14H2z'/></svg>"]
  gateway("GATEWAY (PROXY)<br/>SCHEMA")
  subA("SUBSCHEMA")
  subB("SUBSCHEMA")
  subC("SUBSCHEMA")

  client --> gateway
  gateway --> subA
  gateway --> subB
  gateway --> subC

  classDef box font-weight:700
  classDef icon fill:none,stroke:none
  class gateway,subA,subB,subC box
  class client icon

Schema stitching (@graphql-tools/stitch) creates a single GraphQL gateway schema from multiple underlying GraphQL services. Unlike schema merging, which simply combines local schema instances, stitching builds a combined proxy layer that delegates requests through to underlying service APIs. As of GraphQL Tools v7, stitching is fairly comparable to Apollo Federation with automated query planning, merged types, and declarative schema directives.

Schema stitching uses schema delegation instead of the regular local schema execution using resolvers.

Why Stitching?

One of the main benefits of GraphQL is that we can query for all data in a single request to one schema. As that schema grows though, it may become preferable to break it up into separate modules or microservices that can be developed independently. We may also want to integrate the schemas we own with third-party schemas, allowing mashups with external data.

In these cases, stitchSchemas is used to combine multiple GraphQL APIs into one unified gateway proxy schema that knows how to delegate parts of a request to the relevant underlying subschemas. These subschemas may be local GraphQL instances or APIs running on remote servers.

How to stitch?

There are three different approaches of stitching your schemas;

Learn more about the differences between them