Guided examples of Schema Stitching doing awesome things. Focuses on the new (GraphQL Tools v6+) stitching using type merging, not legacy Apollo Stitching (opens in a new tab).
This handbook initially created by Greg MacWilliam (opens in a new tab)
Table of Contents
Foundation
-
Combining local and remote schemas
- Adding a locally-executable schema.
- Adding a remote schema, fetched via introspection.
- Adding a remote schema, fetched from a custom SDL service.
- Avoiding schema conflicts using transforms.
- Authorization headers.
- Basic error handling.
-
- Adding a remote mutation service.
- Adding a remote subscription service.
- Adding a subscriber proxy.
-
- Type merging using single-record queries.
- Query/execution batching.
-
- Type merging using array queries.
- Handling array errors.
- Nullability & error remapping.
-
Merged types with multiple keys
- Configuring multiple key entry points for a merged type.
-
- Selecting nullability for merged fields.
- Returning nullable and not-nullable results.
-
- Using
valuesFromResults
to normalize resulting query data. - Adapting type merging to query through namespaced scopes.
- Adapting type merging to query through non-root fields.
- Using
batchDelegateToSchema
anddelegateToSchema
.
- Using
-
- Distributing a GraphQL interface across services.
-
- Configuring computed fields.
- Sending complex inputs to subservices.
- Normalizing subservice deprecations in the gateway.
-
@key
directive for type-level selection sets.@merge
directive for type merging services.@computed
directive for computed fields.@canonical
directive for preferred element definitions.
Architecture
-
- Hot reload of the combined gateway schema (no server restart).
- Polling for remote subschema changes.
- Mutations for adding/removing remote subservices.
- Handling subservice request timeouts.
-
- Using GitHub API to manage a simple schema registry.
- Hot reloading from a remote Git registry.
- Running development and production environments.
-
Continuous Integration (CI) testing
- Adding test coverage to a stitched schema.
- Mocking subservices as local test fixtures.
-
- Filtering unwanted fields from the final stitched schema.
- Serving public (filtered) and private (unfiltered) API versions.
-
Persistent connection via WebSockets
- Creating a GraphQL over WebSocket Protocol (opens in a new tab) executor for the persistent connection to the services.
Other Integrations
-
- Integrating Apollo Federation services into a stitched schema.
- Fetching and parsing Federation SDLs.
-
-
JavaScript schemas created with:
graphql-js
nexus
type-graphql
-
Ruby schemas created with:
- Class-based definitions
- Parsed definitions string
-
-
- Adding GraphQL Upload to the gateway server