graphqlapollo-servergraphql-tools

GraphQL stitching VS merging schemas


What is the practical difference between merging and stitching GraphQL schemas? The graphql-tools documentation (merging:https://www.graphql-tools.com/docs/schema-merging, stitching:https://www.graphql-tools.com/docs/schema-stitching/stitch-combining-schemas) is a bit ambiguous when it comes exactly to each implementation's use cases. If I understood correctly, stitching is just a matter of organizational preferences and each subscheme becomes a 'proxy' to your scheme, while the merge functionality seems pretty similar to me. Could you please explain the difference? Thank you!


Solution

  • Schema stitching is used when you want to retrieve data from multiple GraphQL APIs in the same query (which is basically the motivation behind GraphQL). For example, you may have to extract data from two GraphQL APIs - one which offers you information about the location, the other GraphQL API gives information about the weather. For you to execute a query that has access to both endpoints at the same time, you have to STITCH the schemas of the two endpoints, which will allow you to perform a query like this(which presents a link between the two endpoints as well) :

    {
      event(id: "5983706debf3140039d1e8b4") {
        title
        description
        url
        location {
          city
          country
          weather {
            summary
            temperature
          }
        }
      }
    }
    

    On the other hand, schema merging refers to gathering all your schemas that have been split based on domains, mainly for organizational purposes. Schema merging does not keep the individual subschemas.