Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions packages/web/docs/src/content/gateway/subscriptions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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"]}>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like everywhere else.

Suggested change
<Tabs items={["Config", "Programmatic"]}>
<Tabs items={["CLI", "Programmatic Usage"]}>


<Tabs.Tab>

```ts filename="gateway.config.ts"
import { defineConfig, type WSTransportOptions } from '@graphql-hive/gateway'

Expand All @@ -117,6 +125,51 @@ export const gatewayConfig = defineConfig({
})
```

</Tabs.Tab>

<Tabs.Tab>

```ts filename="gateway.runtime.ts"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like everywhere else.

Suggested change
```ts filename="gateway.runtime.ts"
```ts filename="index.ts"

// 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'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As soon as you import @graphql-hive/gateway it's not programmatic usage and you depend on Node.

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 => ({
Copy link
Member

Choose a reason for hiding this comment

The 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 getGraphQLWSOptions.

...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
Expand Down
Loading