Skip to content

Commit

Permalink
fix: fix graphql api error with apollo subscriptions (#1137)
Browse files Browse the repository at this point in the history
  • Loading branch information
pradel committed May 6, 2021
1 parent 217004d commit 7726eaf
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/silly-poems-mix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@accounts/graphql-api': patch
---

Fix `accountsGraphQL.context` breaking apollo subscriptions.
1 change: 1 addition & 0 deletions packages/graphql-api/src/modules/accounts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { CoreAccountsModule } from '../core';

export interface AccountsRequest {
req: IncomingMessage;
connection?: any;
}

export interface AccountsModuleConfig {
Expand Down
7 changes: 6 additions & 1 deletion packages/graphql-api/src/utils/context-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: '',
Expand Down

0 comments on commit 7726eaf

Please sign in to comment.