hotchoc schema stitching example (without hot reload)
In this setup, we will be setting up centralize hotchoc grapql federation that resolves schema residing in another services. The gateway does not import or contains subgraph schema. It does not require developer to copy schema from subgraph over as part of this integration.
It is abit confusing as there are 2 ways to implement federation.
1. Schema stitching which is what this blog talks about.
Will there be manual work to stich schema into a global schema?
What if schema conflict occurs and what would happened?
2. Federated schema - where we are using tech stack such as redis to pull schema changes from different subgraphs into a global schema.
The subgraph needs to know about the global supergraph.
What if schema conflict occurs and what would happened?
In a centralize approach, gateway reference subgraph schemas. Stitching generally happens when we would like to extend our subgraphs for example, introducing another query name. We will see more of this. Inline with the federation intention, if a request for product info, the product subgraph would return product info while leaving reviews to be resolved by another subgraph service.
We will be creating 5 projects
- the gateway - this main graphql allows us to query other subgraph define below.
- product subgraph - a simple subgraph that shows product info
- review subgraph - a slightly more complicated subgraph that provides review information
- account subgraph
- inventory subgraph
Github repository
https://github.com/mitzenjeremywoo/hotchoc-federation-centralize
To run, clone this repo above. Then run all the projects above using dotnet run.
The entry point for us would be the gateway. Gateway does not have method that returns data to us. When we start the app and go into http://localhost:5050/graphql you will noticed that we have all the subgraph schema accessible to us.
For example, we can have reviews that the review subgraph. Then we also have user from the user subgraph (red) and our reviews comes from review subgraph.
Also note that gateway do not hold or contain references of these subgraph schema. As your specify the query, you would be able to retrieve data from different subgraphs.


Comments