@luvio/graphql-parser 0.135.3 → 0.136.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.
@@ -116,11 +116,11 @@ function leftPad(len, str) {
116
116
 
117
117
  function _typeof$3(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof$3 = function _typeof(obj) { return typeof obj; }; } else { _typeof$3 = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof$3(obj); }
118
118
 
119
- function ownKeys$3(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; }
119
+ function ownKeys$1(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; }
120
120
 
121
- function _objectSpread$3(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$3(Object(source), true).forEach(function (key) { _defineProperty$4(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$3(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
121
+ function _objectSpread$1(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$1(Object(source), true).forEach(function (key) { _defineProperty$2(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$1(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
122
122
 
123
- function _defineProperty$4(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; }
123
+ function _defineProperty$2(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; }
124
124
 
125
125
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
126
126
 
@@ -240,7 +240,7 @@ var GraphQLError = /*#__PURE__*/function (_Error) {
240
240
  var originalExtensions = originalError === null || originalError === void 0 ? void 0 : originalError.extensions;
241
241
 
242
242
  if (extensions == null && isObjectLike(originalExtensions)) {
243
- _this.extensions = _objectSpread$3({}, originalExtensions);
243
+ _this.extensions = _objectSpread$1({}, originalExtensions);
244
244
  } else {
245
245
  _this.extensions = extensions !== null && extensions !== void 0 ? extensions : {};
246
246
  } // By being enumerable, JSON.stringify will include bellow properties in the resulting output.
@@ -4355,13 +4355,6 @@ function isLeafType(type) {
4355
4355
  * These types may describe the parent context of a selection set.
4356
4356
  */
4357
4357
 
4358
- function isCompositeType(type) {
4359
- return isObjectType(type) || isInterfaceType(type) || isUnionType(type);
4360
- }
4361
- /**
4362
- * These types may describe the parent context of a selection set.
4363
- */
4364
-
4365
4358
  function isAbstractType(type) {
4366
4359
  return isInterfaceType(type) || isUnionType(type);
4367
4360
  }
@@ -4494,14 +4487,6 @@ function assertNullableType(type) {
4494
4487
 
4495
4488
  return type;
4496
4489
  }
4497
- /* eslint-disable no-redeclare */
4498
-
4499
- function getNullableType(type) {
4500
- /* eslint-enable no-redeclare */
4501
- if (type) {
4502
- return isNonNullType(type) ? type.ofType : type;
4503
- }
4504
- }
4505
4490
  /**
4506
4491
  * These named types do not include modifiers like List or NonNull.
4507
4492
  */
@@ -5331,43 +5316,6 @@ function isTypeSubTypeOf(schema, maybeSubType, superType) {
5331
5316
 
5332
5317
  return isAbstractType(superType) && (isInterfaceType(maybeSubType) || isObjectType(maybeSubType)) && schema.isSubType(superType, maybeSubType);
5333
5318
  }
5334
- /**
5335
- * Provided two composite types, determine if they "overlap". Two composite
5336
- * types overlap when the Sets of possible concrete types for each intersect.
5337
- *
5338
- * This is often used to determine if a fragment of a given type could possibly
5339
- * be visited in a context of another type.
5340
- *
5341
- * This function is commutative.
5342
- */
5343
-
5344
- function doTypesOverlap(schema, typeA, typeB) {
5345
- // Equivalent types overlap
5346
- if (typeA === typeB) {
5347
- return true;
5348
- }
5349
-
5350
- if (isAbstractType(typeA)) {
5351
- if (isAbstractType(typeB)) {
5352
- // If both types are abstract, then determine if there is any intersection
5353
- // between possible concrete types of each.
5354
- return schema.getPossibleTypes(typeA).some(function (type) {
5355
- return schema.isSubType(typeB, type);
5356
- });
5357
- } // Determine if the latter type is a possible concrete type of the former.
5358
-
5359
-
5360
- return schema.isSubType(typeA, typeB);
5361
- }
5362
-
5363
- if (isAbstractType(typeB)) {
5364
- // Determine if the former type is a possible concrete type of the latter.
5365
- return schema.isSubType(typeB, typeA);
5366
- } // Otherwise the types do not overlap.
5367
-
5368
-
5369
- return false;
5370
- }
5371
5319
 
5372
5320
  /* eslint-disable no-redeclare */
5373
5321
  // $FlowFixMe[name-already-bound]
@@ -7540,9 +7488,6 @@ function typeFromAST(schema, typeNode) {
7540
7488
  invariant(0, 'Unexpected type node: ' + inspect(typeNode));
7541
7489
  }
7542
7490
 
7543
- function isExecutableDefinitionNode(node) {
7544
- return node.kind === Kind.OPERATION_DEFINITION || node.kind === Kind.FRAGMENT_DEFINITION;
7545
- }
7546
7491
  function isTypeSystemDefinitionNode(node) {
7547
7492
  return node.kind === Kind.SCHEMA_DEFINITION || isTypeDefinitionNode(node) || node.kind === Kind.DIRECTIVE_DEFINITION;
7548
7493
  }
@@ -7556,95 +7501,6 @@ function isTypeExtensionNode(node) {
7556
7501
  return node.kind === Kind.SCALAR_TYPE_EXTENSION || node.kind === Kind.OBJECT_TYPE_EXTENSION || node.kind === Kind.INTERFACE_TYPE_EXTENSION || node.kind === Kind.UNION_TYPE_EXTENSION || node.kind === Kind.ENUM_TYPE_EXTENSION || node.kind === Kind.INPUT_OBJECT_TYPE_EXTENSION;
7557
7502
  }
7558
7503
 
7559
- /**
7560
- * Executable definitions
7561
- *
7562
- * A GraphQL document is only valid for execution if all definitions are either
7563
- * operation or fragment definitions.
7564
- */
7565
- function ExecutableDefinitionsRule(context) {
7566
- return {
7567
- Document: function Document(node) {
7568
- for (var _i2 = 0, _node$definitions2 = node.definitions; _i2 < _node$definitions2.length; _i2++) {
7569
- var definition = _node$definitions2[_i2];
7570
-
7571
- if (!isExecutableDefinitionNode(definition)) {
7572
- var defName = definition.kind === Kind.SCHEMA_DEFINITION || definition.kind === Kind.SCHEMA_EXTENSION ? 'schema' : '"' + definition.name.value + '"';
7573
- context.reportError(new GraphQLError("The ".concat(defName, " definition is not executable."), definition));
7574
- }
7575
- }
7576
-
7577
- return false;
7578
- }
7579
- };
7580
- }
7581
-
7582
- /**
7583
- * Unique operation names
7584
- *
7585
- * A GraphQL document is only valid if all defined operations have unique names.
7586
- */
7587
- function UniqueOperationNamesRule(context) {
7588
- var knownOperationNames = Object.create(null);
7589
- return {
7590
- OperationDefinition: function OperationDefinition(node) {
7591
- var operationName = node.name;
7592
-
7593
- if (operationName) {
7594
- if (knownOperationNames[operationName.value]) {
7595
- context.reportError(new GraphQLError("There can be only one operation named \"".concat(operationName.value, "\"."), [knownOperationNames[operationName.value], operationName]));
7596
- } else {
7597
- knownOperationNames[operationName.value] = operationName;
7598
- }
7599
- }
7600
-
7601
- return false;
7602
- },
7603
- FragmentDefinition: function FragmentDefinition() {
7604
- return false;
7605
- }
7606
- };
7607
- }
7608
-
7609
- /**
7610
- * Lone anonymous operation
7611
- *
7612
- * A GraphQL document is only valid if when it contains an anonymous operation
7613
- * (the query short-hand) that it contains only that one operation definition.
7614
- */
7615
- function LoneAnonymousOperationRule(context) {
7616
- var operationCount = 0;
7617
- return {
7618
- Document: function Document(node) {
7619
- operationCount = node.definitions.filter(function (definition) {
7620
- return definition.kind === Kind.OPERATION_DEFINITION;
7621
- }).length;
7622
- },
7623
- OperationDefinition: function OperationDefinition(node) {
7624
- if (!node.name && operationCount > 1) {
7625
- context.reportError(new GraphQLError('This anonymous operation must be the only defined operation.', node));
7626
- }
7627
- }
7628
- };
7629
- }
7630
-
7631
- /**
7632
- * Subscriptions must only include one field.
7633
- *
7634
- * A GraphQL subscription is valid only if it contains a single root field.
7635
- */
7636
- function SingleFieldSubscriptionsRule(context) {
7637
- return {
7638
- OperationDefinition: function OperationDefinition(node) {
7639
- if (node.operation === 'subscription') {
7640
- if (node.selectionSet.selections.length !== 1) {
7641
- context.reportError(new GraphQLError(node.name ? "Subscription \"".concat(node.name.value, "\" must select only one top level field.") : 'Anonymous Subscription must select only one top level field.', node.selectionSet.selections.slice(1)));
7642
- }
7643
- }
7644
- }
7645
- };
7646
- }
7647
-
7648
7504
  /**
7649
7505
  * Known type names
7650
7506
  *
@@ -7698,645 +7554,161 @@ function isSDLNode(value) {
7698
7554
  }
7699
7555
 
7700
7556
  /**
7701
- * Fragments on composite type
7557
+ * Known directives
7702
7558
  *
7703
- * Fragments use a type condition to determine if they apply, since fragments
7704
- * can only be spread into a composite type (object, interface, or union), the
7705
- * type condition must also be a composite type.
7559
+ * A GraphQL document is only valid if all `@directives` are known by the
7560
+ * schema and legally positioned.
7706
7561
  */
7707
- function FragmentsOnCompositeTypesRule(context) {
7708
- return {
7709
- InlineFragment: function InlineFragment(node) {
7710
- var typeCondition = node.typeCondition;
7711
-
7712
- if (typeCondition) {
7713
- var type = typeFromAST(context.getSchema(), typeCondition);
7562
+ function KnownDirectivesRule(context) {
7563
+ var locationsMap = Object.create(null);
7564
+ var schema = context.getSchema();
7565
+ var definedDirectives = schema ? schema.getDirectives() : specifiedDirectives;
7714
7566
 
7715
- if (type && !isCompositeType(type)) {
7716
- var typeStr = print(typeCondition);
7717
- context.reportError(new GraphQLError("Fragment cannot condition on non composite type \"".concat(typeStr, "\"."), typeCondition));
7718
- }
7719
- }
7720
- },
7721
- FragmentDefinition: function FragmentDefinition(node) {
7722
- var type = typeFromAST(context.getSchema(), node.typeCondition);
7567
+ for (var _i2 = 0; _i2 < definedDirectives.length; _i2++) {
7568
+ var directive = definedDirectives[_i2];
7569
+ locationsMap[directive.name] = directive.locations;
7570
+ }
7723
7571
 
7724
- if (type && !isCompositeType(type)) {
7725
- var typeStr = print(node.typeCondition);
7726
- context.reportError(new GraphQLError("Fragment \"".concat(node.name.value, "\" cannot condition on non composite type \"").concat(typeStr, "\"."), node.typeCondition));
7727
- }
7728
- }
7729
- };
7730
- }
7572
+ var astDefinitions = context.getDocument().definitions;
7731
7573
 
7732
- /**
7733
- * Variables are input types
7734
- *
7735
- * A GraphQL operation is only valid if all the variables it defines are of
7736
- * input types (scalar, enum, or input object).
7737
- */
7738
- function VariablesAreInputTypesRule(context) {
7739
- return {
7740
- VariableDefinition: function VariableDefinition(node) {
7741
- var type = typeFromAST(context.getSchema(), node.type);
7574
+ for (var _i4 = 0; _i4 < astDefinitions.length; _i4++) {
7575
+ var def = astDefinitions[_i4];
7742
7576
 
7743
- if (type && !isInputType(type)) {
7744
- var variableName = node.variable.name.value;
7745
- var typeName = print(node.type);
7746
- context.reportError(new GraphQLError("Variable \"$".concat(variableName, "\" cannot be non-input type \"").concat(typeName, "\"."), node.type));
7747
- }
7577
+ if (def.kind === Kind.DIRECTIVE_DEFINITION) {
7578
+ locationsMap[def.name.value] = def.locations.map(function (name) {
7579
+ return name.value;
7580
+ });
7748
7581
  }
7749
- };
7750
- }
7582
+ }
7751
7583
 
7752
- /**
7753
- * Scalar leafs
7754
- *
7755
- * A GraphQL document is valid only if all leaf fields (fields without
7756
- * sub selections) are of scalar or enum types.
7757
- */
7758
- function ScalarLeafsRule(context) {
7759
7584
  return {
7760
- Field: function Field(node) {
7761
- var type = context.getType();
7762
- var selectionSet = node.selectionSet;
7763
-
7764
- if (type) {
7765
- if (isLeafType(getNamedType(type))) {
7766
- if (selectionSet) {
7767
- var fieldName = node.name.value;
7768
- var typeStr = inspect(type);
7769
- context.reportError(new GraphQLError("Field \"".concat(fieldName, "\" must not have a selection since type \"").concat(typeStr, "\" has no subfields."), selectionSet));
7770
- }
7771
- } else if (!selectionSet) {
7772
- var _fieldName = node.name.value;
7773
-
7774
- var _typeStr = inspect(type);
7585
+ Directive: function Directive(node, _key, _parent, _path, ancestors) {
7586
+ var name = node.name.value;
7587
+ var locations = locationsMap[name];
7775
7588
 
7776
- context.reportError(new GraphQLError("Field \"".concat(_fieldName, "\" of type \"").concat(_typeStr, "\" must have a selection of subfields. Did you mean \"").concat(_fieldName, " { ... }\"?"), node));
7777
- }
7589
+ if (!locations) {
7590
+ context.reportError(new GraphQLError("Unknown directive \"@".concat(name, "\"."), node));
7591
+ return;
7778
7592
  }
7779
- }
7780
- };
7781
- }
7782
-
7783
- /**
7784
- * Fields on correct type
7785
- *
7786
- * A GraphQL document is only valid if all fields selected are defined by the
7787
- * parent type, or are an allowed meta field such as __typename.
7788
- */
7789
- function FieldsOnCorrectTypeRule(context) {
7790
- return {
7791
- Field: function Field(node) {
7792
- var type = context.getParentType();
7793
-
7794
- if (type) {
7795
- var fieldDef = context.getFieldDef();
7796
-
7797
- if (!fieldDef) {
7798
- // This field doesn't exist, lets look for suggestions.
7799
- var schema = context.getSchema();
7800
- var fieldName = node.name.value; // First determine if there are any suggested types to condition on.
7801
-
7802
- var suggestion = didYouMean('to use an inline fragment on', getSuggestedTypeNames(schema, type, fieldName)); // If there are no suggested types, then perhaps this was a typo?
7803
-
7804
- if (suggestion === '') {
7805
- suggestion = didYouMean(getSuggestedFieldNames(type, fieldName));
7806
- } // Report an error, including helpful suggestions.
7807
7593
 
7594
+ var candidateLocation = getDirectiveLocationForASTPath(ancestors);
7808
7595
 
7809
- context.reportError(new GraphQLError("Cannot query field \"".concat(fieldName, "\" on type \"").concat(type.name, "\".") + suggestion, node));
7810
- }
7596
+ if (candidateLocation && locations.indexOf(candidateLocation) === -1) {
7597
+ context.reportError(new GraphQLError("Directive \"@".concat(name, "\" may not be used on ").concat(candidateLocation, "."), node));
7811
7598
  }
7812
7599
  }
7813
7600
  };
7814
7601
  }
7815
- /**
7816
- * Go through all of the implementations of type, as well as the interfaces that
7817
- * they implement. If any of those types include the provided field, suggest them,
7818
- * sorted by how often the type is referenced.
7819
- */
7820
7602
 
7821
- function getSuggestedTypeNames(schema, type, fieldName) {
7822
- if (!isAbstractType(type)) {
7823
- // Must be an Object type, which does not have possible fields.
7824
- return [];
7825
- }
7603
+ function getDirectiveLocationForASTPath(ancestors) {
7604
+ var appliedTo = ancestors[ancestors.length - 1];
7605
+ !Array.isArray(appliedTo) || invariant(0);
7826
7606
 
7827
- var suggestedTypes = new Set();
7828
- var usageCount = Object.create(null);
7607
+ switch (appliedTo.kind) {
7608
+ case Kind.OPERATION_DEFINITION:
7609
+ return getDirectiveLocationForOperation(appliedTo.operation);
7829
7610
 
7830
- for (var _i2 = 0, _schema$getPossibleTy2 = schema.getPossibleTypes(type); _i2 < _schema$getPossibleTy2.length; _i2++) {
7831
- var possibleType = _schema$getPossibleTy2[_i2];
7611
+ case Kind.FIELD:
7612
+ return DirectiveLocation.FIELD;
7832
7613
 
7833
- if (!possibleType.getFields()[fieldName]) {
7834
- continue;
7835
- } // This object type defines this field.
7614
+ case Kind.FRAGMENT_SPREAD:
7615
+ return DirectiveLocation.FRAGMENT_SPREAD;
7836
7616
 
7617
+ case Kind.INLINE_FRAGMENT:
7618
+ return DirectiveLocation.INLINE_FRAGMENT;
7837
7619
 
7838
- suggestedTypes.add(possibleType);
7839
- usageCount[possibleType.name] = 1;
7620
+ case Kind.FRAGMENT_DEFINITION:
7621
+ return DirectiveLocation.FRAGMENT_DEFINITION;
7840
7622
 
7841
- for (var _i4 = 0, _possibleType$getInte2 = possibleType.getInterfaces(); _i4 < _possibleType$getInte2.length; _i4++) {
7842
- var _usageCount$possibleI;
7623
+ case Kind.VARIABLE_DEFINITION:
7624
+ return DirectiveLocation.VARIABLE_DEFINITION;
7843
7625
 
7844
- var possibleInterface = _possibleType$getInte2[_i4];
7626
+ case Kind.SCHEMA_DEFINITION:
7627
+ case Kind.SCHEMA_EXTENSION:
7628
+ return DirectiveLocation.SCHEMA;
7845
7629
 
7846
- if (!possibleInterface.getFields()[fieldName]) {
7847
- continue;
7848
- } // This interface type defines this field.
7630
+ case Kind.SCALAR_TYPE_DEFINITION:
7631
+ case Kind.SCALAR_TYPE_EXTENSION:
7632
+ return DirectiveLocation.SCALAR;
7849
7633
 
7634
+ case Kind.OBJECT_TYPE_DEFINITION:
7635
+ case Kind.OBJECT_TYPE_EXTENSION:
7636
+ return DirectiveLocation.OBJECT;
7850
7637
 
7851
- suggestedTypes.add(possibleInterface);
7852
- usageCount[possibleInterface.name] = ((_usageCount$possibleI = usageCount[possibleInterface.name]) !== null && _usageCount$possibleI !== void 0 ? _usageCount$possibleI : 0) + 1;
7853
- }
7854
- }
7638
+ case Kind.FIELD_DEFINITION:
7639
+ return DirectiveLocation.FIELD_DEFINITION;
7855
7640
 
7856
- return arrayFrom$1(suggestedTypes).sort(function (typeA, typeB) {
7857
- // Suggest both interface and object types based on how common they are.
7858
- var usageCountDiff = usageCount[typeB.name] - usageCount[typeA.name];
7641
+ case Kind.INTERFACE_TYPE_DEFINITION:
7642
+ case Kind.INTERFACE_TYPE_EXTENSION:
7643
+ return DirectiveLocation.INTERFACE;
7859
7644
 
7860
- if (usageCountDiff !== 0) {
7861
- return usageCountDiff;
7862
- } // Suggest super types first followed by subtypes
7645
+ case Kind.UNION_TYPE_DEFINITION:
7646
+ case Kind.UNION_TYPE_EXTENSION:
7647
+ return DirectiveLocation.UNION;
7863
7648
 
7649
+ case Kind.ENUM_TYPE_DEFINITION:
7650
+ case Kind.ENUM_TYPE_EXTENSION:
7651
+ return DirectiveLocation.ENUM;
7864
7652
 
7865
- if (isInterfaceType(typeA) && schema.isSubType(typeA, typeB)) {
7866
- return -1;
7867
- }
7653
+ case Kind.ENUM_VALUE_DEFINITION:
7654
+ return DirectiveLocation.ENUM_VALUE;
7868
7655
 
7869
- if (isInterfaceType(typeB) && schema.isSubType(typeB, typeA)) {
7870
- return 1;
7871
- }
7656
+ case Kind.INPUT_OBJECT_TYPE_DEFINITION:
7657
+ case Kind.INPUT_OBJECT_TYPE_EXTENSION:
7658
+ return DirectiveLocation.INPUT_OBJECT;
7872
7659
 
7873
- return naturalCompare(typeA.name, typeB.name);
7874
- }).map(function (x) {
7875
- return x.name;
7876
- });
7660
+ case Kind.INPUT_VALUE_DEFINITION:
7661
+ {
7662
+ var parentNode = ancestors[ancestors.length - 3];
7663
+ return parentNode.kind === Kind.INPUT_OBJECT_TYPE_DEFINITION ? DirectiveLocation.INPUT_FIELD_DEFINITION : DirectiveLocation.ARGUMENT_DEFINITION;
7664
+ }
7665
+ }
7877
7666
  }
7878
- /**
7879
- * For the field name provided, determine if there are any similar field names
7880
- * that may be the result of a typo.
7881
- */
7882
7667
 
7668
+ function getDirectiveLocationForOperation(operation) {
7669
+ switch (operation) {
7670
+ case 'query':
7671
+ return DirectiveLocation.QUERY;
7672
+
7673
+ case 'mutation':
7674
+ return DirectiveLocation.MUTATION;
7883
7675
 
7884
- function getSuggestedFieldNames(type, fieldName) {
7885
- if (isObjectType(type) || isInterfaceType(type)) {
7886
- var possibleFieldNames = Object.keys(type.getFields());
7887
- return suggestionList(fieldName, possibleFieldNames);
7888
- } // Otherwise, must be a Union type, which does not define fields.
7676
+ case 'subscription':
7677
+ return DirectiveLocation.SUBSCRIPTION;
7678
+ } // istanbul ignore next (Not reachable. All possible types have been considered)
7889
7679
 
7890
7680
 
7891
- return [];
7681
+ invariant(0, 'Unexpected operation: ' + inspect(operation));
7892
7682
  }
7893
7683
 
7894
7684
  /**
7895
- * Unique fragment names
7685
+ * Unique directive names per location
7896
7686
  *
7897
- * A GraphQL document is only valid if all defined fragments have unique names.
7687
+ * A GraphQL document is only valid if all non-repeatable directives at
7688
+ * a given location are uniquely named.
7898
7689
  */
7899
- function UniqueFragmentNamesRule(context) {
7900
- var knownFragmentNames = Object.create(null);
7901
- return {
7902
- OperationDefinition: function OperationDefinition() {
7903
- return false;
7904
- },
7905
- FragmentDefinition: function FragmentDefinition(node) {
7906
- var fragmentName = node.name.value;
7690
+ function UniqueDirectivesPerLocationRule(context) {
7691
+ var uniqueDirectiveMap = Object.create(null);
7692
+ var schema = context.getSchema();
7693
+ var definedDirectives = schema ? schema.getDirectives() : specifiedDirectives;
7907
7694
 
7908
- if (knownFragmentNames[fragmentName]) {
7909
- context.reportError(new GraphQLError("There can be only one fragment named \"".concat(fragmentName, "\"."), [knownFragmentNames[fragmentName], node.name]));
7910
- } else {
7911
- knownFragmentNames[fragmentName] = node.name;
7912
- }
7695
+ for (var _i2 = 0; _i2 < definedDirectives.length; _i2++) {
7696
+ var directive = definedDirectives[_i2];
7697
+ uniqueDirectiveMap[directive.name] = !directive.isRepeatable;
7698
+ }
7913
7699
 
7914
- return false;
7915
- }
7916
- };
7917
- }
7700
+ var astDefinitions = context.getDocument().definitions;
7918
7701
 
7919
- /**
7920
- * Known fragment names
7921
- *
7922
- * A GraphQL document is only valid if all `...Fragment` fragment spreads refer
7923
- * to fragments defined in the same document.
7924
- */
7925
- function KnownFragmentNamesRule(context) {
7926
- return {
7927
- FragmentSpread: function FragmentSpread(node) {
7928
- var fragmentName = node.name.value;
7929
- var fragment = context.getFragment(fragmentName);
7702
+ for (var _i4 = 0; _i4 < astDefinitions.length; _i4++) {
7703
+ var def = astDefinitions[_i4];
7930
7704
 
7931
- if (!fragment) {
7932
- context.reportError(new GraphQLError("Unknown fragment \"".concat(fragmentName, "\"."), node.name));
7933
- }
7705
+ if (def.kind === Kind.DIRECTIVE_DEFINITION) {
7706
+ uniqueDirectiveMap[def.name.value] = !def.repeatable;
7934
7707
  }
7935
- };
7936
- }
7708
+ }
7937
7709
 
7938
- /**
7939
- * No unused fragments
7940
- *
7941
- * A GraphQL document is only valid if all fragment definitions are spread
7942
- * within operations, or spread within other fragments spread within operations.
7943
- */
7944
- function NoUnusedFragmentsRule(context) {
7945
- var operationDefs = [];
7946
- var fragmentDefs = [];
7947
- return {
7948
- OperationDefinition: function OperationDefinition(node) {
7949
- operationDefs.push(node);
7950
- return false;
7951
- },
7952
- FragmentDefinition: function FragmentDefinition(node) {
7953
- fragmentDefs.push(node);
7954
- return false;
7955
- },
7956
- Document: {
7957
- leave: function leave() {
7958
- var fragmentNameUsed = Object.create(null);
7959
-
7960
- for (var _i2 = 0; _i2 < operationDefs.length; _i2++) {
7961
- var operation = operationDefs[_i2];
7962
-
7963
- for (var _i4 = 0, _context$getRecursive2 = context.getRecursivelyReferencedFragments(operation); _i4 < _context$getRecursive2.length; _i4++) {
7964
- var fragment = _context$getRecursive2[_i4];
7965
- fragmentNameUsed[fragment.name.value] = true;
7966
- }
7967
- }
7968
-
7969
- for (var _i6 = 0; _i6 < fragmentDefs.length; _i6++) {
7970
- var fragmentDef = fragmentDefs[_i6];
7971
- var fragName = fragmentDef.name.value;
7972
-
7973
- if (fragmentNameUsed[fragName] !== true) {
7974
- context.reportError(new GraphQLError("Fragment \"".concat(fragName, "\" is never used."), fragmentDef));
7975
- }
7976
- }
7977
- }
7978
- }
7979
- };
7980
- }
7981
-
7982
- /**
7983
- * Possible fragment spread
7984
- *
7985
- * A fragment spread is only valid if the type condition could ever possibly
7986
- * be true: if there is a non-empty intersection of the possible parent types,
7987
- * and possible types which pass the type condition.
7988
- */
7989
- function PossibleFragmentSpreadsRule(context) {
7990
- return {
7991
- InlineFragment: function InlineFragment(node) {
7992
- var fragType = context.getType();
7993
- var parentType = context.getParentType();
7994
-
7995
- if (isCompositeType(fragType) && isCompositeType(parentType) && !doTypesOverlap(context.getSchema(), fragType, parentType)) {
7996
- var parentTypeStr = inspect(parentType);
7997
- var fragTypeStr = inspect(fragType);
7998
- context.reportError(new GraphQLError("Fragment cannot be spread here as objects of type \"".concat(parentTypeStr, "\" can never be of type \"").concat(fragTypeStr, "\"."), node));
7999
- }
8000
- },
8001
- FragmentSpread: function FragmentSpread(node) {
8002
- var fragName = node.name.value;
8003
- var fragType = getFragmentType(context, fragName);
8004
- var parentType = context.getParentType();
8005
-
8006
- if (fragType && parentType && !doTypesOverlap(context.getSchema(), fragType, parentType)) {
8007
- var parentTypeStr = inspect(parentType);
8008
- var fragTypeStr = inspect(fragType);
8009
- context.reportError(new GraphQLError("Fragment \"".concat(fragName, "\" cannot be spread here as objects of type \"").concat(parentTypeStr, "\" can never be of type \"").concat(fragTypeStr, "\"."), node));
8010
- }
8011
- }
8012
- };
8013
- }
8014
-
8015
- function getFragmentType(context, name) {
8016
- var frag = context.getFragment(name);
8017
-
8018
- if (frag) {
8019
- var type = typeFromAST(context.getSchema(), frag.typeCondition);
8020
-
8021
- if (isCompositeType(type)) {
8022
- return type;
8023
- }
8024
- }
8025
- }
8026
-
8027
- function NoFragmentCyclesRule(context) {
8028
- // Tracks already visited fragments to maintain O(N) and to ensure that cycles
8029
- // are not redundantly reported.
8030
- var visitedFrags = Object.create(null); // Array of AST nodes used to produce meaningful errors
8031
-
8032
- var spreadPath = []; // Position in the spread path
8033
-
8034
- var spreadPathIndexByName = Object.create(null);
8035
- return {
8036
- OperationDefinition: function OperationDefinition() {
8037
- return false;
8038
- },
8039
- FragmentDefinition: function FragmentDefinition(node) {
8040
- detectCycleRecursive(node);
8041
- return false;
8042
- }
8043
- }; // This does a straight-forward DFS to find cycles.
8044
- // It does not terminate when a cycle was found but continues to explore
8045
- // the graph to find all possible cycles.
8046
-
8047
- function detectCycleRecursive(fragment) {
8048
- if (visitedFrags[fragment.name.value]) {
8049
- return;
8050
- }
8051
-
8052
- var fragmentName = fragment.name.value;
8053
- visitedFrags[fragmentName] = true;
8054
- var spreadNodes = context.getFragmentSpreads(fragment.selectionSet);
8055
-
8056
- if (spreadNodes.length === 0) {
8057
- return;
8058
- }
8059
-
8060
- spreadPathIndexByName[fragmentName] = spreadPath.length;
8061
-
8062
- for (var _i2 = 0; _i2 < spreadNodes.length; _i2++) {
8063
- var spreadNode = spreadNodes[_i2];
8064
- var spreadName = spreadNode.name.value;
8065
- var cycleIndex = spreadPathIndexByName[spreadName];
8066
- spreadPath.push(spreadNode);
8067
-
8068
- if (cycleIndex === undefined) {
8069
- var spreadFragment = context.getFragment(spreadName);
8070
-
8071
- if (spreadFragment) {
8072
- detectCycleRecursive(spreadFragment);
8073
- }
8074
- } else {
8075
- var cyclePath = spreadPath.slice(cycleIndex);
8076
- var viaPath = cyclePath.slice(0, -1).map(function (s) {
8077
- return '"' + s.name.value + '"';
8078
- }).join(', ');
8079
- context.reportError(new GraphQLError("Cannot spread fragment \"".concat(spreadName, "\" within itself") + (viaPath !== '' ? " via ".concat(viaPath, ".") : '.'), cyclePath));
8080
- }
8081
-
8082
- spreadPath.pop();
8083
- }
8084
-
8085
- spreadPathIndexByName[fragmentName] = undefined;
8086
- }
8087
- }
8088
-
8089
- /**
8090
- * Unique variable names
8091
- *
8092
- * A GraphQL operation is only valid if all its variables are uniquely named.
8093
- */
8094
- function UniqueVariableNamesRule(context) {
8095
- var knownVariableNames = Object.create(null);
8096
- return {
8097
- OperationDefinition: function OperationDefinition() {
8098
- knownVariableNames = Object.create(null);
8099
- },
8100
- VariableDefinition: function VariableDefinition(node) {
8101
- var variableName = node.variable.name.value;
8102
-
8103
- if (knownVariableNames[variableName]) {
8104
- context.reportError(new GraphQLError("There can be only one variable named \"$".concat(variableName, "\"."), [knownVariableNames[variableName], node.variable.name]));
8105
- } else {
8106
- knownVariableNames[variableName] = node.variable.name;
8107
- }
8108
- }
8109
- };
8110
- }
8111
-
8112
- /**
8113
- * No undefined variables
8114
- *
8115
- * A GraphQL operation is only valid if all variables encountered, both directly
8116
- * and via fragment spreads, are defined by that operation.
8117
- */
8118
- function NoUndefinedVariablesRule(context) {
8119
- var variableNameDefined = Object.create(null);
8120
- return {
8121
- OperationDefinition: {
8122
- enter: function enter() {
8123
- variableNameDefined = Object.create(null);
8124
- },
8125
- leave: function leave(operation) {
8126
- var usages = context.getRecursiveVariableUsages(operation);
8127
-
8128
- for (var _i2 = 0; _i2 < usages.length; _i2++) {
8129
- var _ref2 = usages[_i2];
8130
- var node = _ref2.node;
8131
- var varName = node.name.value;
8132
-
8133
- if (variableNameDefined[varName] !== true) {
8134
- context.reportError(new GraphQLError(operation.name ? "Variable \"$".concat(varName, "\" is not defined by operation \"").concat(operation.name.value, "\".") : "Variable \"$".concat(varName, "\" is not defined."), [node, operation]));
8135
- }
8136
- }
8137
- }
8138
- },
8139
- VariableDefinition: function VariableDefinition(node) {
8140
- variableNameDefined[node.variable.name.value] = true;
8141
- }
8142
- };
8143
- }
8144
-
8145
- /**
8146
- * No unused variables
8147
- *
8148
- * A GraphQL operation is only valid if all variables defined by an operation
8149
- * are used, either directly or within a spread fragment.
8150
- */
8151
- function NoUnusedVariablesRule(context) {
8152
- var variableDefs = [];
8153
- return {
8154
- OperationDefinition: {
8155
- enter: function enter() {
8156
- variableDefs = [];
8157
- },
8158
- leave: function leave(operation) {
8159
- var variableNameUsed = Object.create(null);
8160
- var usages = context.getRecursiveVariableUsages(operation);
8161
-
8162
- for (var _i2 = 0; _i2 < usages.length; _i2++) {
8163
- var _ref2 = usages[_i2];
8164
- var node = _ref2.node;
8165
- variableNameUsed[node.name.value] = true;
8166
- }
8167
-
8168
- for (var _i4 = 0, _variableDefs2 = variableDefs; _i4 < _variableDefs2.length; _i4++) {
8169
- var variableDef = _variableDefs2[_i4];
8170
- var variableName = variableDef.variable.name.value;
8171
-
8172
- if (variableNameUsed[variableName] !== true) {
8173
- context.reportError(new GraphQLError(operation.name ? "Variable \"$".concat(variableName, "\" is never used in operation \"").concat(operation.name.value, "\".") : "Variable \"$".concat(variableName, "\" is never used."), variableDef));
8174
- }
8175
- }
8176
- }
8177
- },
8178
- VariableDefinition: function VariableDefinition(def) {
8179
- variableDefs.push(def);
8180
- }
8181
- };
8182
- }
8183
-
8184
- /**
8185
- * Known directives
8186
- *
8187
- * A GraphQL document is only valid if all `@directives` are known by the
8188
- * schema and legally positioned.
8189
- */
8190
- function KnownDirectivesRule(context) {
8191
- var locationsMap = Object.create(null);
8192
- var schema = context.getSchema();
8193
- var definedDirectives = schema ? schema.getDirectives() : specifiedDirectives;
8194
-
8195
- for (var _i2 = 0; _i2 < definedDirectives.length; _i2++) {
8196
- var directive = definedDirectives[_i2];
8197
- locationsMap[directive.name] = directive.locations;
8198
- }
8199
-
8200
- var astDefinitions = context.getDocument().definitions;
8201
-
8202
- for (var _i4 = 0; _i4 < astDefinitions.length; _i4++) {
8203
- var def = astDefinitions[_i4];
8204
-
8205
- if (def.kind === Kind.DIRECTIVE_DEFINITION) {
8206
- locationsMap[def.name.value] = def.locations.map(function (name) {
8207
- return name.value;
8208
- });
8209
- }
8210
- }
8211
-
8212
- return {
8213
- Directive: function Directive(node, _key, _parent, _path, ancestors) {
8214
- var name = node.name.value;
8215
- var locations = locationsMap[name];
8216
-
8217
- if (!locations) {
8218
- context.reportError(new GraphQLError("Unknown directive \"@".concat(name, "\"."), node));
8219
- return;
8220
- }
8221
-
8222
- var candidateLocation = getDirectiveLocationForASTPath(ancestors);
8223
-
8224
- if (candidateLocation && locations.indexOf(candidateLocation) === -1) {
8225
- context.reportError(new GraphQLError("Directive \"@".concat(name, "\" may not be used on ").concat(candidateLocation, "."), node));
8226
- }
8227
- }
8228
- };
8229
- }
8230
-
8231
- function getDirectiveLocationForASTPath(ancestors) {
8232
- var appliedTo = ancestors[ancestors.length - 1];
8233
- !Array.isArray(appliedTo) || invariant(0);
8234
-
8235
- switch (appliedTo.kind) {
8236
- case Kind.OPERATION_DEFINITION:
8237
- return getDirectiveLocationForOperation(appliedTo.operation);
8238
-
8239
- case Kind.FIELD:
8240
- return DirectiveLocation.FIELD;
8241
-
8242
- case Kind.FRAGMENT_SPREAD:
8243
- return DirectiveLocation.FRAGMENT_SPREAD;
8244
-
8245
- case Kind.INLINE_FRAGMENT:
8246
- return DirectiveLocation.INLINE_FRAGMENT;
8247
-
8248
- case Kind.FRAGMENT_DEFINITION:
8249
- return DirectiveLocation.FRAGMENT_DEFINITION;
8250
-
8251
- case Kind.VARIABLE_DEFINITION:
8252
- return DirectiveLocation.VARIABLE_DEFINITION;
8253
-
8254
- case Kind.SCHEMA_DEFINITION:
8255
- case Kind.SCHEMA_EXTENSION:
8256
- return DirectiveLocation.SCHEMA;
8257
-
8258
- case Kind.SCALAR_TYPE_DEFINITION:
8259
- case Kind.SCALAR_TYPE_EXTENSION:
8260
- return DirectiveLocation.SCALAR;
8261
-
8262
- case Kind.OBJECT_TYPE_DEFINITION:
8263
- case Kind.OBJECT_TYPE_EXTENSION:
8264
- return DirectiveLocation.OBJECT;
8265
-
8266
- case Kind.FIELD_DEFINITION:
8267
- return DirectiveLocation.FIELD_DEFINITION;
8268
-
8269
- case Kind.INTERFACE_TYPE_DEFINITION:
8270
- case Kind.INTERFACE_TYPE_EXTENSION:
8271
- return DirectiveLocation.INTERFACE;
8272
-
8273
- case Kind.UNION_TYPE_DEFINITION:
8274
- case Kind.UNION_TYPE_EXTENSION:
8275
- return DirectiveLocation.UNION;
8276
-
8277
- case Kind.ENUM_TYPE_DEFINITION:
8278
- case Kind.ENUM_TYPE_EXTENSION:
8279
- return DirectiveLocation.ENUM;
8280
-
8281
- case Kind.ENUM_VALUE_DEFINITION:
8282
- return DirectiveLocation.ENUM_VALUE;
8283
-
8284
- case Kind.INPUT_OBJECT_TYPE_DEFINITION:
8285
- case Kind.INPUT_OBJECT_TYPE_EXTENSION:
8286
- return DirectiveLocation.INPUT_OBJECT;
8287
-
8288
- case Kind.INPUT_VALUE_DEFINITION:
8289
- {
8290
- var parentNode = ancestors[ancestors.length - 3];
8291
- return parentNode.kind === Kind.INPUT_OBJECT_TYPE_DEFINITION ? DirectiveLocation.INPUT_FIELD_DEFINITION : DirectiveLocation.ARGUMENT_DEFINITION;
8292
- }
8293
- }
8294
- }
8295
-
8296
- function getDirectiveLocationForOperation(operation) {
8297
- switch (operation) {
8298
- case 'query':
8299
- return DirectiveLocation.QUERY;
8300
-
8301
- case 'mutation':
8302
- return DirectiveLocation.MUTATION;
8303
-
8304
- case 'subscription':
8305
- return DirectiveLocation.SUBSCRIPTION;
8306
- } // istanbul ignore next (Not reachable. All possible types have been considered)
8307
-
8308
-
8309
- invariant(0, 'Unexpected operation: ' + inspect(operation));
8310
- }
8311
-
8312
- /**
8313
- * Unique directive names per location
8314
- *
8315
- * A GraphQL document is only valid if all non-repeatable directives at
8316
- * a given location are uniquely named.
8317
- */
8318
- function UniqueDirectivesPerLocationRule(context) {
8319
- var uniqueDirectiveMap = Object.create(null);
8320
- var schema = context.getSchema();
8321
- var definedDirectives = schema ? schema.getDirectives() : specifiedDirectives;
8322
-
8323
- for (var _i2 = 0; _i2 < definedDirectives.length; _i2++) {
8324
- var directive = definedDirectives[_i2];
8325
- uniqueDirectiveMap[directive.name] = !directive.isRepeatable;
8326
- }
8327
-
8328
- var astDefinitions = context.getDocument().definitions;
8329
-
8330
- for (var _i4 = 0; _i4 < astDefinitions.length; _i4++) {
8331
- var def = astDefinitions[_i4];
8332
-
8333
- if (def.kind === Kind.DIRECTIVE_DEFINITION) {
8334
- uniqueDirectiveMap[def.name.value] = !def.repeatable;
8335
- }
8336
- }
8337
-
8338
- var schemaDirectives = Object.create(null);
8339
- var typeDirectivesMap = Object.create(null);
7710
+ var schemaDirectives = Object.create(null);
7711
+ var typeDirectivesMap = Object.create(null);
8340
7712
  return {
8341
7713
  // Many different AST nodes may contain directives. Rather than listing
8342
7714
  // them all, just listen for entering any node, and check to see if it
@@ -8377,36 +7749,6 @@ function UniqueDirectivesPerLocationRule(context) {
8377
7749
  };
8378
7750
  }
8379
7751
 
8380
- function ownKeys$2(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; }
8381
-
8382
- function _objectSpread$2(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$2(Object(source), true).forEach(function (key) { _defineProperty$3(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$2(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
8383
-
8384
- function _defineProperty$3(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; }
8385
-
8386
- /**
8387
- * Known argument names
8388
- *
8389
- * A GraphQL field is only valid if all supplied arguments are defined by
8390
- * that field.
8391
- */
8392
- function KnownArgumentNamesRule(context) {
8393
- return _objectSpread$2(_objectSpread$2({}, KnownArgumentNamesOnDirectivesRule(context)), {}, {
8394
- Argument: function Argument(argNode) {
8395
- var argDef = context.getArgument();
8396
- var fieldDef = context.getFieldDef();
8397
- var parentType = context.getParentType();
8398
-
8399
- if (!argDef && fieldDef && parentType) {
8400
- var argName = argNode.name.value;
8401
- var knownArgsNames = fieldDef.args.map(function (arg) {
8402
- return arg.name;
8403
- });
8404
- var suggestions = suggestionList(argName, knownArgsNames);
8405
- context.reportError(new GraphQLError("Unknown argument \"".concat(argName, "\" on field \"").concat(parentType.name, ".").concat(fieldDef.name, "\".") + didYouMean(suggestions), argNode));
8406
- }
8407
- }
8408
- });
8409
- }
8410
7752
  /**
8411
7753
  * @internal
8412
7754
  */
@@ -8484,174 +7826,12 @@ function UniqueArgumentNamesRule(context) {
8484
7826
  } else {
8485
7827
  knownArgNames[argName] = node.name;
8486
7828
  }
8487
-
8488
- return false;
8489
- }
8490
- };
8491
- }
8492
-
8493
- /**
8494
- * Value literals of correct type
8495
- *
8496
- * A GraphQL document is only valid if all value literals are of the type
8497
- * expected at their position.
8498
- */
8499
- function ValuesOfCorrectTypeRule(context) {
8500
- return {
8501
- ListValue: function ListValue(node) {
8502
- // Note: TypeInfo will traverse into a list's item type, so look to the
8503
- // parent input type to check if it is a list.
8504
- var type = getNullableType(context.getParentInputType());
8505
-
8506
- if (!isListType(type)) {
8507
- isValidValueNode(context, node);
8508
- return false; // Don't traverse further.
8509
- }
8510
- },
8511
- ObjectValue: function ObjectValue(node) {
8512
- var type = getNamedType(context.getInputType());
8513
-
8514
- if (!isInputObjectType(type)) {
8515
- isValidValueNode(context, node);
8516
- return false; // Don't traverse further.
8517
- } // Ensure every required field exists.
8518
-
8519
-
8520
- var fieldNodeMap = keyMap(node.fields, function (field) {
8521
- return field.name.value;
8522
- });
8523
-
8524
- for (var _i2 = 0, _objectValues2 = objectValues$1(type.getFields()); _i2 < _objectValues2.length; _i2++) {
8525
- var fieldDef = _objectValues2[_i2];
8526
- var fieldNode = fieldNodeMap[fieldDef.name];
8527
-
8528
- if (!fieldNode && isRequiredInputField(fieldDef)) {
8529
- var typeStr = inspect(fieldDef.type);
8530
- context.reportError(new GraphQLError("Field \"".concat(type.name, ".").concat(fieldDef.name, "\" of required type \"").concat(typeStr, "\" was not provided."), node));
8531
- }
8532
- }
8533
- },
8534
- ObjectField: function ObjectField(node) {
8535
- var parentType = getNamedType(context.getParentInputType());
8536
- var fieldType = context.getInputType();
8537
-
8538
- if (!fieldType && isInputObjectType(parentType)) {
8539
- var suggestions = suggestionList(node.name.value, Object.keys(parentType.getFields()));
8540
- context.reportError(new GraphQLError("Field \"".concat(node.name.value, "\" is not defined by type \"").concat(parentType.name, "\".") + didYouMean(suggestions), node));
8541
- }
8542
- },
8543
- NullValue: function NullValue(node) {
8544
- var type = context.getInputType();
8545
-
8546
- if (isNonNullType(type)) {
8547
- context.reportError(new GraphQLError("Expected value of type \"".concat(inspect(type), "\", found ").concat(print(node), "."), node));
8548
- }
8549
- },
8550
- EnumValue: function EnumValue(node) {
8551
- return isValidValueNode(context, node);
8552
- },
8553
- IntValue: function IntValue(node) {
8554
- return isValidValueNode(context, node);
8555
- },
8556
- FloatValue: function FloatValue(node) {
8557
- return isValidValueNode(context, node);
8558
- },
8559
- StringValue: function StringValue(node) {
8560
- return isValidValueNode(context, node);
8561
- },
8562
- BooleanValue: function BooleanValue(node) {
8563
- return isValidValueNode(context, node);
8564
- }
8565
- };
8566
- }
8567
- /**
8568
- * Any value literal may be a valid representation of a Scalar, depending on
8569
- * that scalar type.
8570
- */
8571
-
8572
- function isValidValueNode(context, node) {
8573
- // Report any error at the full type expected by the location.
8574
- var locationType = context.getInputType();
8575
-
8576
- if (!locationType) {
8577
- return;
8578
- }
8579
-
8580
- var type = getNamedType(locationType);
8581
-
8582
- if (!isLeafType(type)) {
8583
- var typeStr = inspect(locationType);
8584
- context.reportError(new GraphQLError("Expected value of type \"".concat(typeStr, "\", found ").concat(print(node), "."), node));
8585
- return;
8586
- } // Scalars and Enums determine if a literal value is valid via parseLiteral(),
8587
- // which may throw or return an invalid value to indicate failure.
8588
-
8589
-
8590
- try {
8591
- var parseResult = type.parseLiteral(node, undefined
8592
- /* variables */
8593
- );
8594
-
8595
- if (parseResult === undefined) {
8596
- var _typeStr = inspect(locationType);
8597
-
8598
- context.reportError(new GraphQLError("Expected value of type \"".concat(_typeStr, "\", found ").concat(print(node), "."), node));
8599
- }
8600
- } catch (error) {
8601
- var _typeStr2 = inspect(locationType);
8602
-
8603
- if (error instanceof GraphQLError) {
8604
- context.reportError(error);
8605
- } else {
8606
- context.reportError(new GraphQLError("Expected value of type \"".concat(_typeStr2, "\", found ").concat(print(node), "; ") + error.message, node, undefined, undefined, undefined, error));
8607
- }
8608
- }
8609
- }
8610
-
8611
- function ownKeys$1(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; }
8612
-
8613
- function _objectSpread$1(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$1(Object(source), true).forEach(function (key) { _defineProperty$2(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$1(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
8614
-
8615
- function _defineProperty$2(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; }
8616
-
8617
- /**
8618
- * Provided required arguments
8619
- *
8620
- * A field or directive is only valid if all required (non-null without a
8621
- * default value) field arguments have been provided.
8622
- */
8623
- function ProvidedRequiredArgumentsRule(context) {
8624
- return _objectSpread$1(_objectSpread$1({}, ProvidedRequiredArgumentsOnDirectivesRule(context)), {}, {
8625
- Field: {
8626
- // Validate on leave to allow for deeper errors to appear first.
8627
- leave: function leave(fieldNode) {
8628
- var _fieldNode$arguments;
8629
-
8630
- var fieldDef = context.getFieldDef();
8631
-
8632
- if (!fieldDef) {
8633
- return false;
8634
- } // istanbul ignore next (See: 'https://github.com/graphql/graphql-js/issues/2203')
8635
-
8636
-
8637
- var argNodes = (_fieldNode$arguments = fieldNode.arguments) !== null && _fieldNode$arguments !== void 0 ? _fieldNode$arguments : [];
8638
- var argNodeMap = keyMap(argNodes, function (arg) {
8639
- return arg.name.value;
8640
- });
8641
-
8642
- for (var _i2 = 0, _fieldDef$args2 = fieldDef.args; _i2 < _fieldDef$args2.length; _i2++) {
8643
- var argDef = _fieldDef$args2[_i2];
8644
- var argNode = argNodeMap[argDef.name];
8645
-
8646
- if (!argNode && isRequiredArgument(argDef)) {
8647
- var argTypeStr = inspect(argDef.type);
8648
- context.reportError(new GraphQLError("Field \"".concat(fieldDef.name, "\" argument \"").concat(argDef.name, "\" of type \"").concat(argTypeStr, "\" is required, but it was not provided."), fieldNode));
8649
- }
8650
- }
8651
- }
7829
+
7830
+ return false;
8652
7831
  }
8653
- });
7832
+ };
8654
7833
  }
7834
+
8655
7835
  /**
8656
7836
  * @internal
8657
7837
  */
@@ -8720,632 +7900,6 @@ function isRequiredArgumentNode(arg) {
8720
7900
  return arg.type.kind === Kind.NON_NULL_TYPE && arg.defaultValue == null;
8721
7901
  }
8722
7902
 
8723
- /**
8724
- * Variables passed to field arguments conform to type
8725
- */
8726
- function VariablesInAllowedPositionRule(context) {
8727
- var varDefMap = Object.create(null);
8728
- return {
8729
- OperationDefinition: {
8730
- enter: function enter() {
8731
- varDefMap = Object.create(null);
8732
- },
8733
- leave: function leave(operation) {
8734
- var usages = context.getRecursiveVariableUsages(operation);
8735
-
8736
- for (var _i2 = 0; _i2 < usages.length; _i2++) {
8737
- var _ref2 = usages[_i2];
8738
- var node = _ref2.node;
8739
- var type = _ref2.type;
8740
- var defaultValue = _ref2.defaultValue;
8741
- var varName = node.name.value;
8742
- var varDef = varDefMap[varName];
8743
-
8744
- if (varDef && type) {
8745
- // A var type is allowed if it is the same or more strict (e.g. is
8746
- // a subtype of) than the expected type. It can be more strict if
8747
- // the variable type is non-null when the expected type is nullable.
8748
- // If both are list types, the variable item type can be more strict
8749
- // than the expected item type (contravariant).
8750
- var schema = context.getSchema();
8751
- var varType = typeFromAST(schema, varDef.type);
8752
-
8753
- if (varType && !allowedVariableUsage(schema, varType, varDef.defaultValue, type, defaultValue)) {
8754
- var varTypeStr = inspect(varType);
8755
- var typeStr = inspect(type);
8756
- context.reportError(new GraphQLError("Variable \"$".concat(varName, "\" of type \"").concat(varTypeStr, "\" used in position expecting type \"").concat(typeStr, "\"."), [varDef, node]));
8757
- }
8758
- }
8759
- }
8760
- }
8761
- },
8762
- VariableDefinition: function VariableDefinition(node) {
8763
- varDefMap[node.variable.name.value] = node;
8764
- }
8765
- };
8766
- }
8767
- /**
8768
- * Returns true if the variable is allowed in the location it was found,
8769
- * which includes considering if default values exist for either the variable
8770
- * or the location at which it is located.
8771
- */
8772
-
8773
- function allowedVariableUsage(schema, varType, varDefaultValue, locationType, locationDefaultValue) {
8774
- if (isNonNullType(locationType) && !isNonNullType(varType)) {
8775
- var hasNonNullVariableDefaultValue = varDefaultValue != null && varDefaultValue.kind !== Kind.NULL;
8776
- var hasLocationDefaultValue = locationDefaultValue !== undefined;
8777
-
8778
- if (!hasNonNullVariableDefaultValue && !hasLocationDefaultValue) {
8779
- return false;
8780
- }
8781
-
8782
- var nullableLocationType = locationType.ofType;
8783
- return isTypeSubTypeOf(schema, varType, nullableLocationType);
8784
- }
8785
-
8786
- return isTypeSubTypeOf(schema, varType, locationType);
8787
- }
8788
-
8789
- function reasonMessage(reason) {
8790
- if (Array.isArray(reason)) {
8791
- return reason.map(function (_ref) {
8792
- var responseName = _ref[0],
8793
- subReason = _ref[1];
8794
- return "subfields \"".concat(responseName, "\" conflict because ") + reasonMessage(subReason);
8795
- }).join(' and ');
8796
- }
8797
-
8798
- return reason;
8799
- }
8800
- /**
8801
- * Overlapping fields can be merged
8802
- *
8803
- * A selection set is only valid if all fields (including spreading any
8804
- * fragments) either correspond to distinct response names or can be merged
8805
- * without ambiguity.
8806
- */
8807
-
8808
-
8809
- function OverlappingFieldsCanBeMergedRule(context) {
8810
- // A memoization for when two fragments are compared "between" each other for
8811
- // conflicts. Two fragments may be compared many times, so memoizing this can
8812
- // dramatically improve the performance of this validator.
8813
- var comparedFragmentPairs = new PairSet(); // A cache for the "field map" and list of fragment names found in any given
8814
- // selection set. Selection sets may be asked for this information multiple
8815
- // times, so this improves the performance of this validator.
8816
-
8817
- var cachedFieldsAndFragmentNames = new Map();
8818
- return {
8819
- SelectionSet: function SelectionSet(selectionSet) {
8820
- var conflicts = findConflictsWithinSelectionSet(context, cachedFieldsAndFragmentNames, comparedFragmentPairs, context.getParentType(), selectionSet);
8821
-
8822
- for (var _i2 = 0; _i2 < conflicts.length; _i2++) {
8823
- var _ref3 = conflicts[_i2];
8824
- var _ref2$ = _ref3[0];
8825
- var responseName = _ref2$[0];
8826
- var reason = _ref2$[1];
8827
- var fields1 = _ref3[1];
8828
- var fields2 = _ref3[2];
8829
- var reasonMsg = reasonMessage(reason);
8830
- context.reportError(new GraphQLError("Fields \"".concat(responseName, "\" conflict because ").concat(reasonMsg, ". Use different aliases on the fields to fetch both if this was intentional."), fields1.concat(fields2)));
8831
- }
8832
- }
8833
- };
8834
- }
8835
-
8836
- /**
8837
- * Algorithm:
8838
- *
8839
- * Conflicts occur when two fields exist in a query which will produce the same
8840
- * response name, but represent differing values, thus creating a conflict.
8841
- * The algorithm below finds all conflicts via making a series of comparisons
8842
- * between fields. In order to compare as few fields as possible, this makes
8843
- * a series of comparisons "within" sets of fields and "between" sets of fields.
8844
- *
8845
- * Given any selection set, a collection produces both a set of fields by
8846
- * also including all inline fragments, as well as a list of fragments
8847
- * referenced by fragment spreads.
8848
- *
8849
- * A) Each selection set represented in the document first compares "within" its
8850
- * collected set of fields, finding any conflicts between every pair of
8851
- * overlapping fields.
8852
- * Note: This is the *only time* that a the fields "within" a set are compared
8853
- * to each other. After this only fields "between" sets are compared.
8854
- *
8855
- * B) Also, if any fragment is referenced in a selection set, then a
8856
- * comparison is made "between" the original set of fields and the
8857
- * referenced fragment.
8858
- *
8859
- * C) Also, if multiple fragments are referenced, then comparisons
8860
- * are made "between" each referenced fragment.
8861
- *
8862
- * D) When comparing "between" a set of fields and a referenced fragment, first
8863
- * a comparison is made between each field in the original set of fields and
8864
- * each field in the the referenced set of fields.
8865
- *
8866
- * E) Also, if any fragment is referenced in the referenced selection set,
8867
- * then a comparison is made "between" the original set of fields and the
8868
- * referenced fragment (recursively referring to step D).
8869
- *
8870
- * F) When comparing "between" two fragments, first a comparison is made between
8871
- * each field in the first referenced set of fields and each field in the the
8872
- * second referenced set of fields.
8873
- *
8874
- * G) Also, any fragments referenced by the first must be compared to the
8875
- * second, and any fragments referenced by the second must be compared to the
8876
- * first (recursively referring to step F).
8877
- *
8878
- * H) When comparing two fields, if both have selection sets, then a comparison
8879
- * is made "between" both selection sets, first comparing the set of fields in
8880
- * the first selection set with the set of fields in the second.
8881
- *
8882
- * I) Also, if any fragment is referenced in either selection set, then a
8883
- * comparison is made "between" the other set of fields and the
8884
- * referenced fragment.
8885
- *
8886
- * J) Also, if two fragments are referenced in both selection sets, then a
8887
- * comparison is made "between" the two fragments.
8888
- *
8889
- */
8890
- // Find all conflicts found "within" a selection set, including those found
8891
- // via spreading in fragments. Called when visiting each SelectionSet in the
8892
- // GraphQL Document.
8893
- function findConflictsWithinSelectionSet(context, cachedFieldsAndFragmentNames, comparedFragmentPairs, parentType, selectionSet) {
8894
- var conflicts = [];
8895
-
8896
- var _getFieldsAndFragment = getFieldsAndFragmentNames(context, cachedFieldsAndFragmentNames, parentType, selectionSet),
8897
- fieldMap = _getFieldsAndFragment[0],
8898
- fragmentNames = _getFieldsAndFragment[1]; // (A) Find find all conflicts "within" the fields of this selection set.
8899
- // Note: this is the *only place* `collectConflictsWithin` is called.
8900
-
8901
-
8902
- collectConflictsWithin(context, conflicts, cachedFieldsAndFragmentNames, comparedFragmentPairs, fieldMap);
8903
-
8904
- if (fragmentNames.length !== 0) {
8905
- // (B) Then collect conflicts between these fields and those represented by
8906
- // each spread fragment name found.
8907
- for (var i = 0; i < fragmentNames.length; i++) {
8908
- collectConflictsBetweenFieldsAndFragment(context, conflicts, cachedFieldsAndFragmentNames, comparedFragmentPairs, false, fieldMap, fragmentNames[i]); // (C) Then compare this fragment with all other fragments found in this
8909
- // selection set to collect conflicts between fragments spread together.
8910
- // This compares each item in the list of fragment names to every other
8911
- // item in that same list (except for itself).
8912
-
8913
- for (var j = i + 1; j < fragmentNames.length; j++) {
8914
- collectConflictsBetweenFragments(context, conflicts, cachedFieldsAndFragmentNames, comparedFragmentPairs, false, fragmentNames[i], fragmentNames[j]);
8915
- }
8916
- }
8917
- }
8918
-
8919
- return conflicts;
8920
- } // Collect all conflicts found between a set of fields and a fragment reference
8921
- // including via spreading in any nested fragments.
8922
-
8923
-
8924
- function collectConflictsBetweenFieldsAndFragment(context, conflicts, cachedFieldsAndFragmentNames, comparedFragmentPairs, areMutuallyExclusive, fieldMap, fragmentName) {
8925
- var fragment = context.getFragment(fragmentName);
8926
-
8927
- if (!fragment) {
8928
- return;
8929
- }
8930
-
8931
- var _getReferencedFieldsA = getReferencedFieldsAndFragmentNames(context, cachedFieldsAndFragmentNames, fragment),
8932
- fieldMap2 = _getReferencedFieldsA[0],
8933
- fragmentNames2 = _getReferencedFieldsA[1]; // Do not compare a fragment's fieldMap to itself.
8934
-
8935
-
8936
- if (fieldMap === fieldMap2) {
8937
- return;
8938
- } // (D) First collect any conflicts between the provided collection of fields
8939
- // and the collection of fields represented by the given fragment.
8940
-
8941
-
8942
- collectConflictsBetween(context, conflicts, cachedFieldsAndFragmentNames, comparedFragmentPairs, areMutuallyExclusive, fieldMap, fieldMap2); // (E) Then collect any conflicts between the provided collection of fields
8943
- // and any fragment names found in the given fragment.
8944
-
8945
- for (var i = 0; i < fragmentNames2.length; i++) {
8946
- collectConflictsBetweenFieldsAndFragment(context, conflicts, cachedFieldsAndFragmentNames, comparedFragmentPairs, areMutuallyExclusive, fieldMap, fragmentNames2[i]);
8947
- }
8948
- } // Collect all conflicts found between two fragments, including via spreading in
8949
- // any nested fragments.
8950
-
8951
-
8952
- function collectConflictsBetweenFragments(context, conflicts, cachedFieldsAndFragmentNames, comparedFragmentPairs, areMutuallyExclusive, fragmentName1, fragmentName2) {
8953
- // No need to compare a fragment to itself.
8954
- if (fragmentName1 === fragmentName2) {
8955
- return;
8956
- } // Memoize so two fragments are not compared for conflicts more than once.
8957
-
8958
-
8959
- if (comparedFragmentPairs.has(fragmentName1, fragmentName2, areMutuallyExclusive)) {
8960
- return;
8961
- }
8962
-
8963
- comparedFragmentPairs.add(fragmentName1, fragmentName2, areMutuallyExclusive);
8964
- var fragment1 = context.getFragment(fragmentName1);
8965
- var fragment2 = context.getFragment(fragmentName2);
8966
-
8967
- if (!fragment1 || !fragment2) {
8968
- return;
8969
- }
8970
-
8971
- var _getReferencedFieldsA2 = getReferencedFieldsAndFragmentNames(context, cachedFieldsAndFragmentNames, fragment1),
8972
- fieldMap1 = _getReferencedFieldsA2[0],
8973
- fragmentNames1 = _getReferencedFieldsA2[1];
8974
-
8975
- var _getReferencedFieldsA3 = getReferencedFieldsAndFragmentNames(context, cachedFieldsAndFragmentNames, fragment2),
8976
- fieldMap2 = _getReferencedFieldsA3[0],
8977
- fragmentNames2 = _getReferencedFieldsA3[1]; // (F) First, collect all conflicts between these two collections of fields
8978
- // (not including any nested fragments).
8979
-
8980
-
8981
- collectConflictsBetween(context, conflicts, cachedFieldsAndFragmentNames, comparedFragmentPairs, areMutuallyExclusive, fieldMap1, fieldMap2); // (G) Then collect conflicts between the first fragment and any nested
8982
- // fragments spread in the second fragment.
8983
-
8984
- for (var j = 0; j < fragmentNames2.length; j++) {
8985
- collectConflictsBetweenFragments(context, conflicts, cachedFieldsAndFragmentNames, comparedFragmentPairs, areMutuallyExclusive, fragmentName1, fragmentNames2[j]);
8986
- } // (G) Then collect conflicts between the second fragment and any nested
8987
- // fragments spread in the first fragment.
8988
-
8989
-
8990
- for (var i = 0; i < fragmentNames1.length; i++) {
8991
- collectConflictsBetweenFragments(context, conflicts, cachedFieldsAndFragmentNames, comparedFragmentPairs, areMutuallyExclusive, fragmentNames1[i], fragmentName2);
8992
- }
8993
- } // Find all conflicts found between two selection sets, including those found
8994
- // via spreading in fragments. Called when determining if conflicts exist
8995
- // between the sub-fields of two overlapping fields.
8996
-
8997
-
8998
- function findConflictsBetweenSubSelectionSets(context, cachedFieldsAndFragmentNames, comparedFragmentPairs, areMutuallyExclusive, parentType1, selectionSet1, parentType2, selectionSet2) {
8999
- var conflicts = [];
9000
-
9001
- var _getFieldsAndFragment2 = getFieldsAndFragmentNames(context, cachedFieldsAndFragmentNames, parentType1, selectionSet1),
9002
- fieldMap1 = _getFieldsAndFragment2[0],
9003
- fragmentNames1 = _getFieldsAndFragment2[1];
9004
-
9005
- var _getFieldsAndFragment3 = getFieldsAndFragmentNames(context, cachedFieldsAndFragmentNames, parentType2, selectionSet2),
9006
- fieldMap2 = _getFieldsAndFragment3[0],
9007
- fragmentNames2 = _getFieldsAndFragment3[1]; // (H) First, collect all conflicts between these two collections of field.
9008
-
9009
-
9010
- collectConflictsBetween(context, conflicts, cachedFieldsAndFragmentNames, comparedFragmentPairs, areMutuallyExclusive, fieldMap1, fieldMap2); // (I) Then collect conflicts between the first collection of fields and
9011
- // those referenced by each fragment name associated with the second.
9012
-
9013
- if (fragmentNames2.length !== 0) {
9014
- for (var j = 0; j < fragmentNames2.length; j++) {
9015
- collectConflictsBetweenFieldsAndFragment(context, conflicts, cachedFieldsAndFragmentNames, comparedFragmentPairs, areMutuallyExclusive, fieldMap1, fragmentNames2[j]);
9016
- }
9017
- } // (I) Then collect conflicts between the second collection of fields and
9018
- // those referenced by each fragment name associated with the first.
9019
-
9020
-
9021
- if (fragmentNames1.length !== 0) {
9022
- for (var i = 0; i < fragmentNames1.length; i++) {
9023
- collectConflictsBetweenFieldsAndFragment(context, conflicts, cachedFieldsAndFragmentNames, comparedFragmentPairs, areMutuallyExclusive, fieldMap2, fragmentNames1[i]);
9024
- }
9025
- } // (J) Also collect conflicts between any fragment names by the first and
9026
- // fragment names by the second. This compares each item in the first set of
9027
- // names to each item in the second set of names.
9028
-
9029
-
9030
- for (var _i3 = 0; _i3 < fragmentNames1.length; _i3++) {
9031
- for (var _j = 0; _j < fragmentNames2.length; _j++) {
9032
- collectConflictsBetweenFragments(context, conflicts, cachedFieldsAndFragmentNames, comparedFragmentPairs, areMutuallyExclusive, fragmentNames1[_i3], fragmentNames2[_j]);
9033
- }
9034
- }
9035
-
9036
- return conflicts;
9037
- } // Collect all Conflicts "within" one collection of fields.
9038
-
9039
-
9040
- function collectConflictsWithin(context, conflicts, cachedFieldsAndFragmentNames, comparedFragmentPairs, fieldMap) {
9041
- // A field map is a keyed collection, where each key represents a response
9042
- // name and the value at that key is a list of all fields which provide that
9043
- // response name. For every response name, if there are multiple fields, they
9044
- // must be compared to find a potential conflict.
9045
- for (var _i5 = 0, _objectEntries2 = objectEntries$1(fieldMap); _i5 < _objectEntries2.length; _i5++) {
9046
- var _ref5 = _objectEntries2[_i5];
9047
- var responseName = _ref5[0];
9048
- var fields = _ref5[1];
9049
-
9050
- // This compares every field in the list to every other field in this list
9051
- // (except to itself). If the list only has one item, nothing needs to
9052
- // be compared.
9053
- if (fields.length > 1) {
9054
- for (var i = 0; i < fields.length; i++) {
9055
- for (var j = i + 1; j < fields.length; j++) {
9056
- var conflict = findConflict(context, cachedFieldsAndFragmentNames, comparedFragmentPairs, false, // within one collection is never mutually exclusive
9057
- responseName, fields[i], fields[j]);
9058
-
9059
- if (conflict) {
9060
- conflicts.push(conflict);
9061
- }
9062
- }
9063
- }
9064
- }
9065
- }
9066
- } // Collect all Conflicts between two collections of fields. This is similar to,
9067
- // but different from the `collectConflictsWithin` function above. This check
9068
- // assumes that `collectConflictsWithin` has already been called on each
9069
- // provided collection of fields. This is true because this validator traverses
9070
- // each individual selection set.
9071
-
9072
-
9073
- function collectConflictsBetween(context, conflicts, cachedFieldsAndFragmentNames, comparedFragmentPairs, parentFieldsAreMutuallyExclusive, fieldMap1, fieldMap2) {
9074
- // A field map is a keyed collection, where each key represents a response
9075
- // name and the value at that key is a list of all fields which provide that
9076
- // response name. For any response name which appears in both provided field
9077
- // maps, each field from the first field map must be compared to every field
9078
- // in the second field map to find potential conflicts.
9079
- for (var _i7 = 0, _Object$keys2 = Object.keys(fieldMap1); _i7 < _Object$keys2.length; _i7++) {
9080
- var responseName = _Object$keys2[_i7];
9081
- var fields2 = fieldMap2[responseName];
9082
-
9083
- if (fields2) {
9084
- var fields1 = fieldMap1[responseName];
9085
-
9086
- for (var i = 0; i < fields1.length; i++) {
9087
- for (var j = 0; j < fields2.length; j++) {
9088
- var conflict = findConflict(context, cachedFieldsAndFragmentNames, comparedFragmentPairs, parentFieldsAreMutuallyExclusive, responseName, fields1[i], fields2[j]);
9089
-
9090
- if (conflict) {
9091
- conflicts.push(conflict);
9092
- }
9093
- }
9094
- }
9095
- }
9096
- }
9097
- } // Determines if there is a conflict between two particular fields, including
9098
- // comparing their sub-fields.
9099
-
9100
-
9101
- function findConflict(context, cachedFieldsAndFragmentNames, comparedFragmentPairs, parentFieldsAreMutuallyExclusive, responseName, field1, field2) {
9102
- var parentType1 = field1[0],
9103
- node1 = field1[1],
9104
- def1 = field1[2];
9105
- var parentType2 = field2[0],
9106
- node2 = field2[1],
9107
- def2 = field2[2]; // If it is known that two fields could not possibly apply at the same
9108
- // time, due to the parent types, then it is safe to permit them to diverge
9109
- // in aliased field or arguments used as they will not present any ambiguity
9110
- // by differing.
9111
- // It is known that two parent types could never overlap if they are
9112
- // different Object types. Interface or Union types might overlap - if not
9113
- // in the current state of the schema, then perhaps in some future version,
9114
- // thus may not safely diverge.
9115
-
9116
- var areMutuallyExclusive = parentFieldsAreMutuallyExclusive || parentType1 !== parentType2 && isObjectType(parentType1) && isObjectType(parentType2);
9117
-
9118
- if (!areMutuallyExclusive) {
9119
- var _node1$arguments, _node2$arguments;
9120
-
9121
- // Two aliases must refer to the same field.
9122
- var name1 = node1.name.value;
9123
- var name2 = node2.name.value;
9124
-
9125
- if (name1 !== name2) {
9126
- return [[responseName, "\"".concat(name1, "\" and \"").concat(name2, "\" are different fields")], [node1], [node2]];
9127
- } // istanbul ignore next (See: 'https://github.com/graphql/graphql-js/issues/2203')
9128
-
9129
-
9130
- var args1 = (_node1$arguments = node1.arguments) !== null && _node1$arguments !== void 0 ? _node1$arguments : []; // istanbul ignore next (See: 'https://github.com/graphql/graphql-js/issues/2203')
9131
-
9132
- var args2 = (_node2$arguments = node2.arguments) !== null && _node2$arguments !== void 0 ? _node2$arguments : []; // Two field calls must have the same arguments.
9133
-
9134
- if (!sameArguments(args1, args2)) {
9135
- return [[responseName, 'they have differing arguments'], [node1], [node2]];
9136
- }
9137
- } // The return type for each field.
9138
-
9139
-
9140
- var type1 = def1 === null || def1 === void 0 ? void 0 : def1.type;
9141
- var type2 = def2 === null || def2 === void 0 ? void 0 : def2.type;
9142
-
9143
- if (type1 && type2 && doTypesConflict(type1, type2)) {
9144
- return [[responseName, "they return conflicting types \"".concat(inspect(type1), "\" and \"").concat(inspect(type2), "\"")], [node1], [node2]];
9145
- } // Collect and compare sub-fields. Use the same "visited fragment names" list
9146
- // for both collections so fields in a fragment reference are never
9147
- // compared to themselves.
9148
-
9149
-
9150
- var selectionSet1 = node1.selectionSet;
9151
- var selectionSet2 = node2.selectionSet;
9152
-
9153
- if (selectionSet1 && selectionSet2) {
9154
- var conflicts = findConflictsBetweenSubSelectionSets(context, cachedFieldsAndFragmentNames, comparedFragmentPairs, areMutuallyExclusive, getNamedType(type1), selectionSet1, getNamedType(type2), selectionSet2);
9155
- return subfieldConflicts(conflicts, responseName, node1, node2);
9156
- }
9157
- }
9158
-
9159
- function sameArguments(arguments1, arguments2) {
9160
- if (arguments1.length !== arguments2.length) {
9161
- return false;
9162
- }
9163
-
9164
- return arguments1.every(function (argument1) {
9165
- var argument2 = find$1(arguments2, function (argument) {
9166
- return argument.name.value === argument1.name.value;
9167
- });
9168
-
9169
- if (!argument2) {
9170
- return false;
9171
- }
9172
-
9173
- return sameValue(argument1.value, argument2.value);
9174
- });
9175
- }
9176
-
9177
- function sameValue(value1, value2) {
9178
- return print(value1) === print(value2);
9179
- } // Two types conflict if both types could not apply to a value simultaneously.
9180
- // Composite types are ignored as their individual field types will be compared
9181
- // later recursively. However List and Non-Null types must match.
9182
-
9183
-
9184
- function doTypesConflict(type1, type2) {
9185
- if (isListType(type1)) {
9186
- return isListType(type2) ? doTypesConflict(type1.ofType, type2.ofType) : true;
9187
- }
9188
-
9189
- if (isListType(type2)) {
9190
- return true;
9191
- }
9192
-
9193
- if (isNonNullType(type1)) {
9194
- return isNonNullType(type2) ? doTypesConflict(type1.ofType, type2.ofType) : true;
9195
- }
9196
-
9197
- if (isNonNullType(type2)) {
9198
- return true;
9199
- }
9200
-
9201
- if (isLeafType(type1) || isLeafType(type2)) {
9202
- return type1 !== type2;
9203
- }
9204
-
9205
- return false;
9206
- } // Given a selection set, return the collection of fields (a mapping of response
9207
- // name to field nodes and definitions) as well as a list of fragment names
9208
- // referenced via fragment spreads.
9209
-
9210
-
9211
- function getFieldsAndFragmentNames(context, cachedFieldsAndFragmentNames, parentType, selectionSet) {
9212
- var cached = cachedFieldsAndFragmentNames.get(selectionSet);
9213
-
9214
- if (!cached) {
9215
- var nodeAndDefs = Object.create(null);
9216
- var fragmentNames = Object.create(null);
9217
-
9218
- _collectFieldsAndFragmentNames(context, parentType, selectionSet, nodeAndDefs, fragmentNames);
9219
-
9220
- cached = [nodeAndDefs, Object.keys(fragmentNames)];
9221
- cachedFieldsAndFragmentNames.set(selectionSet, cached);
9222
- }
9223
-
9224
- return cached;
9225
- } // Given a reference to a fragment, return the represented collection of fields
9226
- // as well as a list of nested fragment names referenced via fragment spreads.
9227
-
9228
-
9229
- function getReferencedFieldsAndFragmentNames(context, cachedFieldsAndFragmentNames, fragment) {
9230
- // Short-circuit building a type from the node if possible.
9231
- var cached = cachedFieldsAndFragmentNames.get(fragment.selectionSet);
9232
-
9233
- if (cached) {
9234
- return cached;
9235
- }
9236
-
9237
- var fragmentType = typeFromAST(context.getSchema(), fragment.typeCondition);
9238
- return getFieldsAndFragmentNames(context, cachedFieldsAndFragmentNames, fragmentType, fragment.selectionSet);
9239
- }
9240
-
9241
- function _collectFieldsAndFragmentNames(context, parentType, selectionSet, nodeAndDefs, fragmentNames) {
9242
- for (var _i9 = 0, _selectionSet$selecti2 = selectionSet.selections; _i9 < _selectionSet$selecti2.length; _i9++) {
9243
- var selection = _selectionSet$selecti2[_i9];
9244
-
9245
- switch (selection.kind) {
9246
- case Kind.FIELD:
9247
- {
9248
- var fieldName = selection.name.value;
9249
- var fieldDef = void 0;
9250
-
9251
- if (isObjectType(parentType) || isInterfaceType(parentType)) {
9252
- fieldDef = parentType.getFields()[fieldName];
9253
- }
9254
-
9255
- var responseName = selection.alias ? selection.alias.value : fieldName;
9256
-
9257
- if (!nodeAndDefs[responseName]) {
9258
- nodeAndDefs[responseName] = [];
9259
- }
9260
-
9261
- nodeAndDefs[responseName].push([parentType, selection, fieldDef]);
9262
- break;
9263
- }
9264
-
9265
- case Kind.FRAGMENT_SPREAD:
9266
- fragmentNames[selection.name.value] = true;
9267
- break;
9268
-
9269
- case Kind.INLINE_FRAGMENT:
9270
- {
9271
- var typeCondition = selection.typeCondition;
9272
- var inlineFragmentType = typeCondition ? typeFromAST(context.getSchema(), typeCondition) : parentType;
9273
-
9274
- _collectFieldsAndFragmentNames(context, inlineFragmentType, selection.selectionSet, nodeAndDefs, fragmentNames);
9275
-
9276
- break;
9277
- }
9278
- }
9279
- }
9280
- } // Given a series of Conflicts which occurred between two sub-fields, generate
9281
- // a single Conflict.
9282
-
9283
-
9284
- function subfieldConflicts(conflicts, responseName, node1, node2) {
9285
- if (conflicts.length > 0) {
9286
- return [[responseName, conflicts.map(function (_ref6) {
9287
- var reason = _ref6[0];
9288
- return reason;
9289
- })], conflicts.reduce(function (allFields, _ref7) {
9290
- var fields1 = _ref7[1];
9291
- return allFields.concat(fields1);
9292
- }, [node1]), conflicts.reduce(function (allFields, _ref8) {
9293
- var fields2 = _ref8[2];
9294
- return allFields.concat(fields2);
9295
- }, [node2])];
9296
- }
9297
- }
9298
- /**
9299
- * A way to keep track of pairs of things when the ordering of the pair does
9300
- * not matter. We do this by maintaining a sort of double adjacency sets.
9301
- */
9302
-
9303
-
9304
- var PairSet = /*#__PURE__*/function () {
9305
- function PairSet() {
9306
- this._data = Object.create(null);
9307
- }
9308
-
9309
- var _proto = PairSet.prototype;
9310
-
9311
- _proto.has = function has(a, b, areMutuallyExclusive) {
9312
- var first = this._data[a];
9313
- var result = first && first[b];
9314
-
9315
- if (result === undefined) {
9316
- return false;
9317
- } // areMutuallyExclusive being false is a superset of being true,
9318
- // hence if we want to know if this PairSet "has" these two with no
9319
- // exclusivity, we have to ensure it was added as such.
9320
-
9321
-
9322
- if (areMutuallyExclusive === false) {
9323
- return result === false;
9324
- }
9325
-
9326
- return true;
9327
- };
9328
-
9329
- _proto.add = function add(a, b, areMutuallyExclusive) {
9330
- this._pairSetAdd(a, b, areMutuallyExclusive);
9331
-
9332
- this._pairSetAdd(b, a, areMutuallyExclusive);
9333
- };
9334
-
9335
- _proto._pairSetAdd = function _pairSetAdd(a, b, areMutuallyExclusive) {
9336
- var map = this._data[a];
9337
-
9338
- if (!map) {
9339
- map = Object.create(null);
9340
- this._data[a] = map;
9341
- }
9342
-
9343
- map[b] = areMutuallyExclusive;
9344
- };
9345
-
9346
- return PairSet;
9347
- }();
9348
-
9349
7903
  /**
9350
7904
  * Unique input field names
9351
7905
  *
@@ -9727,14 +8281,6 @@ function extensionKindToTypeName(kind) {
9727
8281
  }
9728
8282
 
9729
8283
  // Spec Section: "Executable Definitions"
9730
- /**
9731
- * This set includes all validation rules defined by the GraphQL spec.
9732
- *
9733
- * The order of the rules in this list has been adjusted to lead to the
9734
- * most clear output when encountering multiple validation errors.
9735
- */
9736
-
9737
- Object.freeze([ExecutableDefinitionsRule, UniqueOperationNamesRule, LoneAnonymousOperationRule, SingleFieldSubscriptionsRule, KnownTypeNamesRule, FragmentsOnCompositeTypesRule, VariablesAreInputTypesRule, ScalarLeafsRule, FieldsOnCorrectTypeRule, UniqueFragmentNamesRule, KnownFragmentNamesRule, NoUnusedFragmentsRule, PossibleFragmentSpreadsRule, NoFragmentCyclesRule, UniqueVariableNamesRule, NoUndefinedVariablesRule, NoUnusedVariablesRule, KnownDirectivesRule, UniqueDirectivesPerLocationRule, KnownArgumentNamesRule, UniqueArgumentNamesRule, ValuesOfCorrectTypeRule, ProvidedRequiredArgumentsRule, VariablesInAllowedPositionRule, OverlappingFieldsCanBeMergedRule, UniqueInputFieldNamesRule]);
9738
8284
  /**
9739
8285
  * @internal
9740
8286
  */