Skip to content

Commit

Permalink
fix(server): Make sure to use onSubscribe result exclusively
Browse files Browse the repository at this point in the history
  • Loading branch information
enisdenjo committed Oct 31, 2020
1 parent 6cfe526 commit 51fdb7c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
5 changes: 2 additions & 3 deletions src/server.ts
Expand Up @@ -563,9 +563,8 @@ export function createServer(
]);
}

// if you've provided your own root through
// `onSubscribe`, prefer that over the root's root
if (!execArgs.rootValue) {
// if onsubscribe didnt return anything, inject roots
if (!maybeExecArgsOrErrors) {
execArgs.rootValue = roots?.[operationAST.operation];
}

Expand Down
8 changes: 7 additions & 1 deletion src/tests/server.ts
Expand Up @@ -704,8 +704,14 @@ describe('Subscribe', () => {
};
const { url } = await startTServer({
schema: undefined,
roots: {
query: { not: 'me' },
},
execute: (args) => {
expect(args).toBe(nopeArgs);
expect(args.schema).toBe(nopeArgs.schema); // schema from nopeArgs
expect(args.rootValue).toBeUndefined(); // nopeArgs didnt provide any root value
expect(args.operationName).toBe('Nope');
expect(args.variableValues).toBeUndefined(); // nopeArgs didnt provide variables
return execute(args);
},
onSubscribe: (_ctx, _message) => {
Expand Down

0 comments on commit 51fdb7c

Please sign in to comment.