File tree Expand file tree Collapse file tree 3 files changed +15
-6
lines changed
packages/graphiql-toolkit/src/create-fetcher Expand file tree Collapse file tree 3 files changed +15
-6
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ ' @graphiql/toolkit ' : minor
3+ ---
4+
5+ Allow passing Headers for subscriptions into connection_init payload
Original file line number Diff line number Diff 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. ${
Original file line number Diff line number Diff 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 ) {
You can’t perform that action at this time.
0 commit comments