UNPKG

899 BJavaScriptView Raw
1/**
2 * Copyright (c) 2015-present, Facebook, Inc.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 *
7 *
8 */
9import { Kind } from '../language/kinds';
10import { GraphQLList, GraphQLNonNull } from '../type/definition';
11export function typeFromAST(schema, typeNode) {
12 /* eslint-enable no-redeclare */
13 var innerType;
14
15 if (typeNode.kind === Kind.LIST_TYPE) {
16 innerType = typeFromAST(schema, typeNode.type);
17 return innerType && GraphQLList(innerType);
18 }
19
20 if (typeNode.kind === Kind.NON_NULL_TYPE) {
21 innerType = typeFromAST(schema, typeNode.type);
22 return innerType && GraphQLNonNull(innerType);
23 }
24
25 if (typeNode.kind === Kind.NAMED_TYPE) {
26 return schema.getType(typeNode.name.value);
27 }
28 /* istanbul ignore next */
29
30
31 throw new Error("Unexpected type kind: ".concat(typeNode.kind, "."));
32}
\No newline at end of file