1 | import { keyValMap } from '../jsutils/keyValMap.mjs';
|
2 | import { Kind } from '../language/kinds.mjs';
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 | export function valueFromASTUntyped(valueNode, variables) {
|
21 | switch (valueNode.kind) {
|
22 | case Kind.NULL:
|
23 | return null;
|
24 |
|
25 | case Kind.INT:
|
26 | return parseInt(valueNode.value, 10);
|
27 |
|
28 | case Kind.FLOAT:
|
29 | return parseFloat(valueNode.value);
|
30 |
|
31 | case Kind.STRING:
|
32 | case Kind.ENUM:
|
33 | case Kind.BOOLEAN:
|
34 | return valueNode.value;
|
35 |
|
36 | case Kind.LIST:
|
37 | return valueNode.values.map((node) =>
|
38 | valueFromASTUntyped(node, variables),
|
39 | );
|
40 |
|
41 | case Kind.OBJECT:
|
42 | return keyValMap(
|
43 | valueNode.fields,
|
44 | (field) => field.name.value,
|
45 | (field) => valueFromASTUntyped(field.value, variables),
|
46 | );
|
47 |
|
48 | case Kind.VARIABLE:
|
49 | return variables === null || variables === void 0
|
50 | ? void 0
|
51 | : variables[valueNode.name.value];
|
52 | }
|
53 | }
|