v1
Consume in Other Gateways

Consume in other gateways

If you don’t use Hive Gateway, but still want to use Mesh Compose to convert non-federated sources to a federated subgraph. You can still do it but it has some limitations, you need to generate the subgraph, and serve the subgraph with Hive Gateway But if you use Hive Gateway, you don’t need to worry about this, then you can use the supergraph directly without having multiple servers.

That’s because other gateways are not aware of Mesh Compose’s additional directives to handle the non-federated sources.

This means you can use non-federated sources in any Federation compliant gateway such as Apollo Gateway, Apollo Router or Cosmo Router.

Generate the subgraph

First, you need to generate the subgraph with Mesh Compose, and then serve the subgraph with Hive Gateway.

mesh.config.ts
import { defineConfig } from '@graphql-mesh/compose-cli'
import { loadOpenAPISubgraph } from '@omnigraph/openapi'
 
export const composeConfig = defineConfig({
  subgraphs: [
    {
      sourceHandler: loadOpenAPISubgraph('Wiki', {
        source: 'https://api.apis.guru/v2/specs/wikimedia.org/1.0.0/swagger.yaml'
      }),
      transforms: [
        /**.. **/
      ]
    }
  ]
})

Then you can run the following command to generate the subgraph:

npx mesh-compose --subgraph Wiki > wiki-subgraph.graphql

You can also use this schema with any schema registry such as Hive or GraphOS.

💡

For example, with GraphQL Hive CLI you can publish this subgraph with the following command:

hive schema:publish \
  --registry.accessToken YOUR_TOKEN_HERE \
  --service="reviews" \
  --url="http://fake.com/reviews/graphql" \
  --author "Me" \
  --commit "Second" \
  wiki-subgraph.graphql

Serve the subgraph

Then you can serve the subgraph with Hive Gateway with the following command;

npx hive-gateway subgraph wiki-subgraph.graphql

Then you can use the supergraph in any Federation compliant gateway such as Apollo Gateway, Apollo Router or Cosmo Router.