diff --git a/.changeset/silly-poems-mix.md b/.changeset/silly-poems-mix.md new file mode 100644 index 000000000..6d9588dbf --- /dev/null +++ b/.changeset/silly-poems-mix.md @@ -0,0 +1,5 @@ +--- +'@accounts/graphql-api': patch +--- + +Fix `accountsGraphQL.context` breaking apollo subscriptions. diff --git a/packages/graphql-api/src/modules/accounts/index.ts b/packages/graphql-api/src/modules/accounts/index.ts index 8cdba17b5..95deb93b9 100644 --- a/packages/graphql-api/src/modules/accounts/index.ts +++ b/packages/graphql-api/src/modules/accounts/index.ts @@ -18,6 +18,7 @@ import { CoreAccountsModule } from '../core'; export interface AccountsRequest { req: IncomingMessage; + connection?: any; } export interface AccountsModuleConfig { diff --git a/packages/graphql-api/src/utils/context-builder.ts b/packages/graphql-api/src/utils/context-builder.ts index 66b9f99b3..64544aea4 100644 --- a/packages/graphql-api/src/utils/context-builder.ts +++ b/packages/graphql-api/src/utils/context-builder.ts @@ -3,10 +3,15 @@ import { getClientIp } from 'request-ip'; import { AccountsRequest, AccountsModuleConfig } from '../modules'; export const context = (moduleName: string) => async ( - { req }: AccountsRequest, + { req, connection }: AccountsRequest, _: any, { injector }: ModuleSessionInfo ) => { + // If connection is set it means it's a websocket connection coming from apollo + if (connection) { + return connection.context; + } + if (!req) { return { ip: '',