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