Skip to main content

Schema Stitching

In short this is a way to combine two or more GraphQL schemas together so that they can be queried from a single source.

The entry point is often know as a Gateway, and this proxies down to a number of sub schemas.

Schema stitching

The library that enables this was revamped in 2021 and contains more up to date features and whilst not the same as Federation, uses some of the same principles now. The Guild has taken over running the npm package @graphql-tool which handles nearlly all extensions of a GraphQL service.

One useful tool is type merging that allows querying of multiple subschemas which are then merged into the gateway to give a single result.

Take for example querying a Clubhouse. There is data saved in a CMS about opening times, address and a small description. But there are a series of rides that are saved in the Mobile app. We are able to do type merging to combine the results from each individualy sub schema.

The diagram below shows how each resource is requested.

Type Merging

Make sure to check out Batch merging when requesting arrays.

Overview

Pros

  • We dont have to write our own GraphQL schema for Contentful
  • Ability to add any given number of sub schemas
  • Almost zero config to get it up a running, just a simple node server

Cons

  • It's another GraphQL instance to manage
  • Type merging is repetative and can become confusing when using a lot of references