Reputation: 4236
I'm new to both concepts so excuse me if it's opinion-based. Currently, I'm looking at Apollo Federation and schema stitching provided by the graphql-tools package, though I guess it applies to similar packages. Could something like a table be created describing certain requirements/conditions to prefer one over the other?
Upvotes: 4
Views: 1140
Reputation: 509
I explained the difference between GraphQL federation and Schema Stitching here, but what makes GraphQL federation unique is its schema validation and composition aspect. Let me explain.
The schema composition process analyzes every subgraph schema, verifies that everything works well together (by reading federation directives like @key
, @provides
, @requires
and others and comparing them across subgraph schemas). It verifies that all types and fields are compatible with each other.
This analysis enables GraphQL federation to catch potential issues before they reach production, setting it apart from alternatives like Schema Stitching.
In my opinion the biggest difference between Schema Stitching and GraphQL federation is the satisfiability checking of the supergraph.
Imagine you have multiple schemas that you combine together. With Schema Stitching, you do this "merging" manually and it's prone to errors that are undetectable at build time. There could be a case where you defined User types in two schemas, so from a point of view of the GraphQL API client, all the fields of User type are available to query. The problem is, they may not be accessible through certain query paths and you end up with broken queries.
With GraphQL federation (Apollo Federation for example), thanks to its satisfiability validation rule, those issues are prevented at during schema validation. The satisfiability validation rule checks if all possible queries are resolvable and will be resolved by the gateway.
Upvotes: 0
Reputation: 1804
Apollo's GraphQL Federation and "schema stitching" both accomplish a similar goal: unify multiple GraphQL APIs under a single GraphQL API.
Based on my understanding, the main differences between them are:
Apollo's Federation | Schema stitching |
---|---|
subgraph services own the logic for linking shared types together | the gateway owns the logic for linking shared types together |
distributes the ownership of subgraphs to the individual service teams | assumes centralized responsibility of the full schema |
tightly coupled to the Apollo ecosystem | more open source |
For more details, I'd recommend reading https://product.voxmedia.com/2020/11/2/21494865/to-federate-or-stitch-a-graphql-gateway-revisited.
Upvotes: 3