|
3 | 3 | import { expect } from 'chai';
|
4 | 4 | import { describe, it } from 'mocha';
|
5 | 5 |
|
| 6 | +import invariant from '../../jsutils/invariant'; |
| 7 | + |
6 | 8 | import { GraphQLSchema } from '../../type/schema';
|
7 | 9 | import { GraphQLString, GraphQLBoolean } from '../../type/scalars';
|
8 | 10 | import {
|
@@ -268,15 +270,18 @@ describe('Execute: Handles execution of abstract types with promises', () => {
|
268 | 270 | const PetType = new GraphQLInterfaceType({
|
269 | 271 | name: 'Pet',
|
270 | 272 | resolveType(obj) {
|
271 |
| - return Promise.resolve( |
272 |
| - obj instanceof Dog |
273 |
| - ? DogType |
274 |
| - : obj instanceof Cat |
275 |
| - ? CatType |
276 |
| - : obj instanceof Human |
277 |
| - ? HumanType |
278 |
| - : null, |
279 |
| - ); |
| 273 | + if (obj instanceof Dog) { |
| 274 | + return Promise.resolve(DogType); |
| 275 | + } |
| 276 | + if (obj instanceof Cat) { |
| 277 | + return Promise.resolve(CatType); |
| 278 | + } |
| 279 | + if (obj instanceof Human) { |
| 280 | + return Promise.resolve(HumanType); |
| 281 | + } |
| 282 | + |
| 283 | + // Not reachable. All possible types have been considered. |
| 284 | + invariant(false); |
280 | 285 | },
|
281 | 286 | fields: {
|
282 | 287 | name: { type: GraphQLString },
|
@@ -394,15 +399,18 @@ describe('Execute: Handles execution of abstract types with promises', () => {
|
394 | 399 | const PetType = new GraphQLUnionType({
|
395 | 400 | name: 'Pet',
|
396 | 401 | resolveType(obj) {
|
397 |
| - return Promise.resolve( |
398 |
| - obj instanceof Dog |
399 |
| - ? DogType |
400 |
| - : obj instanceof Cat |
401 |
| - ? CatType |
402 |
| - : obj instanceof Human |
403 |
| - ? HumanType |
404 |
| - : null, |
405 |
| - ); |
| 402 | + if (obj instanceof Dog) { |
| 403 | + return Promise.resolve(DogType); |
| 404 | + } |
| 405 | + if (obj instanceof Cat) { |
| 406 | + return Promise.resolve(CatType); |
| 407 | + } |
| 408 | + if (obj instanceof Human) { |
| 409 | + return Promise.resolve(HumanType); |
| 410 | + } |
| 411 | + |
| 412 | + // Not reachable. All possible types have been considered. |
| 413 | + invariant(false); |
406 | 414 | },
|
407 | 415 | types: [DogType, CatType],
|
408 | 416 | });
|
@@ -470,9 +478,15 @@ describe('Execute: Handles execution of abstract types with promises', () => {
|
470 | 478 | const PetType = new GraphQLInterfaceType({
|
471 | 479 | name: 'Pet',
|
472 | 480 | resolveType(obj) {
|
473 |
| - return Promise.resolve( |
474 |
| - obj instanceof Dog ? 'Dog' : obj instanceof Cat ? 'Cat' : null, |
475 |
| - ); |
| 481 | + if (obj instanceof Dog) { |
| 482 | + return Promise.resolve('Dog'); |
| 483 | + } |
| 484 | + if (obj instanceof Cat) { |
| 485 | + return Promise.resolve('Cat'); |
| 486 | + } |
| 487 | + |
| 488 | + // Not reachable. All possible types have been considered. |
| 489 | + invariant(false); |
476 | 490 | },
|
477 | 491 | fields: {
|
478 | 492 | name: { type: GraphQLString },
|
|
0 commit comments