Sha256: 55950edb9cdc22af544a1045e1416a8f46b9b1b586b7f9349e29a9ccfab74262

Contents?: true

Size: 1.08 KB

Versions: 26

Compression:

Stored size: 1.08 KB

Contents

'use strict';

Object.defineProperty(exports, '__esModule', {
  value: true,
});
exports.sortValueNode = sortValueNode;

var _naturalCompare = require('../jsutils/naturalCompare.js');

var _kinds = require('../language/kinds.js');

/**
 * Sort ValueNode.
 *
 * This function returns a sorted copy of the given ValueNode.
 *
 * @internal
 */
function sortValueNode(valueNode) {
  switch (valueNode.kind) {
    case _kinds.Kind.OBJECT:
      return { ...valueNode, fields: sortFields(valueNode.fields) };

    case _kinds.Kind.LIST:
      return { ...valueNode, values: valueNode.values.map(sortValueNode) };

    case _kinds.Kind.INT:
    case _kinds.Kind.FLOAT:
    case _kinds.Kind.STRING:
    case _kinds.Kind.BOOLEAN:
    case _kinds.Kind.NULL:
    case _kinds.Kind.ENUM:
    case _kinds.Kind.VARIABLE:
      return valueNode;
  }
}

function sortFields(fields) {
  return fields
    .map((fieldNode) => ({
      ...fieldNode,
      value: sortValueNode(fieldNode.value),
    }))
    .sort((fieldA, fieldB) =>
      (0, _naturalCompare.naturalCompare)(fieldA.name.value, fieldB.name.value),
    );
}

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
clapton-0.0.26 lib/clapton/javascripts/node_modules/graphql/utilities/sortValueNode.js
clapton-0.0.25 lib/clapton/javascripts/node_modules/graphql/utilities/sortValueNode.js
clapton-0.0.24 lib/clapton/javascripts/node_modules/graphql/utilities/sortValueNode.js
clapton-0.0.23 lib/clapton/javascripts/node_modules/graphql/utilities/sortValueNode.js
clapton-0.0.22 lib/clapton/javascripts/node_modules/graphql/utilities/sortValueNode.js
clapton-0.0.21 lib/clapton/javascripts/node_modules/graphql/utilities/sortValueNode.js
clapton-0.0.20 lib/clapton/javascripts/node_modules/graphql/utilities/sortValueNode.js
clapton-0.0.19 lib/clapton/javascripts/node_modules/graphql/utilities/sortValueNode.js
clapton-0.0.18 lib/clapton/javascripts/node_modules/graphql/utilities/sortValueNode.js
clapton-0.0.17 lib/clapton/javascripts/node_modules/graphql/utilities/sortValueNode.js
clapton-0.0.16 lib/clapton/javascripts/node_modules/graphql/utilities/sortValueNode.js
clapton-0.0.15 lib/clapton/javascripts/node_modules/graphql/utilities/sortValueNode.js
clapton-0.0.14 lib/clapton/javascripts/node_modules/graphql/utilities/sortValueNode.js
clapton-0.0.13 lib/clapton/javascripts/node_modules/graphql/utilities/sortValueNode.js
clapton-0.0.12 lib/clapton/javascripts/node_modules/graphql/utilities/sortValueNode.js
clapton-0.0.11 lib/clapton/javascripts/node_modules/graphql/utilities/sortValueNode.js
clapton-0.0.10 lib/clapton/javascripts/node_modules/graphql/utilities/sortValueNode.js
clapton-0.0.9 lib/clapton/javascripts/node_modules/graphql/utilities/sortValueNode.js
clapton-0.0.8 lib/clapton/javascripts/node_modules/graphql/utilities/sortValueNode.js
clapton-0.0.7 lib/clapton/javascripts/node_modules/graphql/utilities/sortValueNode.js