UNPKG

1.74 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.typeFromAST = typeFromAST;
7
8var _kinds = require('../language/kinds');
9
10var Kind = _interopRequireWildcard(_kinds);
11
12var _wrappers = require('../type/wrappers');
13
14function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
15
16/**
17 * Given a Schema and an AST node describing a type, return a GraphQLType
18 * definition which applies to that type. For example, if provided the parsed
19 * AST node for `[User]`, a GraphQLList instance will be returned, containing
20 * the type called "User" found in the schema. If a type called "User" is not
21 * found in the schema, then undefined will be returned.
22 */
23/* eslint-disable no-redeclare */
24/**
25 * Copyright (c) 2015-present, Facebook, Inc.
26 *
27 * This source code is licensed under the MIT license found in the
28 * LICENSE file in the root directory of this source tree.
29 *
30 *
31 */
32
33function typeFromAST(schema, typeNode) {
34 /* eslint-enable no-redeclare */
35 var innerType = void 0;
36 if (typeNode.kind === Kind.LIST_TYPE) {
37 innerType = typeFromAST(schema, typeNode.type);
38 return innerType && (0, _wrappers.GraphQLList)(innerType);
39 }
40 if (typeNode.kind === Kind.NON_NULL_TYPE) {
41 innerType = typeFromAST(schema, typeNode.type);
42 return innerType && (0, _wrappers.GraphQLNonNull)(innerType);
43 }
44 if (typeNode.kind === Kind.NAMED_TYPE) {
45 return schema.getType(typeNode.name.value);
46 }
47 /* istanbul ignore next */
48 throw new Error('Unexpected type kind: ' + typeNode.kind + '.');
49}
\No newline at end of file