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 |
|
21 | function astFromValueUntyped(value) {
|
22 |
|
23 | if (value === null) {
|
24 | return { kind: graphql_1.Kind.NULL };
|
25 | }
|
26 |
|
27 | if (value === undefined) {
|
28 | return null;
|
29 | }
|
30 |
|
31 |
|
32 | if (Array.isArray(value)) {
|
33 | const valuesNodes = [];
|
34 | for (const item of value) {
|
35 | const itemNode = astFromValueUntyped(item);
|
36 | if (itemNode != null) {
|
37 | valuesNodes.push(itemNode);
|
38 | }
|
39 | }
|
40 | return { kind: graphql_1.Kind.LIST, values: valuesNodes };
|
41 | }
|
42 | if (typeof value === 'object') {
|
43 | if (value?.toJSON) {
|
44 | return astFromValueUntyped(value.toJSON());
|
45 | }
|
46 | const fieldNodes = [];
|
47 | for (const fieldName in value) {
|
48 | const fieldValue = value[fieldName];
|
49 | const ast = astFromValueUntyped(fieldValue);
|
50 | if (ast) {
|
51 | fieldNodes.push({
|
52 | kind: graphql_1.Kind.OBJECT_FIELD,
|
53 | name: { kind: graphql_1.Kind.NAME, value: fieldName },
|
54 | value: ast,
|
55 | });
|
56 | }
|
57 | }
|
58 | return { kind: graphql_1.Kind.OBJECT, fields: fieldNodes };
|
59 | }
|
60 |
|
61 | if (typeof value === 'boolean') {
|
62 | return { kind: graphql_1.Kind.BOOLEAN, value };
|
63 | }
|
64 | if (typeof value === 'bigint') {
|
65 | return { kind: graphql_1.Kind.INT, value: String(value) };
|
66 | }
|
67 |
|
68 | if (typeof value === 'number' && isFinite(value)) {
|
69 | const stringNum = String(value);
|
70 | return integerStringRegExp.test(stringNum)
|
71 | ? { kind: graphql_1.Kind.INT, value: stringNum }
|
72 | : { kind: graphql_1.Kind.FLOAT, value: stringNum };
|
73 | }
|
74 | if (typeof value === 'string') {
|
75 | return { kind: graphql_1.Kind.STRING, value };
|
76 | }
|
77 | throw new TypeError(`Cannot convert value to AST: ${value}.`);
|
78 | }
|
79 | exports.astFromValueUntyped = astFromValueUntyped;
|
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 | const integerStringRegExp = /^-?(?:0|[1-9][0-9]*)$/;
|