Series Navigation
Hive Gateway (Node.js)
Now, let's tie it all together with the Hive Gateway, made by the awesome team, "TheGuild" over on GitHub.
First, let's create the node project with Nx:
nx g @nx/node:application
Install a few dependencies:
pnpm i @graphql-hive/gateway graphql-ws ws
Add a config in src/gateway.config.ts
:
import { defineConfig, LogLevel } from '@graphql-hive/gateway';
export const gatewayConfig = defineConfig({
port: 8000,
supergraph: 'apps/gateway/supergraph.graphql',
logging: LogLevel.debug,
transportEntries: {
'*.http': {
options: {
subscriptions: {
kind: 'ws',
},
},
},
},
});
Let's add a few commands to this project, too:
...
"hive-gateway": {
"dependsOn": ["supergraph-compose"],
"executor": "nx:run-commands",
"options": {
"command": "node_modules/.bin/hive-gateway supergraph -c apps/gateway/src/gateway.config.ts"
}
},
"supergraph-compose": {
"executor": "nx:run-commands",
"options": {
"command": "rover supergraph compose --elv2-license=accept --config apps/gateway/supergraph.json --output apps/gateway/supergraph.graphql"
}
},
...
Add a supergraph config for supergraph.json
:
{
"federation_version": "=2.9.0",
"subgraphs": {
"spells": {
"schema": {
"subgraph_url": "http://localhost:8080/query"
}
},
"messages": {
"schema": {
"subgraph_url": "http://localhost:8081"
}
},
"players": {
"schema": {
"subgraph_url": "http://localhost:8082/graphql"
}
}
}
}
Okay, let's test this out and run the subgraphs first:
nx run-many -t=serve -p player-service message-service spell-service
Now, let's run the gateway:
NOTE: rover
CLI is required for this step.
nx run gateway:hive-gateway
You should be able to run and execute Subscriptions through the gateway! Nice! You've now got a polyglot federated supergraph with subscriptions!
If you'd like to see the code, check it out here: https://github.com/sutt0n/polyglot-fed-gql
Top comments (0)