Skip to content

Commit e244b78

Browse files
authored
feat: pass subscription Headers as connection_init payload (#2719)
Co-authored-by: Andrei Alecu <[email protected]>
1 parent 3cf8bb5 commit e244b78

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

.changeset/late-queens-visit.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@graphiql/toolkit': minor
3+
---
4+
5+
Allow passing Headers for subscriptions into connection_init payload

packages/graphiql-toolkit/src/create-fetcher/createFetcher.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ export function createGraphiQLFetcher(options: CreateFetcherOptions): Fetcher {
3535
// simpler fetcher for schema requests
3636
const simpleFetcher = createSimpleFetcher(options, httpFetch);
3737

38-
const wsFetcher = getWsFetcher(options);
3938
const httpFetcher = options.enableIncrementalDelivery
4039
? createMultipartFetcher(options, httpFetch)
4140
: simpleFetcher;
@@ -54,6 +53,8 @@ export function createGraphiQLFetcher(options: CreateFetcherOptions): Fetcher {
5453
)
5554
: false;
5655
if (isSubscription) {
56+
const wsFetcher = getWsFetcher(options, fetcherOpts);
57+
5758
if (!wsFetcher) {
5859
throw Error(
5960
`Your GraphiQL createFetcher is not properly configured for websocket subscriptions yet. ${

packages/graphiql-toolkit/src/create-fetcher/lib.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,15 +193,18 @@ export const createMultipartFetcher = (
193193
* @param options {CreateFetcherOptions}
194194
* @returns
195195
*/
196-
export const getWsFetcher = (options: CreateFetcherOptions) => {
196+
export const getWsFetcher = (
197+
options: CreateFetcherOptions,
198+
fetcherOpts: FetcherOpts | undefined,
199+
) => {
197200
if (options.wsClient) {
198201
return createWebsocketsFetcherFromClient(options.wsClient);
199202
}
200203
if (options.subscriptionUrl) {
201-
return createWebsocketsFetcherFromUrl(
202-
options.subscriptionUrl,
203-
options.wsConnectionParams,
204-
);
204+
return createWebsocketsFetcherFromUrl(options.subscriptionUrl, {
205+
...options.wsConnectionParams,
206+
...fetcherOpts?.headers,
207+
});
205208
}
206209
const legacyWebsocketsClient = options.legacyClient || options.legacyWsClient;
207210
if (legacyWebsocketsClient) {

0 commit comments

Comments
 (0)