Featured image of post GraphQL Schema Stitching In a Nutshell

GraphQL Schema Stitching In a Nutshell

How GraphQL Schema Stitching Worked

How make a patchwork quilt

GraphQL Schema Stitching—it’s a bit like stitching together Frankenstein’s monster, but way less terrifying and significantly more useful.

What Is Schema Stitching?

Schema stitching is the art (and occasional nightmare) of merging multiple GraphQL schemas into a single unified API.

Instead of making users query separate GraphQL services, you stitch them into one seamless schema, allowing queries across multiple sources.

Think of it as taking different LEGO sets, smashing them together, and somehow still ending up with a cohesive Death Star model.

The History of Schema Stitching

Schema stitching made its grand entrance around 2017, introduced by Apollo as a solution to GraphQL’s growing pains.

At that time, developers were struggling with GraphQL services that were fragmented across multiple microservices.

Instead of making users send multiple queries to different services, Apollo’s schema stitching allowed developers to merge multiple schemas into a single API, making life easier for frontend devs and backend architects alike.

It was revolutionary! Until it wasn’t.

Motivation: Why Was Schema Stitching Even a Thing?

Before schema stitching, GraphQL microservices had a real problem: each service had its own schema, and users had to make separate API calls to get data from different services. This was annoying and inefficient.

Schema stitching promised:

  • A unified API experience.
  • A way to resolve types across services (e.g., users from one service and orders from another).
  • The ability to extend types across multiple services without needing a monolithic GraphQL server.

Basically, it sounded like a dream come true for teams building GraphQL-powered microservices.

Pros of Schema Stitching

  • Unified API: Clients can query across multiple services with a single request.
  • Scalability: Teams can work on separate GraphQL services while still exposing a single API.
  • Flexibility: You can combine different GraphQL services dynamically.
  • Extendable: You can extend types across schemas without needing a monolith.

Cons of Schema Stitching

  • Complexity: Managing stitched schemas is not for the faint of heart.
  • Performance Issues: It introduces overhead since resolvers often need to fetch data across multiple services.
  • Debugging Nightmares: Error messages can be tricky because they often originate from stitched resolvers.
  • Deprecated in Apollo: Apollo decided to abandon schema stitching in favor of GraphQL Federation, which solved many of its limitations.

Is Schema Stitching Still Used Today?

Short answer: Not really, at least not in its original form.

Long answer: Apollo officially moved away from schema stitching in favor of GraphQL Federation, a more scalable and maintainable approach to combining GraphQL schemas.

However, some teams still use schema stitching, especially in legacy systems or when Federation isn’t an option. If you’re starting fresh today, GraphQL Federation is the way to go.

Key Ideas

ConceptDescription
Schema StitchingMerging multiple GraphQL schemas into one API.
HistoryIntroduced by Apollo in 2017 to solve GraphQL microservices fragmentation.
MotivationAimed to provide a unified API, extend types, and make microservices friendlier.
ProsUnified API, scalable, flexible, and extendable.
ConsComplex, performance-heavy, hard to debug, and now largely obsolete.
Current StateReplaced by GraphQL Federation but still exists in some legacy systems.

References

  1. Apollo’s original schema stitching docs
  2. GraphQL Federation
  3. The evolution of GraphQL API composition

And there you have it! Schema stitching—once a shining beacon of hope, now mostly a relic of the past. If you’re working with GraphQL today, you’re better off using Federation.