graphql 15.10.3 → 15.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. package/error/GraphQLError.js +7 -6
  2. package/error/GraphQLError.js.flow +3 -3
  3. package/error/GraphQLError.mjs +8 -7
  4. package/execution/execute.d.ts +2 -0
  5. package/execution/execute.js +33 -12
  6. package/execution/execute.js.flow +32 -11
  7. package/execution/execute.mjs +33 -12
  8. package/execution/values.d.ts +1 -1
  9. package/execution/values.js +5 -5
  10. package/execution/values.js.flow +5 -2
  11. package/execution/values.mjs +4 -4
  12. package/graphql.d.ts +1 -0
  13. package/graphql.js +4 -1
  14. package/graphql.js.flow +5 -1
  15. package/graphql.mjs +4 -1
  16. package/jsutils/SetMap.js +56 -0
  17. package/jsutils/SetMap.js.flow +39 -0
  18. package/jsutils/SetMap.mjs +47 -0
  19. package/language/lexer.js +21 -2
  20. package/language/lexer.js.flow +24 -2
  21. package/language/lexer.mjs +21 -2
  22. package/language/location.d.ts +5 -0
  23. package/language/location.js +64 -0
  24. package/language/location.js.flow +39 -0
  25. package/language/location.mjs +62 -0
  26. package/language/parser.js +34 -19
  27. package/language/parser.js.flow +54 -10
  28. package/language/parser.mjs +34 -19
  29. package/language/printer.d.ts +7 -0
  30. package/language/printer.js +251 -118
  31. package/language/printer.js.flow +345 -141
  32. package/language/printer.mjs +246 -116
  33. package/language/reducer.js +99 -0
  34. package/language/reducer.js.flow +89 -0
  35. package/language/reducer.mjs +89 -0
  36. package/package.json +1 -1
  37. package/subscription/subscribe.d.ts +2 -0
  38. package/subscription/subscribe.js +4 -3
  39. package/subscription/subscribe.js.flow +6 -0
  40. package/subscription/subscribe.mjs +4 -3
  41. package/type/definition.d.ts +2 -1
  42. package/type/definition.js +8 -8
  43. package/type/definition.js.flow +13 -7
  44. package/type/definition.mjs +7 -7
  45. package/type/scalars.js +5 -5
  46. package/type/scalars.js.flow +1 -1
  47. package/type/scalars.mjs +1 -1
  48. package/utilities/buildASTSchema.js +3 -0
  49. package/utilities/buildASTSchema.js.flow +3 -0
  50. package/utilities/buildASTSchema.mjs +3 -0
  51. package/utilities/coerceInputValue.d.ts +1 -0
  52. package/utilities/coerceInputValue.js +9 -8
  53. package/utilities/coerceInputValue.js.flow +42 -9
  54. package/utilities/coerceInputValue.mjs +10 -9
  55. package/utilities/findBreakingChanges.js +3 -23
  56. package/utilities/findBreakingChanges.js.flow +2 -15
  57. package/utilities/findBreakingChanges.mjs +2 -21
  58. package/utilities/sortValueNode.js +52 -0
  59. package/utilities/sortValueNode.js.flow +42 -0
  60. package/utilities/sortValueNode.mjs +42 -0
  61. package/utilities/valueFromAST.js +2 -2
  62. package/utilities/valueFromAST.js.flow +8 -2
  63. package/utilities/valueFromAST.mjs +2 -2
  64. package/validation/ValidationContext.d.ts +8 -0
  65. package/validation/ValidationContext.js +82 -24
  66. package/validation/ValidationContext.js.flow +70 -21
  67. package/validation/ValidationContext.mjs +80 -24
  68. package/validation/rules/FieldsOnCorrectTypeRule.js +2 -2
  69. package/validation/rules/FieldsOnCorrectTypeRule.js.flow +8 -2
  70. package/validation/rules/FieldsOnCorrectTypeRule.mjs +2 -2
  71. package/validation/rules/KnownArgumentNamesRule.js +8 -9
  72. package/validation/rules/KnownArgumentNamesRule.js.flow +16 -6
  73. package/validation/rules/KnownArgumentNamesRule.mjs +8 -9
  74. package/validation/rules/KnownTypeNamesRule.js +1 -1
  75. package/validation/rules/KnownTypeNamesRule.js.flow +6 -4
  76. package/validation/rules/KnownTypeNamesRule.mjs +1 -1
  77. package/validation/rules/MaxIntrospectionDepthRule.js +37 -17
  78. package/validation/rules/MaxIntrospectionDepthRule.js.flow +46 -15
  79. package/validation/rules/MaxIntrospectionDepthRule.mjs +37 -17
  80. package/validation/rules/NoUnusedFragmentsRule.js +6 -13
  81. package/validation/rules/NoUnusedFragmentsRule.js.flow +6 -10
  82. package/validation/rules/NoUnusedFragmentsRule.mjs +6 -13
  83. package/validation/rules/OverlappingFieldsCanBeMergedRule.js +402 -208
  84. package/validation/rules/OverlappingFieldsCanBeMergedRule.js.flow +566 -330
  85. package/validation/rules/OverlappingFieldsCanBeMergedRule.mjs +400 -206
  86. package/validation/rules/ValuesOfCorrectTypeRule.js +6 -6
  87. package/validation/rules/ValuesOfCorrectTypeRule.js.flow +11 -6
  88. package/validation/rules/ValuesOfCorrectTypeRule.mjs +4 -4
  89. package/validation/validate.d.ts +1 -1
  90. package/validation/validate.js +6 -2
  91. package/validation/validate.js.flow +8 -2
  92. package/validation/validate.mjs +5 -2
  93. package/validation/validationAbortedError.d.ts +4 -0
  94. package/validation/validationAbortedError.js +12 -0
  95. package/validation/validationAbortedError.js.flow +7 -0
  96. package/validation/validationAbortedError.mjs +4 -0
  97. package/version.js +3 -3
  98. package/version.js.flow +3 -3
  99. package/version.mjs +3 -3
@@ -40,7 +40,8 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
40
40
  */
41
41
  function coerceInputValue(inputValue, type) {
42
42
  var onError = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : defaultOnError;
43
- return coerceInputValueImpl(inputValue, type, onError);
43
+ var hideSuggestions = arguments.length > 3 ? arguments[3] : undefined;
44
+ return coerceInputValueImpl(inputValue, type, onError, undefined, hideSuggestions);
44
45
  }
45
46
 
46
47
  function defaultOnError(path, invalidValue, error) {
@@ -54,10 +55,10 @@ function defaultOnError(path, invalidValue, error) {
54
55
  throw error;
55
56
  }
56
57
 
57
- function coerceInputValueImpl(inputValue, type, onError, path) {
58
+ function coerceInputValueImpl(inputValue, type, onError, path, hideSuggestions) {
58
59
  if ((0, _definition.isNonNullType)(type)) {
59
60
  if (inputValue != null) {
60
- return coerceInputValueImpl(inputValue, type.ofType, onError, path);
61
+ return coerceInputValueImpl(inputValue, type.ofType, onError, path, hideSuggestions);
61
62
  }
62
63
 
63
64
  onError((0, _Path.pathToArray)(path), inputValue, new _GraphQLError.GraphQLError("Expected non-nullable type \"".concat((0, _inspect.default)(type), "\" not to be null.")));
@@ -73,7 +74,7 @@ function coerceInputValueImpl(inputValue, type, onError, path) {
73
74
  var itemType = type.ofType;
74
75
  var coercedList = (0, _safeArrayFrom.default)(inputValue, function (itemValue, index) {
75
76
  var itemPath = (0, _Path.addPath)(path, index, undefined);
76
- return coerceInputValueImpl(itemValue, itemType, onError, itemPath);
77
+ return coerceInputValueImpl(itemValue, itemType, onError, itemPath, hideSuggestions);
77
78
  });
78
79
 
79
80
  if (coercedList != null) {
@@ -81,7 +82,7 @@ function coerceInputValueImpl(inputValue, type, onError, path) {
81
82
  } // Lists accept a non-list value as a list of one.
82
83
 
83
84
 
84
- return [coerceInputValueImpl(inputValue, itemType, onError, path)];
85
+ return [coerceInputValueImpl(inputValue, itemType, onError, path, hideSuggestions)];
85
86
  }
86
87
 
87
88
  if ((0, _definition.isInputObjectType)(type)) {
@@ -108,7 +109,7 @@ function coerceInputValueImpl(inputValue, type, onError, path) {
108
109
  continue;
109
110
  }
110
111
 
111
- coercedValue[field.name] = coerceInputValueImpl(fieldValue, field.type, onError, (0, _Path.addPath)(path, field.name, type.name));
112
+ coercedValue[field.name] = coerceInputValueImpl(fieldValue, field.type, onError, (0, _Path.addPath)(path, field.name, type.name), hideSuggestions);
112
113
  } // Ensure every provided field is defined.
113
114
 
114
115
 
@@ -116,7 +117,7 @@ function coerceInputValueImpl(inputValue, type, onError, path) {
116
117
  var fieldName = _Object$keys2[_i4];
117
118
 
118
119
  if (!fieldDefs[fieldName]) {
119
- var suggestions = (0, _suggestionList.default)(fieldName, Object.keys(type.getFields()));
120
+ var suggestions = hideSuggestions === true ? [] : (0, _suggestionList.default)(fieldName, Object.keys(type.getFields()));
120
121
  onError((0, _Path.pathToArray)(path), inputValue, new _GraphQLError.GraphQLError("Field \"".concat(fieldName, "\" is not defined by type \"").concat(type.name, "\".") + (0, _didYouMean.default)(suggestions)));
121
122
  }
122
123
  }
@@ -131,7 +132,7 @@ function coerceInputValueImpl(inputValue, type, onError, path) {
131
132
  // to the original error.
132
133
 
133
134
  try {
134
- parseResult = type.parseValue(inputValue);
135
+ parseResult = (0, _definition.isEnumType)(type) ? type.parseValue(inputValue, hideSuggestions) : type.parseValue(inputValue);
135
136
  } catch (error) {
136
137
  if (error instanceof _GraphQLError.GraphQLError) {
137
138
  onError((0, _Path.pathToArray)(path), inputValue, error);
@@ -17,6 +17,7 @@ import type { GraphQLInputType } from '../type/definition';
17
17
  import {
18
18
  isLeafType,
19
19
  isInputObjectType,
20
+ isEnumType,
20
21
  isListType,
21
22
  isNonNullType,
22
23
  } from '../type/definition';
@@ -33,9 +34,17 @@ type OnErrorCB = (
33
34
  export function coerceInputValue(
34
35
  inputValue: mixed,
35
36
  type: GraphQLInputType,
37
+ // eslint-disable-next-line default-param-last
36
38
  onError: OnErrorCB = defaultOnError,
39
+ hideSuggestions?: ?boolean,
37
40
  ): mixed {
38
- return coerceInputValueImpl(inputValue, type, onError);
41
+ return coerceInputValueImpl(
42
+ inputValue,
43
+ type,
44
+ onError,
45
+ undefined,
46
+ hideSuggestions,
47
+ );
39
48
  }
40
49
 
41
50
  function defaultOnError(
@@ -56,10 +65,17 @@ function coerceInputValueImpl(
56
65
  type: GraphQLInputType,
57
66
  onError: OnErrorCB,
58
67
  path: Path | void,
68
+ hideSuggestions?: ?boolean,
59
69
  ): mixed {
60
70
  if (isNonNullType(type)) {
61
71
  if (inputValue != null) {
62
- return coerceInputValueImpl(inputValue, type.ofType, onError, path);
72
+ return coerceInputValueImpl(
73
+ inputValue,
74
+ type.ofType,
75
+ onError,
76
+ path,
77
+ hideSuggestions,
78
+ );
63
79
  }
64
80
  onError(
65
81
  pathToArray(path),
@@ -81,7 +97,13 @@ function coerceInputValueImpl(
81
97
 
82
98
  const coercedList = safeArrayFrom(inputValue, (itemValue, index) => {
83
99
  const itemPath = addPath(path, index, undefined);
84
- return coerceInputValueImpl(itemValue, itemType, onError, itemPath);
100
+ return coerceInputValueImpl(
101
+ itemValue,
102
+ itemType,
103
+ onError,
104
+ itemPath,
105
+ hideSuggestions,
106
+ );
85
107
  });
86
108
 
87
109
  if (coercedList != null) {
@@ -89,7 +111,15 @@ function coerceInputValueImpl(
89
111
  }
90
112
 
91
113
  // Lists accept a non-list value as a list of one.
92
- return [coerceInputValueImpl(inputValue, itemType, onError, path)];
114
+ return [
115
+ coerceInputValueImpl(
116
+ inputValue,
117
+ itemType,
118
+ onError,
119
+ path,
120
+ hideSuggestions,
121
+ ),
122
+ ];
93
123
  }
94
124
 
95
125
  if (isInputObjectType(type)) {
@@ -129,16 +159,17 @@ function coerceInputValueImpl(
129
159
  field.type,
130
160
  onError,
131
161
  addPath(path, field.name, type.name),
162
+ hideSuggestions,
132
163
  );
133
164
  }
134
165
 
135
166
  // Ensure every provided field is defined.
136
167
  for (const fieldName of Object.keys(inputValue)) {
137
168
  if (!fieldDefs[fieldName]) {
138
- const suggestions = suggestionList(
139
- fieldName,
140
- Object.keys(type.getFields()),
141
- );
169
+ const suggestions =
170
+ hideSuggestions === true
171
+ ? []
172
+ : suggestionList(fieldName, Object.keys(type.getFields()));
142
173
  onError(
143
174
  pathToArray(path),
144
175
  inputValue,
@@ -160,7 +191,9 @@ function coerceInputValueImpl(
160
191
  // which can throw to indicate failure. If it throws, maintain a reference
161
192
  // to the original error.
162
193
  try {
163
- parseResult = type.parseValue(inputValue);
194
+ parseResult = isEnumType(type)
195
+ ? type.parseValue(inputValue, hideSuggestions)
196
+ : type.parseValue(inputValue);
164
197
  } catch (error) {
165
198
  if (error instanceof GraphQLError) {
166
199
  onError(pathToArray(path), inputValue, error);
@@ -14,14 +14,15 @@ import suggestionList from "../jsutils/suggestionList.mjs";
14
14
  import printPathArray from "../jsutils/printPathArray.mjs";
15
15
  import { addPath, pathToArray } from "../jsutils/Path.mjs";
16
16
  import { GraphQLError } from "../error/GraphQLError.mjs";
17
- import { isLeafType, isInputObjectType, isListType, isNonNullType } from "../type/definition.mjs";
17
+ import { isLeafType, isInputObjectType, isEnumType, isListType, isNonNullType } from "../type/definition.mjs";
18
18
 
19
19
  /**
20
20
  * Coerces a JavaScript value given a GraphQL Input Type.
21
21
  */
22
22
  export function coerceInputValue(inputValue, type) {
23
23
  var onError = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : defaultOnError;
24
- return coerceInputValueImpl(inputValue, type, onError);
24
+ var hideSuggestions = arguments.length > 3 ? arguments[3] : undefined;
25
+ return coerceInputValueImpl(inputValue, type, onError, undefined, hideSuggestions);
25
26
  }
26
27
 
27
28
  function defaultOnError(path, invalidValue, error) {
@@ -35,10 +36,10 @@ function defaultOnError(path, invalidValue, error) {
35
36
  throw error;
36
37
  }
37
38
 
38
- function coerceInputValueImpl(inputValue, type, onError, path) {
39
+ function coerceInputValueImpl(inputValue, type, onError, path, hideSuggestions) {
39
40
  if (isNonNullType(type)) {
40
41
  if (inputValue != null) {
41
- return coerceInputValueImpl(inputValue, type.ofType, onError, path);
42
+ return coerceInputValueImpl(inputValue, type.ofType, onError, path, hideSuggestions);
42
43
  }
43
44
 
44
45
  onError(pathToArray(path), inputValue, new GraphQLError("Expected non-nullable type \"".concat(inspect(type), "\" not to be null.")));
@@ -54,7 +55,7 @@ function coerceInputValueImpl(inputValue, type, onError, path) {
54
55
  var itemType = type.ofType;
55
56
  var coercedList = safeArrayFrom(inputValue, function (itemValue, index) {
56
57
  var itemPath = addPath(path, index, undefined);
57
- return coerceInputValueImpl(itemValue, itemType, onError, itemPath);
58
+ return coerceInputValueImpl(itemValue, itemType, onError, itemPath, hideSuggestions);
58
59
  });
59
60
 
60
61
  if (coercedList != null) {
@@ -62,7 +63,7 @@ function coerceInputValueImpl(inputValue, type, onError, path) {
62
63
  } // Lists accept a non-list value as a list of one.
63
64
 
64
65
 
65
- return [coerceInputValueImpl(inputValue, itemType, onError, path)];
66
+ return [coerceInputValueImpl(inputValue, itemType, onError, path, hideSuggestions)];
66
67
  }
67
68
 
68
69
  if (isInputObjectType(type)) {
@@ -89,7 +90,7 @@ function coerceInputValueImpl(inputValue, type, onError, path) {
89
90
  continue;
90
91
  }
91
92
 
92
- coercedValue[field.name] = coerceInputValueImpl(fieldValue, field.type, onError, addPath(path, field.name, type.name));
93
+ coercedValue[field.name] = coerceInputValueImpl(fieldValue, field.type, onError, addPath(path, field.name, type.name), hideSuggestions);
93
94
  } // Ensure every provided field is defined.
94
95
 
95
96
 
@@ -97,7 +98,7 @@ function coerceInputValueImpl(inputValue, type, onError, path) {
97
98
  var fieldName = _Object$keys2[_i4];
98
99
 
99
100
  if (!fieldDefs[fieldName]) {
100
- var suggestions = suggestionList(fieldName, Object.keys(type.getFields()));
101
+ var suggestions = hideSuggestions === true ? [] : suggestionList(fieldName, Object.keys(type.getFields()));
101
102
  onError(pathToArray(path), inputValue, new GraphQLError("Field \"".concat(fieldName, "\" is not defined by type \"").concat(type.name, "\".") + didYouMean(suggestions)));
102
103
  }
103
104
  }
@@ -112,7 +113,7 @@ function coerceInputValueImpl(inputValue, type, onError, path) {
112
113
  // to the original error.
113
114
 
114
115
  try {
115
- parseResult = type.parseValue(inputValue);
116
+ parseResult = isEnumType(type) ? type.parseValue(inputValue, hideSuggestions) : type.parseValue(inputValue);
116
117
  } catch (error) {
117
118
  if (error instanceof GraphQLError) {
118
119
  onError(pathToArray(path), inputValue, error);
@@ -15,25 +15,17 @@ var _inspect = _interopRequireDefault(require("../jsutils/inspect.js"));
15
15
 
16
16
  var _invariant = _interopRequireDefault(require("../jsutils/invariant.js"));
17
17
 
18
- var _naturalCompare = _interopRequireDefault(require("../jsutils/naturalCompare.js"));
19
-
20
18
  var _printer = require("../language/printer.js");
21
19
 
22
- var _visitor = require("../language/visitor.js");
23
-
24
20
  var _scalars = require("../type/scalars.js");
25
21
 
26
22
  var _definition = require("../type/definition.js");
27
23
 
28
24
  var _astFromValue = require("./astFromValue.js");
29
25
 
30
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
31
-
32
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
33
-
34
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
26
+ var _sortValueNode = require("./sortValueNode.js");
35
27
 
36
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
28
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
37
29
 
38
30
  var BreakingChangeType = Object.freeze({
39
31
  TYPE_REMOVED: 'TYPE_REMOVED',
@@ -467,19 +459,7 @@ function typeKindName(type) {
467
459
  function stringifyValue(value, type) {
468
460
  var ast = (0, _astFromValue.astFromValue)(value, type);
469
461
  ast != null || (0, _invariant.default)(0);
470
- var sortedAST = (0, _visitor.visit)(ast, {
471
- ObjectValue: function ObjectValue(objectNode) {
472
- // Make a copy since sort mutates array
473
- var fields = [].concat(objectNode.fields);
474
- fields.sort(function (fieldA, fieldB) {
475
- return (0, _naturalCompare.default)(fieldA.name.value, fieldB.name.value);
476
- });
477
- return _objectSpread(_objectSpread({}, objectNode), {}, {
478
- fields: fields
479
- });
480
- }
481
- });
482
- return (0, _printer.print)(sortedAST);
462
+ return (0, _printer.print)((0, _sortValueNode.sortValueNode)(ast));
483
463
  }
484
464
 
485
465
  function diff(oldArray, newArray) {
@@ -4,10 +4,8 @@ import objectValues from '../polyfills/objectValues';
4
4
  import keyMap from '../jsutils/keyMap';
5
5
  import inspect from '../jsutils/inspect';
6
6
  import invariant from '../jsutils/invariant';
7
- import naturalCompare from '../jsutils/naturalCompare';
8
7
 
9
8
  import { print } from '../language/printer';
10
- import { visit } from '../language/visitor';
11
9
 
12
10
  import type { GraphQLSchema } from '../type/schema';
13
11
  import type {
@@ -37,6 +35,7 @@ import {
37
35
  } from '../type/definition';
38
36
 
39
37
  import { astFromValue } from './astFromValue';
38
+ import { sortValueNode } from './sortValueNode';
40
39
 
41
40
  export const BreakingChangeType = Object.freeze({
42
41
  TYPE_REMOVED: 'TYPE_REMOVED',
@@ -541,19 +540,7 @@ function stringifyValue(value: mixed, type: GraphQLInputType): string {
541
540
  const ast = astFromValue(value, type);
542
541
  invariant(ast != null);
543
542
 
544
- const sortedAST = visit(ast, {
545
- ObjectValue(objectNode) {
546
- // Make a copy since sort mutates array
547
- const fields = [...objectNode.fields];
548
-
549
- fields.sort((fieldA, fieldB) =>
550
- naturalCompare(fieldA.name.value, fieldB.name.value),
551
- );
552
- return { ...objectNode, fields };
553
- },
554
- });
555
-
556
- return print(sortedAST);
543
+ return print(sortValueNode(ast));
557
544
  }
558
545
 
559
546
  function diff<T: { name: string, ... }>(
@@ -1,19 +1,12 @@
1
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
2
-
3
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
4
-
5
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
-
7
1
  import objectValues from "../polyfills/objectValues.mjs";
8
2
  import keyMap from "../jsutils/keyMap.mjs";
9
3
  import inspect from "../jsutils/inspect.mjs";
10
4
  import invariant from "../jsutils/invariant.mjs";
11
- import naturalCompare from "../jsutils/naturalCompare.mjs";
12
5
  import { print } from "../language/printer.mjs";
13
- import { visit } from "../language/visitor.mjs";
14
6
  import { isSpecifiedScalarType } from "../type/scalars.mjs";
15
7
  import { isScalarType, isObjectType, isInterfaceType, isUnionType, isEnumType, isInputObjectType, isNonNullType, isListType, isNamedType, isRequiredArgument, isRequiredInputField } from "../type/definition.mjs";
16
8
  import { astFromValue } from "./astFromValue.mjs";
9
+ import { sortValueNode } from "./sortValueNode.mjs";
17
10
  export var BreakingChangeType = Object.freeze({
18
11
  TYPE_REMOVED: 'TYPE_REMOVED',
19
12
  TYPE_CHANGED_KIND: 'TYPE_CHANGED_KIND',
@@ -443,19 +436,7 @@ function typeKindName(type) {
443
436
  function stringifyValue(value, type) {
444
437
  var ast = astFromValue(value, type);
445
438
  ast != null || invariant(0);
446
- var sortedAST = visit(ast, {
447
- ObjectValue: function ObjectValue(objectNode) {
448
- // Make a copy since sort mutates array
449
- var fields = [].concat(objectNode.fields);
450
- fields.sort(function (fieldA, fieldB) {
451
- return naturalCompare(fieldA.name.value, fieldB.name.value);
452
- });
453
- return _objectSpread(_objectSpread({}, objectNode), {}, {
454
- fields: fields
455
- });
456
- }
457
- });
458
- return print(sortedAST);
439
+ return print(sortValueNode(ast));
459
440
  }
460
441
 
461
442
  function diff(oldArray, newArray) {
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.sortValueNode = sortValueNode;
7
+
8
+ var _naturalCompare = _interopRequireDefault(require("../jsutils/naturalCompare.js"));
9
+
10
+ var _kinds = require("../language/kinds.js");
11
+
12
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
+
14
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
15
+
16
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
17
+
18
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
19
+
20
+ /**
21
+ * Sort ValueNode.
22
+ *
23
+ * This function returns a sorted copy of the given ValueNode.
24
+ *
25
+ * @internal
26
+ */
27
+ function sortValueNode(valueNode) {
28
+ switch (valueNode.kind) {
29
+ case _kinds.Kind.OBJECT:
30
+ return _objectSpread(_objectSpread({}, valueNode), {}, {
31
+ fields: sortFields(valueNode.fields)
32
+ });
33
+
34
+ case _kinds.Kind.LIST:
35
+ return _objectSpread(_objectSpread({}, valueNode), {}, {
36
+ values: valueNode.values.map(sortValueNode)
37
+ });
38
+
39
+ default:
40
+ return valueNode;
41
+ }
42
+ }
43
+
44
+ function sortFields(fields) {
45
+ return fields.map(function (fieldNode) {
46
+ return _objectSpread(_objectSpread({}, fieldNode), {}, {
47
+ value: sortValueNode(fieldNode.value)
48
+ });
49
+ }).sort(function (fieldA, fieldB) {
50
+ return (0, _naturalCompare.default)(fieldA.name.value, fieldB.name.value);
51
+ });
52
+ }
@@ -0,0 +1,42 @@
1
+ // @flow strict
2
+ import naturalCompare from '../jsutils/naturalCompare';
3
+
4
+ import type { ObjectFieldNode, ValueNode } from '../language/ast';
5
+ import { Kind } from '../language/kinds';
6
+
7
+ /**
8
+ * Sort ValueNode.
9
+ *
10
+ * This function returns a sorted copy of the given ValueNode.
11
+ *
12
+ * @internal
13
+ */
14
+ export function sortValueNode(valueNode: ValueNode): ValueNode {
15
+ switch (valueNode.kind) {
16
+ case Kind.OBJECT:
17
+ return {
18
+ ...valueNode,
19
+ fields: sortFields(valueNode.fields),
20
+ };
21
+ case Kind.LIST:
22
+ return {
23
+ ...valueNode,
24
+ values: valueNode.values.map(sortValueNode),
25
+ };
26
+ default:
27
+ return valueNode;
28
+ }
29
+ }
30
+
31
+ function sortFields(
32
+ fields: $ReadOnlyArray<ObjectFieldNode>,
33
+ ): Array<ObjectFieldNode> {
34
+ return fields
35
+ .map((fieldNode) => ({
36
+ ...fieldNode,
37
+ value: sortValueNode(fieldNode.value),
38
+ }))
39
+ .sort((fieldA, fieldB) =>
40
+ naturalCompare(fieldA.name.value, fieldB.name.value),
41
+ );
42
+ }
@@ -0,0 +1,42 @@
1
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
2
+
3
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
4
+
5
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
+
7
+ import naturalCompare from "../jsutils/naturalCompare.mjs";
8
+ import { Kind } from "../language/kinds.mjs";
9
+ /**
10
+ * Sort ValueNode.
11
+ *
12
+ * This function returns a sorted copy of the given ValueNode.
13
+ *
14
+ * @internal
15
+ */
16
+
17
+ export function sortValueNode(valueNode) {
18
+ switch (valueNode.kind) {
19
+ case Kind.OBJECT:
20
+ return _objectSpread(_objectSpread({}, valueNode), {}, {
21
+ fields: sortFields(valueNode.fields)
22
+ });
23
+
24
+ case Kind.LIST:
25
+ return _objectSpread(_objectSpread({}, valueNode), {}, {
26
+ values: valueNode.values.map(sortValueNode)
27
+ });
28
+
29
+ default:
30
+ return valueNode;
31
+ }
32
+ }
33
+
34
+ function sortFields(fields) {
35
+ return fields.map(function (fieldNode) {
36
+ return _objectSpread(_objectSpread({}, fieldNode), {}, {
37
+ value: sortValueNode(fieldNode.value)
38
+ });
39
+ }).sort(function (fieldA, fieldB) {
40
+ return naturalCompare(fieldA.name.value, fieldB.name.value);
41
+ });
42
+ }
@@ -49,7 +49,7 @@ function valueFromAST(valueNode, type, variables) {
49
49
  if (valueNode.kind === _kinds.Kind.VARIABLE) {
50
50
  var variableName = valueNode.name.value;
51
51
 
52
- if (variables == null || variables[variableName] === undefined) {
52
+ if (variables == null || !Object.prototype.hasOwnProperty.call(variables, variableName) || variables[variableName] === undefined) {
53
53
  // No valid return value.
54
54
  return;
55
55
  }
@@ -182,5 +182,5 @@ function valueFromAST(valueNode, type, variables) {
182
182
 
183
183
 
184
184
  function isMissingVariable(valueNode, variables) {
185
- return valueNode.kind === _kinds.Kind.VARIABLE && (variables == null || variables[valueNode.name.value] === undefined);
185
+ return valueNode.kind === _kinds.Kind.VARIABLE && (variables == null || !Object.prototype.hasOwnProperty.call(variables, valueNode.name.value) || variables[valueNode.name.value] === undefined);
186
186
  }
@@ -50,7 +50,11 @@ export function valueFromAST(
50
50
 
51
51
  if (valueNode.kind === Kind.VARIABLE) {
52
52
  const variableName = valueNode.name.value;
53
- if (variables == null || variables[variableName] === undefined) {
53
+ if (
54
+ variables == null ||
55
+ !Object.prototype.hasOwnProperty.call(variables, variableName) ||
56
+ variables[variableName] === undefined
57
+ ) {
54
58
  // No valid return value.
55
59
  return;
56
60
  }
@@ -159,6 +163,8 @@ function isMissingVariable(
159
163
  ): boolean {
160
164
  return (
161
165
  valueNode.kind === Kind.VARIABLE &&
162
- (variables == null || variables[valueNode.name.value] === undefined)
166
+ (variables == null ||
167
+ !Object.prototype.hasOwnProperty.call(variables, valueNode.name.value) ||
168
+ variables[valueNode.name.value] === undefined)
163
169
  );
164
170
  }
@@ -35,7 +35,7 @@ export function valueFromAST(valueNode, type, variables) {
35
35
  if (valueNode.kind === Kind.VARIABLE) {
36
36
  var variableName = valueNode.name.value;
37
37
 
38
- if (variables == null || variables[variableName] === undefined) {
38
+ if (variables == null || !Object.prototype.hasOwnProperty.call(variables, variableName) || variables[variableName] === undefined) {
39
39
  // No valid return value.
40
40
  return;
41
41
  }
@@ -167,5 +167,5 @@ export function valueFromAST(valueNode, type, variables) {
167
167
  // in the set of variables.
168
168
 
169
169
  function isMissingVariable(valueNode, variables) {
170
- return valueNode.kind === Kind.VARIABLE && (variables == null || variables[valueNode.name.value] === undefined);
170
+ return valueNode.kind === Kind.VARIABLE && (variables == null || !Object.prototype.hasOwnProperty.call(variables, valueNode.name.value) || variables[valueNode.name.value] === undefined);
171
171
  }
@@ -48,9 +48,15 @@ export class ASTValidationContext {
48
48
  getRecursivelyReferencedFragments(
49
49
  operation: OperationDefinitionNode,
50
50
  ): ReadonlyArray<FragmentDefinitionNode>;
51
+ getRecursivelyReferencedFragmentsForOperations(
52
+ operations: ReadonlyArray<OperationDefinitionNode>,
53
+ ): ReadonlyArray<FragmentDefinitionNode>;
54
+ /** @internal */
55
+ spendFragmentWork(cost: number): void;
51
56
  }
52
57
 
53
58
  export class SDLValidationContext extends ASTValidationContext {
59
+ readonly hideSuggestions: boolean;
54
60
  constructor(
55
61
  ast: DocumentNode,
56
62
  schema: Maybe<GraphQLSchema>,
@@ -63,11 +69,13 @@ export class SDLValidationContext extends ASTValidationContext {
63
69
  export type SDLValidationRule = (context: SDLValidationContext) => ASTVisitor;
64
70
 
65
71
  export class ValidationContext extends ASTValidationContext {
72
+ readonly hideSuggestions: boolean;
66
73
  constructor(
67
74
  schema: GraphQLSchema,
68
75
  ast: DocumentNode,
69
76
  typeInfo: TypeInfo,
70
77
  onError: (err: GraphQLError) => void,
78
+ hideSuggestions?: Maybe<boolean>,
71
79
  );
72
80
 
73
81
  getSchema(): GraphQLSchema;