|
1 |
| -import { inspect } from '../jsutils/inspect'; |
2 |
| -import { invariant } from '../jsutils/invariant'; |
3 |
| - |
4 | 1 | import type {
|
5 | 2 | TypeNode,
|
6 | 3 | NamedTypeNode,
|
@@ -41,20 +38,16 @@ export function typeFromAST(
|
41 | 38 | schema: GraphQLSchema,
|
42 | 39 | typeNode: TypeNode,
|
43 | 40 | ): GraphQLType | undefined {
|
44 |
| - let innerType; |
45 |
| - if (typeNode.kind === Kind.LIST_TYPE) { |
46 |
| - innerType = typeFromAST(schema, typeNode.type); |
47 |
| - return innerType && new GraphQLList(innerType); |
48 |
| - } |
49 |
| - if (typeNode.kind === Kind.NON_NULL_TYPE) { |
50 |
| - innerType = typeFromAST(schema, typeNode.type); |
51 |
| - return innerType && new GraphQLNonNull(innerType); |
| 41 | + switch (typeNode.kind) { |
| 42 | + case Kind.LIST_TYPE: { |
| 43 | + const innerType = typeFromAST(schema, typeNode.type); |
| 44 | + return innerType && new GraphQLList(innerType); |
| 45 | + } |
| 46 | + case Kind.NON_NULL_TYPE: { |
| 47 | + const innerType = typeFromAST(schema, typeNode.type); |
| 48 | + return innerType && new GraphQLNonNull(innerType); |
| 49 | + } |
| 50 | + case Kind.NAMED_TYPE: |
| 51 | + return schema.getType(typeNode.name.value); |
52 | 52 | }
|
53 |
| - // istanbul ignore else (See: 'https://github.com/graphql/graphql-js/issues/2618') |
54 |
| - if (typeNode.kind === Kind.NAMED_TYPE) { |
55 |
| - return schema.getType(typeNode.name.value); |
56 |
| - } |
57 |
| - |
58 |
| - // istanbul ignore next (Not reachable. All possible type nodes have been considered) |
59 |
| - invariant(false, 'Unexpected type node: ' + inspect(typeNode)); |
60 | 53 | }
|
0 commit comments