1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.astFromValueUntyped = void 0;
|
4 | const graphql_1 = require("graphql");
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 | function astFromValueUntyped(value) {
|
21 |
|
22 | if (value === null) {
|
23 | return { kind: graphql_1.Kind.NULL };
|
24 | }
|
25 |
|
26 | if (value === undefined) {
|
27 | return null;
|
28 | }
|
29 |
|
30 |
|
31 | if (Array.isArray(value)) {
|
32 | const valuesNodes = [];
|
33 | for (const item of value) {
|
34 | const itemNode = astFromValueUntyped(item);
|
35 | if (itemNode != null) {
|
36 | valuesNodes.push(itemNode);
|
37 | }
|
38 | }
|
39 | return { kind: graphql_1.Kind.LIST, values: valuesNodes };
|
40 | }
|
41 | if (typeof value === 'object') {
|
42 | const fieldNodes = [];
|
43 | for (const fieldName in value) {
|
44 | const fieldValue = value[fieldName];
|
45 | const ast = astFromValueUntyped(fieldValue);
|
46 | if (ast) {
|
47 | fieldNodes.push({
|
48 | kind: graphql_1.Kind.OBJECT_FIELD,
|
49 | name: { kind: graphql_1.Kind.NAME, value: fieldName },
|
50 | value: ast,
|
51 | });
|
52 | }
|
53 | }
|
54 | return { kind: graphql_1.Kind.OBJECT, fields: fieldNodes };
|
55 | }
|
56 |
|
57 | if (typeof value === 'boolean') {
|
58 | return { kind: graphql_1.Kind.BOOLEAN, value };
|
59 | }
|
60 |
|
61 | if (typeof value === 'number' && isFinite(value)) {
|
62 | const stringNum = String(value);
|
63 | return integerStringRegExp.test(stringNum)
|
64 | ? { kind: graphql_1.Kind.INT, value: stringNum }
|
65 | : { kind: graphql_1.Kind.FLOAT, value: stringNum };
|
66 | }
|
67 | if (typeof value === 'string') {
|
68 | return { kind: graphql_1.Kind.STRING, value };
|
69 | }
|
70 | throw new TypeError(`Cannot convert value to AST: ${value}.`);
|
71 | }
|
72 | exports.astFromValueUntyped = astFromValueUntyped;
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 | const integerStringRegExp = /^-?(?:0|[1-9][0-9]*)$/;
|