Open GraphQL
Published in

Open GraphQL

GraphQL Schema Stitching in action with Apollo

Schema stiching diagram

Let’s start with a real example!

Single schema as the union of our local schema and the commmercetools remote schema


Local schema

Address type
Customer type
Customer resolvers
Customer schema

Remote schema

$ npm install -g get-graphql-schema
$ get-graphql-schema [OPTIONS] ENDPOINT_URL > schema.graphql
$ get-graphql-schema --header "Authorization=Bearer <token>“<projectKey>/graphql > commercetools.types.graphql
commercetools types
commercetools schema
  • It has a “commercetools” service injected. This service provides various values that are necessary to properly forward the requests to commercetools such as the api host, the project key, and the access token
  • It includes the “http link”, that will be responsible for fetching the data from commercetools
  • It also imports the “apollo-link-context”. This library provides a “setContext” function that allows us to add the authorization header in each request made to commercetools
  • It creates the executable schema from the schema definition we have stored previously, and together with the “http link”, we get the remote schema
Express server exposing the /graphql endpoint
Our GraphQL API in action with both schemas merged



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Javier Ortiz Saorin Web developer, proton (+), Full stack developer and software engineer. Freelance