1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, '__esModule', {
|
4 | value: true,
|
5 | });
|
6 | exports.sortValueNode = sortValueNode;
|
7 |
|
8 | var _naturalCompare = require('../jsutils/naturalCompare.js');
|
9 |
|
10 | var _kinds = require('../language/kinds.js');
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 | function sortValueNode(valueNode) {
|
20 | switch (valueNode.kind) {
|
21 | case _kinds.Kind.OBJECT:
|
22 | return { ...valueNode, fields: sortFields(valueNode.fields) };
|
23 |
|
24 | case _kinds.Kind.LIST:
|
25 | return { ...valueNode, values: valueNode.values.map(sortValueNode) };
|
26 |
|
27 | case _kinds.Kind.INT:
|
28 | case _kinds.Kind.FLOAT:
|
29 | case _kinds.Kind.STRING:
|
30 | case _kinds.Kind.BOOLEAN:
|
31 | case _kinds.Kind.NULL:
|
32 | case _kinds.Kind.ENUM:
|
33 | case _kinds.Kind.VARIABLE:
|
34 | return valueNode;
|
35 | }
|
36 | }
|
37 |
|
38 | function sortFields(fields) {
|
39 | return fields
|
40 | .map((fieldNode) => ({
|
41 | ...fieldNode,
|
42 | value: sortValueNode(fieldNode.value),
|
43 | }))
|
44 | .sort((fieldA, fieldB) =>
|
45 | (0, _naturalCompare.naturalCompare)(fieldA.name.value, fieldB.name.value),
|
46 | );
|
47 | }
|