Skip to content

Commit 20263e7

Browse files
JoviDeCroockbenjie
andcommitted
Update execute.ts
Co-authored-by: Benjie <benjie@jemjie.com>
1 parent 1c2cee6 commit 20263e7

File tree

3 files changed

+17
-19
lines changed

3 files changed

+17
-19
lines changed

.c8rc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"src/jsutils/ObjMap.ts",
99
"src/jsutils/PromiseOrValue.ts",
1010
"src/utilities/assertValidName.ts",
11-
"src/utilities/typedQueryDocumentNode.ts"
11+
"src/utilities/typedQueryDocumentNode.ts",
12+
"src/**/__tests__/**/*.ts"
1213
],
1314
"clean": true,
1415
"temp-directory": "coverage",

src/execution/__tests__/union-interface-test.ts

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ const PetType = new GraphQLUnionType({
118118
if (value instanceof Cat) {
119119
return CatType.name;
120120
}
121-
/* c8 ignore next 3 */
122121
// Not reachable, all possible types have been considered.
123122
expect.fail('Not reachable');
124123
},
@@ -169,14 +168,10 @@ const TypeA = new GraphQLObjectType({
169168
nameA: { type: GraphQLString },
170169
}),
171170
isTypeOf: (_value, _context, _info) =>
172-
new Promise(
173-
(_resolve, reject) =>
174-
void setTimeout(
175-
() => void reject(new Error("TypeA_isTypeOf_rejected")),
176-
10,
177-
),
171+
new Promise((_resolve, reject) =>
172+
// eslint-disable-next-line
173+
setTimeout(() => reject(new Error('TypeA_isTypeOf_rejected')), 10),
178174
),
179-
},
180175
});
181176

182177
const TypeB = new GraphQLObjectType({
@@ -186,9 +181,7 @@ const TypeB = new GraphQLObjectType({
186181
id: { type: GraphQLString },
187182
nameB: { type: GraphQLString },
188183
}),
189-
isTypeOf: (value: any, _context, _info) => {
190-
return value.id === 'b';
191-
},
184+
isTypeOf: (value: any, _context, _info) => value.id === 'b',
192185
});
193186

194187
const queryTypeWithSearchable = new GraphQLObjectType({
@@ -202,10 +195,8 @@ const queryTypeWithSearchable = new GraphQLObjectType({
202195
type: SearchableInterface,
203196
args: { id: { type: GraphQLString } },
204197
resolve: (_source, { id }) => {
205-
/* c8 ignore start */
206198
if (id === 'a') {
207199
return { id: 'a', nameA: 'Object A' };
208-
/* c8 ignore end */
209200
} else if (id === 'b') {
210201
return { id: 'b', nameB: 'Object B' };
211202
}
@@ -636,19 +627,18 @@ describe('Execute: Union and intersection types', () => {
636627
`);
637628

638629
let unhandledRejection: any = null;
639-
/* c8 ignore start */
640630
const unhandledRejectionListener = (reason: any) => {
641631
unhandledRejection = reason;
642632
};
633+
// eslint-disable-next-line
643634
process.on('unhandledRejection', unhandledRejectionListener);
644-
/* c8 ignore end */
645635

646636
const result = await execute({
647637
schema: schemaWithSearchable,
648638
document,
649639
});
650640

651-
expect(result.errors).to.be.undefined;
641+
expect(result.errors).to.equal(undefined);
652642
expect(result.data).to.deep.equal({
653643
search: {
654644
__typename: 'TypeB',
@@ -658,10 +648,12 @@ describe('Execute: Union and intersection types', () => {
658648
});
659649

660650
// Give the TypeA promise a chance to reject and the listener to fire
651+
// eslint-disable-next-line
661652
await new Promise((resolve) => setTimeout(resolve, 20));
662653

654+
// eslint-disable-next-line
663655
process.removeListener('unhandledRejection', unhandledRejectionListener);
664656

665-
expect(unhandledRejection).to.be.null;
657+
expect(unhandledRejection).to.equal(null);
666658
});
667659
});

src/execution/execute.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1003,7 +1003,12 @@ export const defaultTypeResolver: GraphQLTypeResolver<unknown, unknown> =
10031003
promisedIsTypeOfResults[i] = isTypeOfResult;
10041004
} else if (isTypeOfResult) {
10051005
if (promisedIsTypeOfResults.length) {
1006-
Promise.allSettled(promisedIsTypeOfResults);
1006+
// Explicitly ignore any promise rejections
1007+
Promise.allSettled(promisedIsTypeOfResults)
1008+
/* c8 ignore next 3 */
1009+
.catch(() => {
1010+
// Do nothing
1011+
});
10071012
}
10081013
return type.name;
10091014
}

0 commit comments

Comments
 (0)