UNPKG

graphql

Version:

A Query Language and Runtime which can target any service.

41 lines (32 loc) 1.06 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.typeFromAST = typeFromAST; var _kinds = require("../language/kinds"); var _definition = require("../type/definition"); /** * Copyright (c) 2015-present, Facebook, Inc. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * * strict */ function typeFromAST(schema, typeNode) { /* eslint-enable no-redeclare */ var innerType; if (typeNode.kind === _kinds.Kind.LIST_TYPE) { innerType = typeFromAST(schema, typeNode.type); return innerType && (0, _definition.GraphQLList)(innerType); } if (typeNode.kind === _kinds.Kind.NON_NULL_TYPE) { innerType = typeFromAST(schema, typeNode.type); return innerType && (0, _definition.GraphQLNonNull)(innerType); } if (typeNode.kind === _kinds.Kind.NAMED_TYPE) { return schema.getType(typeNode.name.value); } /* istanbul ignore next */ throw new Error("Unexpected type kind: ".concat(typeNode.kind, ".")); }