1 | import inspect from '../jsutils/inspect';
|
2 | import invariant from '../jsutils/invariant';
|
3 | import { Kind } from '../language/kinds';
|
4 | import { GraphQLList, GraphQLNonNull } from '../type/definition';
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 | export function typeFromAST(schema, typeNode) {
|
16 |
|
17 | var innerType;
|
18 |
|
19 | if (typeNode.kind === Kind.LIST_TYPE) {
|
20 | innerType = typeFromAST(schema, typeNode.type);
|
21 | return innerType && GraphQLList(innerType);
|
22 | }
|
23 |
|
24 | if (typeNode.kind === Kind.NON_NULL_TYPE) {
|
25 | innerType = typeFromAST(schema, typeNode.type);
|
26 | return innerType && GraphQLNonNull(innerType);
|
27 | }
|
28 |
|
29 |
|
30 | if (typeNode.kind === Kind.NAMED_TYPE) {
|
31 | return schema.getType(typeNode.name.value);
|
32 | }
|
33 |
|
34 |
|
35 |
|
36 | invariant(false, 'Unexpected type node: ' + inspect(typeNode));
|
37 | }
|