Skip to content

Commit bc3564a

Browse files
typeFromAST: use exhaustive switch and remove invariant (#3396)
1 parent 79d984f commit bc3564a

File tree

1 file changed

+11
-18
lines changed

1 file changed

+11
-18
lines changed

src/utilities/typeFromAST.ts

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
import { inspect } from '../jsutils/inspect';
2-
import { invariant } from '../jsutils/invariant';
3-
41
import type {
52
TypeNode,
63
NamedTypeNode,
@@ -41,20 +38,16 @@ export function typeFromAST(
4138
schema: GraphQLSchema,
4239
typeNode: TypeNode,
4340
): 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);
5252
}
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));
6053
}

0 commit comments

Comments
 (0)