graphql 15.4.0 → 15.5.3

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 (72) hide show
  1. package/README.md +10 -0
  2. package/error/GraphQLError.js +3 -3
  3. package/error/GraphQLError.js.flow +1 -1
  4. package/error/GraphQLError.mjs +1 -1
  5. package/execution/execute.js +8 -9
  6. package/execution/execute.js.flow +8 -10
  7. package/execution/execute.mjs +8 -8
  8. package/jsutils/instanceOf.js +15 -9
  9. package/jsutils/instanceOf.js.flow +12 -5
  10. package/jsutils/instanceOf.mjs +13 -5
  11. package/jsutils/isAsyncIterable.js +1 -7
  12. package/jsutils/isAsyncIterable.js.flow +1 -5
  13. package/jsutils/isAsyncIterable.mjs +1 -7
  14. package/jsutils/naturalCompare.js +69 -0
  15. package/jsutils/naturalCompare.js.flow +59 -0
  16. package/jsutils/naturalCompare.mjs +61 -0
  17. package/jsutils/safeArrayFrom.js +73 -0
  18. package/jsutils/safeArrayFrom.js.flow +59 -0
  19. package/jsutils/safeArrayFrom.mjs +66 -0
  20. package/jsutils/suggestionList.js +5 -1
  21. package/jsutils/suggestionList.js.flow +3 -1
  22. package/jsutils/suggestionList.mjs +3 -1
  23. package/language/blockString.js.flow +2 -2
  24. package/language/parser.d.ts +456 -1
  25. package/language/source.js.flow +1 -1
  26. package/package.json +2 -3
  27. package/type/definition.js +1 -0
  28. package/type/definition.js.flow +58 -45
  29. package/type/definition.mjs +1 -0
  30. package/type/directives.js.flow +9 -7
  31. package/type/schema.js.flow +1 -1
  32. package/utilities/TypeInfo.js.flow +1 -1
  33. package/utilities/astFromValue.js +6 -8
  34. package/utilities/astFromValue.js.flow +6 -6
  35. package/utilities/astFromValue.mjs +6 -7
  36. package/utilities/buildClientSchema.js +2 -1
  37. package/utilities/buildClientSchema.js.flow +1 -0
  38. package/utilities/buildClientSchema.mjs +2 -1
  39. package/utilities/coerceInputValue.js +7 -8
  40. package/utilities/coerceInputValue.js.flow +11 -8
  41. package/utilities/coerceInputValue.mjs +7 -7
  42. package/utilities/findBreakingChanges.js +6 -2
  43. package/utilities/findBreakingChanges.js.flow +6 -2
  44. package/utilities/findBreakingChanges.mjs +5 -2
  45. package/utilities/getIntrospectionQuery.d.ts +6 -0
  46. package/utilities/getIntrospectionQuery.js +8 -2
  47. package/utilities/getIntrospectionQuery.js.flow +16 -3
  48. package/utilities/getIntrospectionQuery.mjs +8 -2
  49. package/utilities/introspectionFromSchema.js +3 -1
  50. package/utilities/introspectionFromSchema.js.flow +2 -0
  51. package/utilities/introspectionFromSchema.mjs +3 -1
  52. package/utilities/lexicographicSortSchema.js +3 -1
  53. package/utilities/lexicographicSortSchema.js.flow +3 -2
  54. package/utilities/lexicographicSortSchema.mjs +2 -1
  55. package/utilities/separateOperations.js +44 -40
  56. package/utilities/separateOperations.js.flow +46 -36
  57. package/utilities/separateOperations.mjs +44 -40
  58. package/validation/ValidationContext.js.flow +3 -3
  59. package/validation/rules/FieldsOnCorrectTypeRule.js +3 -1
  60. package/validation/rules/FieldsOnCorrectTypeRule.js.flow +2 -1
  61. package/validation/rules/FieldsOnCorrectTypeRule.mjs +2 -1
  62. package/validation/rules/UniqueDirectiveNamesRule.js +1 -1
  63. package/validation/rules/UniqueDirectiveNamesRule.mjs +1 -1
  64. package/validation/rules/UniqueTypeNamesRule.js +1 -1
  65. package/validation/rules/UniqueTypeNamesRule.mjs +1 -1
  66. package/validation/validate.js.flow +4 -4
  67. package/version.js +3 -3
  68. package/version.js.flow +3 -3
  69. package/version.mjs +3 -3
  70. package/jsutils/isCollection.js +0 -47
  71. package/jsutils/isCollection.js.flow +0 -38
  72. package/jsutils/isCollection.mjs +0 -40
@@ -17,6 +17,10 @@ export type IntrospectionOptions = {|
17
17
  // Whether to include `description` field on schema.
18
18
  // Default: false
19
19
  schemaDescription?: boolean,
20
+
21
+ // Whether target GraphQL server support deprecation of input values.
22
+ // Default: false
23
+ inputValueDeprecation?: boolean,
20
24
  |};
21
25
 
22
26
  export function getIntrospectionQuery(options?: IntrospectionOptions): string {
@@ -25,6 +29,7 @@ export function getIntrospectionQuery(options?: IntrospectionOptions): string {
25
29
  specifiedByUrl: false,
26
30
  directiveIsRepeatable: false,
27
31
  schemaDescription: false,
32
+ inputValueDeprecation: false,
28
33
  ...options,
29
34
  };
30
35
 
@@ -39,6 +44,10 @@ export function getIntrospectionQuery(options?: IntrospectionOptions): string {
39
44
  ? descriptions
40
45
  : '';
41
46
 
47
+ function inputDeprecation(str) {
48
+ return optionsWithDefault.inputValueDeprecation ? str : '';
49
+ }
50
+
42
51
  return `
43
52
  query IntrospectionQuery {
44
53
  __schema {
@@ -54,7 +63,7 @@ export function getIntrospectionQuery(options?: IntrospectionOptions): string {
54
63
  ${descriptions}
55
64
  ${directiveIsRepeatable}
56
65
  locations
57
- args {
66
+ args${inputDeprecation('(includeDeprecated: true)')} {
58
67
  ...InputValue
59
68
  }
60
69
  }
@@ -69,7 +78,7 @@ export function getIntrospectionQuery(options?: IntrospectionOptions): string {
69
78
  fields(includeDeprecated: true) {
70
79
  name
71
80
  ${descriptions}
72
- args {
81
+ args${inputDeprecation('(includeDeprecated: true)')} {
73
82
  ...InputValue
74
83
  }
75
84
  type {
@@ -78,7 +87,7 @@ export function getIntrospectionQuery(options?: IntrospectionOptions): string {
78
87
  isDeprecated
79
88
  deprecationReason
80
89
  }
81
- inputFields {
90
+ inputFields${inputDeprecation('(includeDeprecated: true)')} {
82
91
  ...InputValue
83
92
  }
84
93
  interfaces {
@@ -100,6 +109,8 @@ export function getIntrospectionQuery(options?: IntrospectionOptions): string {
100
109
  ${descriptions}
101
110
  type { ...TypeRef }
102
111
  defaultValue
112
+ ${inputDeprecation('isDeprecated')}
113
+ ${inputDeprecation('deprecationReason')}
103
114
  }
104
115
 
105
116
  fragment TypeRef on __Type {
@@ -281,6 +292,8 @@ export type IntrospectionInputValue = {|
281
292
  +description?: ?string,
282
293
  +type: IntrospectionInputTypeRef,
283
294
  +defaultValue: ?string,
295
+ +isDeprecated?: boolean,
296
+ +deprecationReason?: ?string,
284
297
  |};
285
298
 
286
299
  export type IntrospectionEnumValue = {|
@@ -9,12 +9,18 @@ export function getIntrospectionQuery(options) {
9
9
  descriptions: true,
10
10
  specifiedByUrl: false,
11
11
  directiveIsRepeatable: false,
12
- schemaDescription: false
12
+ schemaDescription: false,
13
+ inputValueDeprecation: false
13
14
  }, options);
14
15
 
15
16
  var descriptions = optionsWithDefault.descriptions ? 'description' : '';
16
17
  var specifiedByUrl = optionsWithDefault.specifiedByUrl ? 'specifiedByUrl' : '';
17
18
  var directiveIsRepeatable = optionsWithDefault.directiveIsRepeatable ? 'isRepeatable' : '';
18
19
  var schemaDescription = optionsWithDefault.schemaDescription ? descriptions : '';
19
- return "\n query IntrospectionQuery {\n __schema {\n ".concat(schemaDescription, "\n queryType { name }\n mutationType { name }\n subscriptionType { name }\n types {\n ...FullType\n }\n directives {\n name\n ").concat(descriptions, "\n ").concat(directiveIsRepeatable, "\n locations\n args {\n ...InputValue\n }\n }\n }\n }\n\n fragment FullType on __Type {\n kind\n name\n ").concat(descriptions, "\n ").concat(specifiedByUrl, "\n fields(includeDeprecated: true) {\n name\n ").concat(descriptions, "\n args {\n ...InputValue\n }\n type {\n ...TypeRef\n }\n isDeprecated\n deprecationReason\n }\n inputFields {\n ...InputValue\n }\n interfaces {\n ...TypeRef\n }\n enumValues(includeDeprecated: true) {\n name\n ").concat(descriptions, "\n isDeprecated\n deprecationReason\n }\n possibleTypes {\n ...TypeRef\n }\n }\n\n fragment InputValue on __InputValue {\n name\n ").concat(descriptions, "\n type { ...TypeRef }\n defaultValue\n }\n\n fragment TypeRef on __Type {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n }\n }\n }\n }\n }\n }\n }\n }\n ");
20
+
21
+ function inputDeprecation(str) {
22
+ return optionsWithDefault.inputValueDeprecation ? str : '';
23
+ }
24
+
25
+ return "\n query IntrospectionQuery {\n __schema {\n ".concat(schemaDescription, "\n queryType { name }\n mutationType { name }\n subscriptionType { name }\n types {\n ...FullType\n }\n directives {\n name\n ").concat(descriptions, "\n ").concat(directiveIsRepeatable, "\n locations\n args").concat(inputDeprecation('(includeDeprecated: true)'), " {\n ...InputValue\n }\n }\n }\n }\n\n fragment FullType on __Type {\n kind\n name\n ").concat(descriptions, "\n ").concat(specifiedByUrl, "\n fields(includeDeprecated: true) {\n name\n ").concat(descriptions, "\n args").concat(inputDeprecation('(includeDeprecated: true)'), " {\n ...InputValue\n }\n type {\n ...TypeRef\n }\n isDeprecated\n deprecationReason\n }\n inputFields").concat(inputDeprecation('(includeDeprecated: true)'), " {\n ...InputValue\n }\n interfaces {\n ...TypeRef\n }\n enumValues(includeDeprecated: true) {\n name\n ").concat(descriptions, "\n isDeprecated\n deprecationReason\n }\n possibleTypes {\n ...TypeRef\n }\n }\n\n fragment InputValue on __InputValue {\n name\n ").concat(descriptions, "\n type { ...TypeRef }\n defaultValue\n ").concat(inputDeprecation('isDeprecated'), "\n ").concat(inputDeprecation('deprecationReason'), "\n }\n\n fragment TypeRef on __Type {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n }\n }\n }\n }\n }\n }\n }\n }\n ");
20
26
  }
@@ -32,8 +32,10 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
32
32
  */
33
33
  function introspectionFromSchema(schema, options) {
34
34
  var optionsWithDefaults = _objectSpread({
35
+ specifiedByUrl: true,
35
36
  directiveIsRepeatable: true,
36
- schemaDescription: true
37
+ schemaDescription: true,
38
+ inputValueDeprecation: true
37
39
  }, options);
38
40
 
39
41
  var document = (0, _parser.parse)((0, _getIntrospectionQuery.getIntrospectionQuery)(optionsWithDefaults));
@@ -27,8 +27,10 @@ export function introspectionFromSchema(
27
27
  options?: IntrospectionOptions,
28
28
  ): IntrospectionQuery {
29
29
  const optionsWithDefaults = {
30
+ specifiedByUrl: true,
30
31
  directiveIsRepeatable: true,
31
32
  schemaDescription: true,
33
+ inputValueDeprecation: true,
32
34
  ...options,
33
35
  };
34
36
 
@@ -20,8 +20,10 @@ import { getIntrospectionQuery } from "./getIntrospectionQuery.mjs";
20
20
 
21
21
  export function introspectionFromSchema(schema, options) {
22
22
  var optionsWithDefaults = _objectSpread({
23
+ specifiedByUrl: true,
23
24
  directiveIsRepeatable: true,
24
- schemaDescription: true
25
+ schemaDescription: true,
26
+ inputValueDeprecation: true
25
27
  }, options);
26
28
 
27
29
  var document = parse(getIntrospectionQuery(optionsWithDefaults));
@@ -13,6 +13,8 @@ var _invariant = _interopRequireDefault(require("../jsutils/invariant.js"));
13
13
 
14
14
  var _keyValMap = _interopRequireDefault(require("../jsutils/keyValMap.js"));
15
15
 
16
+ var _naturalCompare = _interopRequireDefault(require("../jsutils/naturalCompare.js"));
17
+
16
18
  var _schema = require("../type/schema.js");
17
19
 
18
20
  var _directives = require("../type/directives.js");
@@ -195,6 +197,6 @@ function sortBy(array, mapToKey) {
195
197
  return array.slice().sort(function (obj1, obj2) {
196
198
  var key1 = mapToKey(obj1);
197
199
  var key2 = mapToKey(obj2);
198
- return key1.localeCompare(key2);
200
+ return (0, _naturalCompare.default)(key1, key2);
199
201
  });
200
202
  }
@@ -5,6 +5,7 @@ import type { ObjMap } from '../jsutils/ObjMap';
5
5
  import inspect from '../jsutils/inspect';
6
6
  import invariant from '../jsutils/invariant';
7
7
  import keyValMap from '../jsutils/keyValMap';
8
+ import naturalCompare from '../jsutils/naturalCompare';
8
9
 
9
10
  import type {
10
11
  GraphQLType,
@@ -110,7 +111,7 @@ export function lexicographicSortSchema(schema: GraphQLSchema): GraphQLSchema {
110
111
  return sortByName(arr).map(replaceNamedType);
111
112
  }
112
113
 
113
- function sortNamedType<T: GraphQLNamedType>(type: T) {
114
+ function sortNamedType(type: GraphQLNamedType): GraphQLNamedType {
114
115
  if (isScalarType(type) || isIntrospectionType(type)) {
115
116
  return type;
116
117
  }
@@ -181,6 +182,6 @@ function sortBy<T>(
181
182
  return array.slice().sort((obj1, obj2) => {
182
183
  const key1 = mapToKey(obj1);
183
184
  const key2 = mapToKey(obj2);
184
- return key1.localeCompare(key2);
185
+ return naturalCompare(key1, key2);
185
186
  });
186
187
  }
@@ -8,6 +8,7 @@ import objectValues from "../polyfills/objectValues.mjs";
8
8
  import inspect from "../jsutils/inspect.mjs";
9
9
  import invariant from "../jsutils/invariant.mjs";
10
10
  import keyValMap from "../jsutils/keyValMap.mjs";
11
+ import naturalCompare from "../jsutils/naturalCompare.mjs";
11
12
  import { GraphQLSchema } from "../type/schema.mjs";
12
13
  import { GraphQLDirective } from "../type/directives.mjs";
13
14
  import { isIntrospectionType } from "../type/introspection.mjs";
@@ -179,6 +180,6 @@ function sortBy(array, mapToKey) {
179
180
  return array.slice().sort(function (obj1, obj2) {
180
181
  var key1 = mapToKey(obj1);
181
182
  var key2 = mapToKey(obj2);
182
- return key1.localeCompare(key2);
183
+ return naturalCompare(key1, key2);
183
184
  });
184
185
  }
@@ -17,72 +17,76 @@ var _visitor = require("../language/visitor.js");
17
17
  */
18
18
  function separateOperations(documentAST) {
19
19
  var operations = [];
20
- var depGraph = Object.create(null);
21
- var fromName; // Populate metadata and build a dependency graph.
22
-
23
- (0, _visitor.visit)(documentAST, {
24
- OperationDefinition: function OperationDefinition(node) {
25
- fromName = opName(node);
26
- operations.push(node);
27
- },
28
- FragmentDefinition: function FragmentDefinition(node) {
29
- fromName = node.name.value;
30
- },
31
- FragmentSpread: function FragmentSpread(node) {
32
- var toName = node.name.value;
33
- var dependents = depGraph[fromName];
20
+ var depGraph = Object.create(null); // Populate metadata and build a dependency graph.
34
21
 
35
- if (dependents === undefined) {
36
- dependents = depGraph[fromName] = Object.create(null);
37
- }
22
+ for (var _i2 = 0, _documentAST$definiti2 = documentAST.definitions; _i2 < _documentAST$definiti2.length; _i2++) {
23
+ var definitionNode = _documentAST$definiti2[_i2];
38
24
 
39
- dependents[toName] = true;
25
+ switch (definitionNode.kind) {
26
+ case _kinds.Kind.OPERATION_DEFINITION:
27
+ operations.push(definitionNode);
28
+ break;
29
+
30
+ case _kinds.Kind.FRAGMENT_DEFINITION:
31
+ depGraph[definitionNode.name.value] = collectDependencies(definitionNode.selectionSet);
32
+ break;
40
33
  }
41
- }); // For each operation, produce a new synthesized AST which includes only what
34
+ } // For each operation, produce a new synthesized AST which includes only what
42
35
  // is necessary for completing that operation.
43
36
 
37
+
44
38
  var separatedDocumentASTs = Object.create(null);
45
39
 
46
- var _loop = function _loop(_i2) {
47
- var operation = operations[_i2];
48
- var operationName = opName(operation);
49
- var dependencies = Object.create(null);
50
- collectTransitiveDependencies(dependencies, depGraph, operationName); // The list of definition nodes to be included for this operation, sorted
40
+ var _loop = function _loop(_i4) {
41
+ var operation = operations[_i4];
42
+ var dependencies = new Set();
43
+
44
+ for (var _i6 = 0, _collectDependencies2 = collectDependencies(operation.selectionSet); _i6 < _collectDependencies2.length; _i6++) {
45
+ var fragmentName = _collectDependencies2[_i6];
46
+ collectTransitiveDependencies(dependencies, depGraph, fragmentName);
47
+ } // Provides the empty string for anonymous operations.
48
+
49
+
50
+ var operationName = operation.name ? operation.name.value : ''; // The list of definition nodes to be included for this operation, sorted
51
51
  // to retain the same order as the original document.
52
52
 
53
53
  separatedDocumentASTs[operationName] = {
54
54
  kind: _kinds.Kind.DOCUMENT,
55
55
  definitions: documentAST.definitions.filter(function (node) {
56
- return node === operation || node.kind === _kinds.Kind.FRAGMENT_DEFINITION && dependencies[node.name.value];
56
+ return node === operation || node.kind === _kinds.Kind.FRAGMENT_DEFINITION && dependencies.has(node.name.value);
57
57
  })
58
58
  };
59
59
  };
60
60
 
61
- for (var _i2 = 0; _i2 < operations.length; _i2++) {
62
- _loop(_i2);
61
+ for (var _i4 = 0; _i4 < operations.length; _i4++) {
62
+ _loop(_i4);
63
63
  }
64
64
 
65
65
  return separatedDocumentASTs;
66
66
  }
67
67
 
68
- // Provides the empty string for anonymous operations.
69
- function opName(operation) {
70
- return operation.name ? operation.name.value : '';
71
- } // From a dependency graph, collects a list of transitive dependencies by
68
+ // From a dependency graph, collects a list of transitive dependencies by
72
69
  // recursing through a dependency graph.
73
-
74
-
75
70
  function collectTransitiveDependencies(collected, depGraph, fromName) {
76
- var immediateDeps = depGraph[fromName];
71
+ if (!collected.has(fromName)) {
72
+ collected.add(fromName);
73
+ var immediateDeps = depGraph[fromName];
77
74
 
78
- if (immediateDeps) {
79
- for (var _i4 = 0, _Object$keys2 = Object.keys(immediateDeps); _i4 < _Object$keys2.length; _i4++) {
80
- var toName = _Object$keys2[_i4];
81
-
82
- if (!collected[toName]) {
83
- collected[toName] = true;
75
+ if (immediateDeps !== undefined) {
76
+ for (var _i8 = 0; _i8 < immediateDeps.length; _i8++) {
77
+ var toName = immediateDeps[_i8];
84
78
  collectTransitiveDependencies(collected, depGraph, toName);
85
79
  }
86
80
  }
87
81
  }
88
82
  }
83
+
84
+ function collectDependencies(selectionSet) {
85
+ var dependencies = [];
86
+ (0, _visitor.visit)(selectionSet, {
87
+ FragmentSpread: function FragmentSpread(node) {
88
+ dependencies.push(node.name.value);
89
+ }
90
+ });
91
+ return dependencies;
92
+ }
@@ -1,7 +1,11 @@
1
1
  // @flow strict
2
2
  import type { ObjMap } from '../jsutils/ObjMap';
3
3
 
4
- import type { DocumentNode, OperationDefinitionNode } from '../language/ast';
4
+ import type {
5
+ DocumentNode,
6
+ OperationDefinitionNode,
7
+ SelectionSetNode,
8
+ } from '../language/ast';
5
9
  import { Kind } from '../language/kinds';
6
10
  import { visit } from '../language/visitor';
7
11
 
@@ -14,36 +18,35 @@ import { visit } from '../language/visitor';
14
18
  export function separateOperations(
15
19
  documentAST: DocumentNode,
16
20
  ): ObjMap<DocumentNode> {
17
- const operations = [];
21
+ const operations: Array<OperationDefinitionNode> = [];
18
22
  const depGraph: DepGraph = Object.create(null);
19
- let fromName;
20
23
 
21
24
  // Populate metadata and build a dependency graph.
22
- visit(documentAST, {
23
- OperationDefinition(node) {
24
- fromName = opName(node);
25
- operations.push(node);
26
- },
27
- FragmentDefinition(node) {
28
- fromName = node.name.value;
29
- },
30
- FragmentSpread(node) {
31
- const toName = node.name.value;
32
- let dependents = depGraph[fromName];
33
- if (dependents === undefined) {
34
- dependents = depGraph[fromName] = Object.create(null);
35
- }
36
- dependents[toName] = true;
37
- },
38
- });
25
+ for (const definitionNode of documentAST.definitions) {
26
+ switch (definitionNode.kind) {
27
+ case Kind.OPERATION_DEFINITION:
28
+ operations.push(definitionNode);
29
+ break;
30
+ case Kind.FRAGMENT_DEFINITION:
31
+ depGraph[definitionNode.name.value] = collectDependencies(
32
+ definitionNode.selectionSet,
33
+ );
34
+ break;
35
+ }
36
+ }
39
37
 
40
38
  // For each operation, produce a new synthesized AST which includes only what
41
39
  // is necessary for completing that operation.
42
40
  const separatedDocumentASTs = Object.create(null);
43
41
  for (const operation of operations) {
44
- const operationName = opName(operation);
45
- const dependencies = Object.create(null);
46
- collectTransitiveDependencies(dependencies, depGraph, operationName);
42
+ const dependencies = new Set();
43
+
44
+ for (const fragmentName of collectDependencies(operation.selectionSet)) {
45
+ collectTransitiveDependencies(dependencies, depGraph, fragmentName);
46
+ }
47
+
48
+ // Provides the empty string for anonymous operations.
49
+ const operationName = operation.name ? operation.name.value : '';
47
50
 
48
51
  // The list of definition nodes to be included for this operation, sorted
49
52
  // to retain the same order as the original document.
@@ -53,7 +56,7 @@ export function separateOperations(
53
56
  (node) =>
54
57
  node === operation ||
55
58
  (node.kind === Kind.FRAGMENT_DEFINITION &&
56
- dependencies[node.name.value]),
59
+ dependencies.has(node.name.value)),
57
60
  ),
58
61
  };
59
62
  }
@@ -61,27 +64,34 @@ export function separateOperations(
61
64
  return separatedDocumentASTs;
62
65
  }
63
66
 
64
- type DepGraph = ObjMap<ObjMap<boolean>>;
65
-
66
- // Provides the empty string for anonymous operations.
67
- function opName(operation: OperationDefinitionNode): string {
68
- return operation.name ? operation.name.value : '';
69
- }
67
+ type DepGraph = ObjMap<Array<string>>;
70
68
 
71
69
  // From a dependency graph, collects a list of transitive dependencies by
72
70
  // recursing through a dependency graph.
73
71
  function collectTransitiveDependencies(
74
- collected: ObjMap<boolean>,
72
+ collected: Set<string>,
75
73
  depGraph: DepGraph,
76
74
  fromName: string,
77
75
  ): void {
78
- const immediateDeps = depGraph[fromName];
79
- if (immediateDeps) {
80
- for (const toName of Object.keys(immediateDeps)) {
81
- if (!collected[toName]) {
82
- collected[toName] = true;
76
+ if (!collected.has(fromName)) {
77
+ collected.add(fromName);
78
+
79
+ const immediateDeps = depGraph[fromName];
80
+ if (immediateDeps !== undefined) {
81
+ for (const toName of immediateDeps) {
83
82
  collectTransitiveDependencies(collected, depGraph, toName);
84
83
  }
85
84
  }
86
85
  }
87
86
  }
87
+
88
+ function collectDependencies(selectionSet: SelectionSetNode): Array<string> {
89
+ const dependencies = [];
90
+
91
+ visit(selectionSet, {
92
+ FragmentSpread(node) {
93
+ dependencies.push(node.name.value);
94
+ },
95
+ });
96
+ return dependencies;
97
+ }
@@ -9,72 +9,76 @@ import { visit } from "../language/visitor.mjs";
9
9
 
10
10
  export function separateOperations(documentAST) {
11
11
  var operations = [];
12
- var depGraph = Object.create(null);
13
- var fromName; // Populate metadata and build a dependency graph.
14
-
15
- visit(documentAST, {
16
- OperationDefinition: function OperationDefinition(node) {
17
- fromName = opName(node);
18
- operations.push(node);
19
- },
20
- FragmentDefinition: function FragmentDefinition(node) {
21
- fromName = node.name.value;
22
- },
23
- FragmentSpread: function FragmentSpread(node) {
24
- var toName = node.name.value;
25
- var dependents = depGraph[fromName];
12
+ var depGraph = Object.create(null); // Populate metadata and build a dependency graph.
26
13
 
27
- if (dependents === undefined) {
28
- dependents = depGraph[fromName] = Object.create(null);
29
- }
14
+ for (var _i2 = 0, _documentAST$definiti2 = documentAST.definitions; _i2 < _documentAST$definiti2.length; _i2++) {
15
+ var definitionNode = _documentAST$definiti2[_i2];
30
16
 
31
- dependents[toName] = true;
17
+ switch (definitionNode.kind) {
18
+ case Kind.OPERATION_DEFINITION:
19
+ operations.push(definitionNode);
20
+ break;
21
+
22
+ case Kind.FRAGMENT_DEFINITION:
23
+ depGraph[definitionNode.name.value] = collectDependencies(definitionNode.selectionSet);
24
+ break;
32
25
  }
33
- }); // For each operation, produce a new synthesized AST which includes only what
26
+ } // For each operation, produce a new synthesized AST which includes only what
34
27
  // is necessary for completing that operation.
35
28
 
29
+
36
30
  var separatedDocumentASTs = Object.create(null);
37
31
 
38
- var _loop = function _loop(_i2) {
39
- var operation = operations[_i2];
40
- var operationName = opName(operation);
41
- var dependencies = Object.create(null);
42
- collectTransitiveDependencies(dependencies, depGraph, operationName); // The list of definition nodes to be included for this operation, sorted
32
+ var _loop = function _loop(_i4) {
33
+ var operation = operations[_i4];
34
+ var dependencies = new Set();
35
+
36
+ for (var _i6 = 0, _collectDependencies2 = collectDependencies(operation.selectionSet); _i6 < _collectDependencies2.length; _i6++) {
37
+ var fragmentName = _collectDependencies2[_i6];
38
+ collectTransitiveDependencies(dependencies, depGraph, fragmentName);
39
+ } // Provides the empty string for anonymous operations.
40
+
41
+
42
+ var operationName = operation.name ? operation.name.value : ''; // The list of definition nodes to be included for this operation, sorted
43
43
  // to retain the same order as the original document.
44
44
 
45
45
  separatedDocumentASTs[operationName] = {
46
46
  kind: Kind.DOCUMENT,
47
47
  definitions: documentAST.definitions.filter(function (node) {
48
- return node === operation || node.kind === Kind.FRAGMENT_DEFINITION && dependencies[node.name.value];
48
+ return node === operation || node.kind === Kind.FRAGMENT_DEFINITION && dependencies.has(node.name.value);
49
49
  })
50
50
  };
51
51
  };
52
52
 
53
- for (var _i2 = 0; _i2 < operations.length; _i2++) {
54
- _loop(_i2);
53
+ for (var _i4 = 0; _i4 < operations.length; _i4++) {
54
+ _loop(_i4);
55
55
  }
56
56
 
57
57
  return separatedDocumentASTs;
58
58
  }
59
59
 
60
- // Provides the empty string for anonymous operations.
61
- function opName(operation) {
62
- return operation.name ? operation.name.value : '';
63
- } // From a dependency graph, collects a list of transitive dependencies by
60
+ // From a dependency graph, collects a list of transitive dependencies by
64
61
  // recursing through a dependency graph.
65
-
66
-
67
62
  function collectTransitiveDependencies(collected, depGraph, fromName) {
68
- var immediateDeps = depGraph[fromName];
63
+ if (!collected.has(fromName)) {
64
+ collected.add(fromName);
65
+ var immediateDeps = depGraph[fromName];
69
66
 
70
- if (immediateDeps) {
71
- for (var _i4 = 0, _Object$keys2 = Object.keys(immediateDeps); _i4 < _Object$keys2.length; _i4++) {
72
- var toName = _Object$keys2[_i4];
73
-
74
- if (!collected[toName]) {
75
- collected[toName] = true;
67
+ if (immediateDeps !== undefined) {
68
+ for (var _i8 = 0; _i8 < immediateDeps.length; _i8++) {
69
+ var toName = immediateDeps[_i8];
76
70
  collectTransitiveDependencies(collected, depGraph, toName);
77
71
  }
78
72
  }
79
73
  }
80
74
  }
75
+
76
+ function collectDependencies(selectionSet) {
77
+ var dependencies = [];
78
+ visit(selectionSet, {
79
+ FragmentSpread: function FragmentSpread(node) {
80
+ dependencies.push(node.name.value);
81
+ }
82
+ });
83
+ return dependencies;
84
+ }
@@ -51,7 +51,7 @@ export class ASTValidationContext {
51
51
  $ReadOnlyArray<FragmentDefinitionNode>,
52
52
  >;
53
53
 
54
- constructor(ast: DocumentNode, onError: (err: GraphQLError) => void): void {
54
+ constructor(ast: DocumentNode, onError: (err: GraphQLError) => void) {
55
55
  this._ast = ast;
56
56
  this._fragments = undefined;
57
57
  this._fragmentSpreads = new Map();
@@ -142,7 +142,7 @@ export class SDLValidationContext extends ASTValidationContext {
142
142
  ast: DocumentNode,
143
143
  schema: ?GraphQLSchema,
144
144
  onError: (err: GraphQLError) => void,
145
- ): void {
145
+ ) {
146
146
  super(ast, onError);
147
147
  this._schema = schema;
148
148
  }
@@ -168,7 +168,7 @@ export class ValidationContext extends ASTValidationContext {
168
168
  ast: DocumentNode,
169
169
  typeInfo: TypeInfo,
170
170
  onError: (err: GraphQLError) => void,
171
- ): void {
171
+ ) {
172
172
  super(ast, onError);
173
173
  this._schema = schema;
174
174
  this._typeInfo = typeInfo;
@@ -11,6 +11,8 @@ var _didYouMean = _interopRequireDefault(require("../../jsutils/didYouMean.js"))
11
11
 
12
12
  var _suggestionList = _interopRequireDefault(require("../../jsutils/suggestionList.js"));
13
13
 
14
+ var _naturalCompare = _interopRequireDefault(require("../../jsutils/naturalCompare.js"));
15
+
14
16
  var _GraphQLError = require("../../error/GraphQLError.js");
15
17
 
16
18
  var _definition = require("../../type/definition.js");
@@ -108,7 +110,7 @@ function getSuggestedTypeNames(schema, type, fieldName) {
108
110
  return 1;
109
111
  }
110
112
 
111
- return typeA.name.localeCompare(typeB.name);
113
+ return (0, _naturalCompare.default)(typeA.name, typeB.name);
112
114
  }).map(function (x) {
113
115
  return x.name;
114
116
  });
@@ -3,6 +3,7 @@ import arrayFrom from '../../polyfills/arrayFrom';
3
3
 
4
4
  import didYouMean from '../../jsutils/didYouMean';
5
5
  import suggestionList from '../../jsutils/suggestionList';
6
+ import naturalCompare from '../../jsutils/naturalCompare';
6
7
 
7
8
  import { GraphQLError } from '../../error/GraphQLError';
8
9
 
@@ -123,7 +124,7 @@ function getSuggestedTypeNames(
123
124
  return 1;
124
125
  }
125
126
 
126
- return typeA.name.localeCompare(typeB.name);
127
+ return naturalCompare(typeA.name, typeB.name);
127
128
  })
128
129
  .map((x) => x.name);
129
130
  }
@@ -1,6 +1,7 @@
1
1
  import arrayFrom from "../../polyfills/arrayFrom.mjs";
2
2
  import didYouMean from "../../jsutils/didYouMean.mjs";
3
3
  import suggestionList from "../../jsutils/suggestionList.mjs";
4
+ import naturalCompare from "../../jsutils/naturalCompare.mjs";
4
5
  import { GraphQLError } from "../../error/GraphQLError.mjs";
5
6
  import { isObjectType, isInterfaceType, isAbstractType } from "../../type/definition.mjs";
6
7
 
@@ -94,7 +95,7 @@ function getSuggestedTypeNames(schema, type, fieldName) {
94
95
  return 1;
95
96
  }
96
97
 
97
- return typeA.name.localeCompare(typeB.name);
98
+ return naturalCompare(typeA.name, typeB.name);
98
99
  }).map(function (x) {
99
100
  return x.name;
100
101
  });
@@ -19,7 +19,7 @@ function UniqueDirectiveNamesRule(context) {
19
19
  DirectiveDefinition: function DirectiveDefinition(node) {
20
20
  var directiveName = node.name.value;
21
21
 
22
- if (schema === null || schema === void 0 ? void 0 : schema.getDirective(directiveName)) {
22
+ if (schema !== null && schema !== void 0 && schema.getDirective(directiveName)) {
23
23
  context.reportError(new _GraphQLError.GraphQLError("Directive \"@".concat(directiveName, "\" already exists in the schema. It cannot be redefined."), node.name));
24
24
  return;
25
25
  }
@@ -12,7 +12,7 @@ export function UniqueDirectiveNamesRule(context) {
12
12
  DirectiveDefinition: function DirectiveDefinition(node) {
13
13
  var directiveName = node.name.value;
14
14
 
15
- if (schema === null || schema === void 0 ? void 0 : schema.getDirective(directiveName)) {
15
+ if (schema !== null && schema !== void 0 && schema.getDirective(directiveName)) {
16
16
  context.reportError(new GraphQLError("Directive \"@".concat(directiveName, "\" already exists in the schema. It cannot be redefined."), node.name));
17
17
  return;
18
18
  }