-
Notifications
You must be signed in to change notification settings - Fork 175
feat(BA-2806): Implement WebSocket connectionParams to HTTP headers conversion #6379
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
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 |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Implement WebSocket connectionParams to HTTP headers conversion |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,13 +1,54 @@ | ||||||
| import { defineConfig } from '@graphql-hive/gateway'; | ||||||
| import { defineConfig, WSTransportOptions, type GatewayPlugin } from '@graphql-hive/gateway'; | ||||||
|
|
||||||
| // Custom plugin to convert WebSocket connectionParams to HTTP headers | ||||||
| // This allows authentication parameters sent via WebSocket connection_init | ||||||
| // to be forwarded as HTTP headers when the gateway makes federation requests to subgraphs | ||||||
| const useConnectionParamsToHeadersPlugin = (): GatewayPlugin => { | ||||||
| return { | ||||||
| onSubgraphExecute({ executionRequest, executor, setExecutor }) { | ||||||
| // Access WebSocket connectionParams from context | ||||||
| const connectionParams = executionRequest.context?.connectionParams; | ||||||
|
|
||||||
| if (connectionParams && typeof connectionParams === 'object') { | ||||||
| // Wrap executor to inject connectionParams as HTTP headers | ||||||
| const originalExecutor = executor; | ||||||
| const wrappedExecutor = async (execRequest: any) => { | ||||||
| // Extract Authorization header from context if it exists | ||||||
| let reqHeaders = execRequest.context.headers || {}; | ||||||
|
||||||
| let reqHeaders = execRequest.context.headers || {}; | |
| const reqHeaders = { ...(execRequest.context.headers || {}) }; |
This file was deleted.
This file was deleted.
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.
The
execRequestparameter usesanytype, which bypasses TypeScript's type safety. Consider using a proper type from the gateway library or defining an appropriate interface for the execution request.