Skip to content
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions .changeset/late-queens-visit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphiql/toolkit': minor
---

Allow passing Headers for subscriptions into connection_init payload
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export function createGraphiQLFetcher(options: CreateFetcherOptions): Fetcher {
// simpler fetcher for schema requests
const simpleFetcher = createSimpleFetcher(options, httpFetch);

const wsFetcher = getWsFetcher(options);
const httpFetcher = options.enableIncrementalDelivery
? createMultipartFetcher(options, httpFetch)
: simpleFetcher;
Expand All @@ -52,6 +51,8 @@ export function createGraphiQLFetcher(options: CreateFetcherOptions): Fetcher {
graphQLParams.operationName || undefined,
);
if (isSubscription) {
const wsFetcher = getWsFetcher(options, fetcherOpts);

if (!wsFetcher) {
throw Error(
`Your GraphiQL createFetcher is not properly configured for websocket subscriptions yet. ${
Expand Down
13 changes: 8 additions & 5 deletions packages/graphiql-toolkit/src/create-fetcher/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,15 +193,18 @@ export const createMultipartFetcher = (
* @param options {CreateFetcherOptions}
* @returns
*/
export const getWsFetcher = (options: CreateFetcherOptions) => {
export const getWsFetcher = (
options: CreateFetcherOptions,
fetcherOpts: FetcherOpts | undefined,
) => {
if (options.wsClient) {
return createWebsocketsFetcherFromClient(options.wsClient);
}
if (options.subscriptionUrl) {
return createWebsocketsFetcherFromUrl(
options.subscriptionUrl,
options.wsConnectionParams,
);
return createWebsocketsFetcherFromUrl(options.subscriptionUrl, {
...options.wsConnectionParams,
...fetcherOpts?.headers,
});
}
const legacyWebsocketsClient = options.legacyClient || options.legacyWsClient;
if (legacyWebsocketsClient) {
Expand Down