Federation Supergraph
You can use GraphQL Mesh as a Federation supergraph in multiple ways. You can either provide each source, and let Mesh build your supergraph, or you can provide prebuilt Supergraph SDL.
Consuming prebuilt Supergraph SDL
If you use Apollo Rover CLI or GraphQL Hive to compose your subgraphs, you can easily consume the prebuilt supergraph SDL by using Supergraph handler;
npm i @graphql-mesh/supergraph
sources:
- name: Supergraph
handler:
supergraph:
source: http://some-source.com/supergraph.graphql # it can be a path from the file system `./supergraph.graphql`
schemaHeaders:
myTokenHeader: MY_TOKEN_VALUE
Using Mesh to build the supergraph
You can provide the existing subgraphs within GraphQL Mesh, or you can use Federation Subgraph to create subgraphs from regular sources.
sources:
- name: accounts
handler:
graphql:
endpoint: http://localhost:9871/graphql
transforms:
- federation:
types:
- name: User
config:
key:
- fields: id
resolveReference:
queryFieldName: user
args:
id: '{root.id}'
- name: reviews
handler:
graphql:
endpoint: http://localhost:9872/graphql
- name: products
handler:
graphql:
endpoint: http://localhost:9873/graphql
- name: inventory
handler:
graphql:
endpoint: http://localhost:9874/graphql
You can check our working example on the repo.