Skip to Content
Mesh
v0Source HandlersFederation Supergraph
⚠️
This is the documentation for the old GraphQL Mesh version v0. We recommend upgrading to the latest GraphQL Mesh version v1.

Migrate to GraphQL Mesh 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;

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

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.

sources: - name: Supergraph handler: supergraph: source: http://some-source.com/supergraph.graphql subgraphs: - name: accounts endpoint: http://localhost:9871/graphql operationHeaders: # You can use context variables here Authorization: "Bearer {context.headers['x-accounts-token']}" - name: reviews endpoint: '{env.REVIEWS_ENDPOINT:https://default-reviews.com/graphql}' operationHeaders: Authorization: "Bearer {context.headers['x-reviews-token']}"

Config API Reference

  • source (type: String, required) - A url to your WSDL or generated SDL with annotations
  • schemaHeaders (type: Any) - JSON object representing the Headers to add to the runtime of the API calls only for schema introspection You can also provide .js or .ts file path that exports schemaHeaders as an object
  • operationHeaders (type: JSON) - JSON object representing the Headers to add to the runtime of the API calls only for operation during runtime
  • bodyAlias (type: String) - The name of the alias to be used in the envelope for body components

default: body

  • soapHeaders (type: Object) - SOAP Headers to be added to the request:
    • alias (type: String) - The name of the alias to be used in the envelope

default: header

  • namespace (type: String, required) - The namespace of the SOAP Header For example: http://www.example.com/namespace
  • headers (type: JSON, required) - The content of the SOAP Header For example: { “key”: “value” } then the content will be <key>value</key>
  • soapNamespace (type: String) - The namespace of the SOAP envelope By default, SOAP handler detects the SOAP version and if SOAP version is 1.1, it uses http://schemas.xmlsoap.org/soap/envelope/ namespace If SOAP version is 1.2, it uses http://www.w3.org/2003/05/soap-envelope namespace

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.

Last updated on