Skip to content

Commit

Permalink
adjust error when unexpectedly encountering experimental directives
Browse files Browse the repository at this point in the history
  • Loading branch information
yaacovCR committed Dec 28, 2022
1 parent 1af828b commit 3b00b01
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/execution/__tests__/executor-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -931,7 +931,7 @@ describe('Execute: Handles basic execution tasks', () => {
const document = parse('query Q { a }');

expect(() => execute({ schema, document })).to.throw(
'Use function `experimentalExecuteIncrementally` to execute operations against schemas that define the experimental @defer or @stream directives.',
'The provided schema unexpectedly contains experimental directives (@defer or @stream). These directives may only be utilized if experimental execution features are explicitly enabled.',
);
});

Expand All @@ -948,7 +948,7 @@ describe('Execute: Handles basic execution tasks', () => {
const document = parse('query Q { a }');

expect(() => execute({ schema, document })).to.throw(
'Use function `experimentalExecuteIncrementally` to execute operations against schemas that define the experimental @defer or @stream directives.',
'The provided schema unexpectedly contains experimental directives (@defer or @stream). These directives may only be utilized if experimental execution features are explicitly enabled.',
);
});

Expand Down
7 changes: 4 additions & 3 deletions src/execution/execute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,9 @@ export interface ExecutionArgs {
subscribeFieldResolver?: Maybe<GraphQLFieldResolver<any, any>>;
}

const UNEXPECTED_EXPERIMENTAL_DIRECTIVES =
'The provided schema unexpectedly contains experimental directives (@defer or @stream). These directives may only be utilized if experimental execution features are explicitly enabled.';

const UNEXPECTED_MULTIPLE_PAYLOADS =
'Executing this GraphQL operation would unexpectedly produce multiple payloads (due to @defer or @stream directive)';

Expand All @@ -284,9 +287,7 @@ const UNEXPECTED_MULTIPLE_PAYLOADS =
*/
export function execute(args: ExecutionArgs): PromiseOrValue<ExecutionResult> {
if (args.schema.getDirective('defer') || args.schema.getDirective('stream')) {
throw new Error(
'Use function `experimentalExecuteIncrementally` to execute operations against schemas that define the experimental @defer or @stream directives.',
);
throw new Error(UNEXPECTED_EXPERIMENTAL_DIRECTIVES);
}

const result = experimentalExecuteIncrementally(args);
Expand Down

0 comments on commit 3b00b01

Please sign in to comment.