Federation Supergraph
GraphQL Mesh v0 documentation (superseded by v1): Federation Supergraph
You can use GraphQL Mesh as a [Federation](https://the-guild.dev/graphql/hive/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;
Configuring subgraphs within the supergraph
You can also configure subgraphs within the supergraph by providing the subgraph name in order to change the endpoint and headers for each subgraph.
Config API Reference
source(type:String, required) - A file path to your Supergraph Schema If you provide a path to a code file(js or ts), other options will be ignored and the schema exported from the file will be used directly.schemaHeaders(type:Any)operationHeaders(type:Any)batch(type:Boolean)subgraphs(type:Array of Object, required):name(type:String, required) - The name of the subgraph you want to configureendpoint(type:String) - A url or file path to your remote GraphQL endpoint. If you provide a path to a code file(js or ts), other options will be ignored and the schema exported from the file will be used directly.operationHeaders(type:JSON) - JSON object representing the Headers to add to the runtime of the API calls only for operation during runtimeuseGETForQueries(type:Boolean) - Use HTTP GET for Query operationsmethod(type:String (GET | POST)) - HTTP method used for GraphQL operationscredentials(type:String (omit | include)) - Request Credentials if your environment supports it. See more
@default “same-origin”
webSocketImpl(type:String) - Path to a custom W3 Compatible WebSocket Implementationsource(type:String) - Path to the introspection You can separately give schema introspection or SDLsubscriptionsProtocol(type:String (SSE | WS | LEGACY_WS)) - SSE - Server Sent Events WS - New graphql-ws LEGACY_WS - Legacy subscriptions-transport-wssubscriptionsEndpoint(type:String) - URL to your endpoint serving all subscription queries for this sourceretry(type:Int) - Retry attempts if failstimeout(type:Int) - Timeout in millisecondsconnectionParams(type:JSON) - JSON object representing theconnectionParamsfrom a WebSocket connection to add to the runtime of the API calls only for operation during runtime. More information about the WebSocketconnectionParams:
- When using
subscriptionsProtocol=WS(graphql-ws): https://github.com/enisdenjo/graphql-ws/blob/master/docs/interfaces/client.ClientOptions.md#connectionparams - When using
subscriptionsProtocol=LEGACY_WS(subscriptions-transport-ws): https://github.com/apollographql/subscriptions-transport-ws/blob/51270cc7dbaf09c7b9aa67368f1de58148c7d334/README.md#subscriptionclient
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.
You can check our working example on the repo.