UNPKG

1.51 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3var graphql_1 = require("graphql");
4var debugging_1 = require("../debugging");
5function isRequired(type) {
6 var stringType = String(type);
7 return stringType.lastIndexOf('!') === stringType.length - 1;
8}
9exports.isRequired = isRequired;
10function isNullable(type) {
11 var stringType = String(type);
12 return isArray(type) && !stringType.includes('!]');
13}
14exports.isNullable = isNullable;
15function isArray(type) {
16 return String(type).indexOf('[') > -1;
17}
18exports.isArray = isArray;
19function dimensionOfArray(type) {
20 if (isArray(type)) {
21 var dimension = 0;
22 var characters = Array.from(String(type));
23 for (var _i = 0, characters_1 = characters; _i < characters_1.length; _i++) {
24 var char = characters_1[_i];
25 if (char !== '[') {
26 return dimension;
27 }
28 else {
29 dimension++;
30 }
31 }
32 }
33 return -1;
34}
35exports.dimensionOfArray = dimensionOfArray;
36function resolveType(type) {
37 var name = graphql_1.getNamedType(type).name;
38 debugging_1.debugLog("[resolveType] resolving type " + name);
39 return {
40 name: name,
41 raw: String(type),
42 isRequired: isRequired(type),
43 isArray: isArray(type),
44 isNullableArray: isNullable(type),
45 dimensionOfArray: dimensionOfArray(type)
46 };
47}
48exports.resolveType = resolveType;
49//# sourceMappingURL=resolve-type.js.map
\No newline at end of file