|
1 | 1 | import { inspect } from '@graphql-tools/utils';
|
2 |
| -import { createGraphQLError, createSchema, createYoga } from '../src/index.js'; |
| 2 | +import { createGraphQLError, createLogger, createSchema, createYoga } from '../src/index.js'; |
3 | 3 | import { eventStream } from './utilities.js';
|
4 | 4 |
|
5 | 5 | describe('error masking', () => {
|
@@ -693,4 +693,67 @@ describe('error masking', () => {
|
693 | 693 |
|
694 | 694 | expect(counter).toBe(3);
|
695 | 695 | });
|
| 696 | + |
| 697 | + it('AbortSignal cancelation within resolver is not treated as a execution request cancelation by the yoga error handler', async () => { |
| 698 | + const schema = createSchema({ |
| 699 | + typeDefs: /* GraphQL */ ` |
| 700 | + type Query { |
| 701 | + root: A! |
| 702 | + } |
| 703 | + type A { |
| 704 | + a: String! |
| 705 | + } |
| 706 | + `, |
| 707 | + resolvers: { |
| 708 | + Query: { |
| 709 | + async root() { |
| 710 | + /** we just gonna throw a DOMException here to see what happens */ |
| 711 | + const abortController = new AbortController(); |
| 712 | + abortController.abort(); |
| 713 | + expect(abortController.signal.reason?.constructor.name).toBe('DOMException'); |
| 714 | + throw abortController.signal.reason; |
| 715 | + }, |
| 716 | + }, |
| 717 | + }, |
| 718 | + }); |
| 719 | + |
| 720 | + const logger = createLogger('silent'); |
| 721 | + const error = jest.fn(); |
| 722 | + const debug = jest.fn(); |
| 723 | + logger.debug = debug; |
| 724 | + logger.error = error; |
| 725 | + const yoga = createYoga({ schema, logging: logger }); |
| 726 | + |
| 727 | + const result = await yoga.fetch('http://yoga/graphql', { |
| 728 | + method: 'POST', |
| 729 | + body: JSON.stringify({ query: '{ root { a } }' }), |
| 730 | + headers: { |
| 731 | + 'Content-Type': 'application/json', |
| 732 | + }, |
| 733 | + }); |
| 734 | + |
| 735 | + expect(result.status).toEqual(200); |
| 736 | + expect(await result.json()).toEqual({ |
| 737 | + data: null, |
| 738 | + errors: [ |
| 739 | + { |
| 740 | + locations: [ |
| 741 | + { |
| 742 | + column: 3, |
| 743 | + line: 1, |
| 744 | + }, |
| 745 | + ], |
| 746 | + message: 'Unexpected error.', |
| 747 | + path: ['root'], |
| 748 | + }, |
| 749 | + ], |
| 750 | + }); |
| 751 | + // in the future this might change as we decide to within our graphql-tools/executor error handler treat DOMException similar to a normal Error |
| 752 | + expect(error.mock.calls).toMatchObject([[{ message: 'Unexpected error value: {}' }]]); |
| 753 | + expect(debug.mock.calls).toEqual([ |
| 754 | + ['Parsing request to extract GraphQL parameters'], |
| 755 | + ['Processing GraphQL Parameters'], |
| 756 | + ['Processing GraphQL Parameters done.'], |
| 757 | + ]); |
| 758 | + }); |
696 | 759 | });
|
0 commit comments