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