-
Notifications
You must be signed in to change notification settings - Fork 124
chore(docs): Document WebSocket programmatic setup #7489
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -97,6 +97,14 @@ subgraph. | |||||
| Please note that WebSocket for communications between Hive Gateway and subgraphs are suboptimal | ||||||
| compared to other possible transports. We recommend using either SSE or HTTP Callbacks instead. | ||||||
|
|
||||||
| To configure WebSocket subscriptions, you can use either a configuration file or runtime | ||||||
| programmatic configuration. This allows for flexibility in dynamically configuring the WebSocket | ||||||
| settings or integrating with other parts of your application. | ||||||
|
|
||||||
| <Tabs items={["Config", "Programmatic"]}> | ||||||
|
|
||||||
| <Tabs.Tab> | ||||||
|
|
||||||
| ```ts filename="gateway.config.ts" | ||||||
| import { defineConfig, type WSTransportOptions } from '@graphql-hive/gateway' | ||||||
|
|
||||||
|
|
@@ -117,6 +125,51 @@ export const gatewayConfig = defineConfig({ | |||||
| }) | ||||||
| ``` | ||||||
|
|
||||||
| </Tabs.Tab> | ||||||
|
|
||||||
| <Tabs.Tab> | ||||||
|
|
||||||
| ```ts filename="gateway.runtime.ts" | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Like everywhere else.
Suggested change
|
||||||
| // When using the gateway programmatically at runtime, you can configure WebSocket subscriptions | ||||||
| // directly in your code using the `createGatewayRuntime` function. | ||||||
|
|
||||||
| import { startNodeHttpServer } from '@graphql-hive/gateway' | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As soon as you import |
||||||
| import { createGatewayRuntime } from '@graphql-hive/gateway-runtime' | ||||||
|
|
||||||
| const runtime = createGatewayRuntime({ | ||||||
| supergraph: 'supergraph.graphql', | ||||||
| transportEntries: { | ||||||
| '*.http': { | ||||||
| options: { | ||||||
| subscriptions: { | ||||||
| kind: 'ws', | ||||||
| location: '/subscriptions', // WebSocket endpoint path on the subgraph | ||||||
| connectionParams: { | ||||||
| token: '{context.headers.authorization}' // Propagate auth headers as connection params | ||||||
| }, | ||||||
| // Optional: Customize WebSocket client options | ||||||
| getGraphQLWSOptions: options => ({ | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not where the config goes. This wont work. There's not even a property |
||||||
| ...options, | ||||||
| keepAlive: 10000, // Send keep-alive pings every 10 seconds | ||||||
| connectionTimeout: 5000 // Timeout for initial connection | ||||||
| }) | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
| }) | ||||||
|
|
||||||
| // Start the server with WebSocket support enabled by default | ||||||
| await startNodeHttpServer(runtime, { | ||||||
| // WebSocket server is automatically set up | ||||||
| // To disable WebSockets entirely, add: disableWebsockets: true | ||||||
| }) | ||||||
| ``` | ||||||
|
|
||||||
| </Tabs.Tab> | ||||||
|
|
||||||
| </Tabs> | ||||||
|
|
||||||
| ### Subscriptions using HTTP Callback | ||||||
|
|
||||||
| If your subgraph uses | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like everywhere else.