UNPKG

1.01 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.astFromType = void 0;
4const cross_inspect_1 = require("cross-inspect");
5const graphql_1 = require("graphql");
6function astFromType(type) {
7 if ((0, graphql_1.isNonNullType)(type)) {
8 const innerType = astFromType(type.ofType);
9 if (innerType.kind === graphql_1.Kind.NON_NULL_TYPE) {
10 throw new Error(`Invalid type node ${(0, cross_inspect_1.inspect)(type)}. Inner type of non-null type cannot be a non-null type.`);
11 }
12 return {
13 kind: graphql_1.Kind.NON_NULL_TYPE,
14 type: innerType,
15 };
16 }
17 else if ((0, graphql_1.isListType)(type)) {
18 return {
19 kind: graphql_1.Kind.LIST_TYPE,
20 type: astFromType(type.ofType),
21 };
22 }
23 return {
24 kind: graphql_1.Kind.NAMED_TYPE,
25 name: {
26 kind: graphql_1.Kind.NAME,
27 value: type.name,
28 },
29 };
30}
31exports.astFromType = astFromType;