@apollo/federation-internals 2.0.0-preview.1 → 2.0.0-preview.10
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/CHANGELOG.md +35 -3
- package/dist/buildSchema.d.ts.map +1 -1
- package/dist/buildSchema.js +59 -45
- package/dist/buildSchema.js.map +1 -1
- package/dist/coreSpec.d.ts +16 -8
- package/dist/coreSpec.d.ts.map +1 -1
- package/dist/coreSpec.js +171 -42
- package/dist/coreSpec.js.map +1 -1
- package/dist/definitions.d.ts +24 -11
- package/dist/definitions.d.ts.map +1 -1
- package/dist/definitions.js +142 -31
- package/dist/definitions.js.map +1 -1
- package/dist/directiveAndTypeSpecification.d.ts +11 -1
- package/dist/directiveAndTypeSpecification.d.ts.map +1 -1
- package/dist/directiveAndTypeSpecification.js +77 -20
- package/dist/directiveAndTypeSpecification.js.map +1 -1
- package/dist/error.d.ts +12 -0
- package/dist/error.d.ts.map +1 -1
- package/dist/error.js +44 -2
- package/dist/error.js.map +1 -1
- package/dist/extractSubgraphsFromSupergraph.d.ts.map +1 -1
- package/dist/extractSubgraphsFromSupergraph.js +15 -5
- package/dist/extractSubgraphsFromSupergraph.js.map +1 -1
- package/dist/federation.d.ts +18 -4
- package/dist/federation.d.ts.map +1 -1
- package/dist/federation.js +117 -67
- package/dist/federation.js.map +1 -1
- package/dist/federationSpec.d.ts +6 -2
- package/dist/federationSpec.d.ts.map +1 -1
- package/dist/federationSpec.js +47 -21
- package/dist/federationSpec.js.map +1 -1
- package/dist/inaccessibleSpec.d.ts +5 -1
- package/dist/inaccessibleSpec.d.ts.map +1 -1
- package/dist/inaccessibleSpec.js +31 -3
- package/dist/inaccessibleSpec.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -1
- package/dist/index.js.map +1 -1
- package/dist/introspection.d.ts.map +1 -1
- package/dist/introspection.js +8 -3
- package/dist/introspection.js.map +1 -1
- package/dist/joinSpec.d.ts +5 -1
- package/dist/joinSpec.d.ts.map +1 -1
- package/dist/joinSpec.js +21 -0
- package/dist/joinSpec.js.map +1 -1
- package/dist/knownCoreFeatures.d.ts +4 -0
- package/dist/knownCoreFeatures.d.ts.map +1 -0
- package/dist/knownCoreFeatures.js +16 -0
- package/dist/knownCoreFeatures.js.map +1 -0
- package/dist/operations.d.ts +1 -0
- package/dist/operations.d.ts.map +1 -1
- package/dist/operations.js +16 -1
- package/dist/operations.js.map +1 -1
- package/dist/{sharing.d.ts → precompute.d.ts} +1 -1
- package/dist/precompute.d.ts.map +1 -0
- package/dist/{sharing.js → precompute.js} +3 -3
- package/dist/precompute.js.map +1 -0
- package/dist/print.js +12 -12
- package/dist/print.js.map +1 -1
- package/dist/schemaUpgrader.d.ts.map +1 -1
- package/dist/schemaUpgrader.js +5 -6
- package/dist/schemaUpgrader.js.map +1 -1
- package/dist/suggestions.d.ts +1 -1
- package/dist/suggestions.d.ts.map +1 -1
- package/dist/suggestions.js.map +1 -1
- package/dist/supergraphs.d.ts.map +1 -1
- package/dist/supergraphs.js +1 -0
- package/dist/supergraphs.js.map +1 -1
- package/dist/tagSpec.d.ts +7 -2
- package/dist/tagSpec.d.ts.map +1 -1
- package/dist/tagSpec.js +35 -13
- package/dist/tagSpec.js.map +1 -1
- package/dist/validate.js +10 -7
- package/dist/validate.js.map +1 -1
- package/package.json +3 -3
- package/src/__tests__/coreSpec.test.ts +100 -0
- package/src/__tests__/definitions.test.ts +79 -0
- package/src/__tests__/extractSubgraphsFromSupergraph.test.ts +64 -0
- package/src/__tests__/removeInaccessibleElements.test.ts +59 -6
- package/src/__tests__/schemaUpgrader.test.ts +3 -2
- package/src/__tests__/subgraphValidation.test.ts +419 -4
- package/src/buildSchema.ts +104 -53
- package/src/coreSpec.ts +208 -50
- package/src/definitions.ts +185 -32
- package/src/directiveAndTypeSpecification.ts +98 -21
- package/src/error.ts +89 -1
- package/src/extractSubgraphsFromSupergraph.ts +23 -5
- package/src/federation.ts +154 -82
- package/src/federationSpec.ts +56 -23
- package/src/inaccessibleSpec.ts +39 -11
- package/src/index.ts +2 -0
- package/src/introspection.ts +8 -3
- package/src/joinSpec.ts +33 -3
- package/src/knownCoreFeatures.ts +13 -0
- package/src/operations.ts +15 -0
- package/src/{sharing.ts → precompute.ts} +3 -6
- package/src/print.ts +13 -11
- package/src/schemaUpgrader.ts +8 -12
- package/src/suggestions.ts +1 -1
- package/src/supergraphs.ts +1 -0
- package/src/tagSpec.ts +49 -15
- package/src/validate.ts +14 -9
- package/tsconfig.test.tsbuildinfo +1 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/sharing.d.ts.map +0 -1
- package/dist/sharing.js.map +0 -1
package/dist/definitions.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.newNamedType = exports.variableDefinitionFromAST = exports.variableDefinitionsFromAST = exports.VariableDefinitions = exports.VariableDefinition = exports.variablesInArguments = exports.isVariable = exports.containsVariable = exports.mergeVariables = exports.Variable = exports.Directive = exports.DirectiveDefinition = exports.EnumValue = exports.ArgumentDefinition = exports.InputFieldDefinition = exports.FieldDefinition = exports.NonNullType = exports.ListType = exports.InputObjectType = exports.EnumType = exports.UnionType = exports.UnionMember = exports.InterfaceType = exports.ObjectType = exports.InterfaceImplementation = void 0;
|
|
3
|
+
exports.RootType = exports.Schema = exports.CoreFeatures = exports.CoreFeature = exports.defaultSchemaBlueprint = exports.SchemaBlueprint = exports.NamedSchemaElementWithType = exports.NamedSchemaElement = exports.SchemaElement = exports.Extension = exports.sourceASTs = exports.DirectiveTargetElement = exports.isLeafType = exports.typeFromAST = exports.typeToAST = exports.executableDirectiveLocations = exports.runtimeTypesIntersects = exports.possibleRuntimeTypes = exports.isCompositeType = exports.isAbstractType = exports.isNullableType = exports.baseType = exports.filterTypesOfKind = exports.isTypeOfKind = exports.isInputType = exports.isOutputType = exports.isInputObjectType = exports.isUnionType = exports.isEnumType = exports.isInterfaceType = exports.isObjectType = exports.isIDType = exports.isBooleanType = exports.isFloatType = exports.isStringType = exports.isIntType = exports.isCustomScalarType = exports.isScalarType = exports.isNonNullType = exports.isListType = exports.isWrapperType = exports.isNamedType = exports.isSchemaRootType = exports.defaultRootName = exports.allSchemaRootKinds = exports.typenameFieldName = exports.printErrors = exports.printGraphQLErrorsOrRethrow = exports.errorCauses = exports.ErrGraphQLValidationFailed = void 0;
|
|
4
|
+
exports.newNamedType = exports.variableDefinitionFromAST = exports.variableDefinitionsFromAST = exports.VariableDefinitions = exports.VariableDefinition = exports.variablesInArguments = exports.isVariable = exports.containsVariable = exports.mergeVariables = exports.Variable = exports.Directive = exports.DirectiveDefinition = exports.EnumValue = exports.ArgumentDefinition = exports.InputFieldDefinition = exports.FieldDefinition = exports.NonNullType = exports.ListType = exports.InputObjectType = exports.EnumType = exports.UnionType = exports.UnionMember = exports.InterfaceType = exports.ObjectType = exports.InterfaceImplementation = exports.ScalarType = exports.SchemaDefinition = void 0;
|
|
5
5
|
const graphql_1 = require("graphql");
|
|
6
6
|
const coreSpec_1 = require("./coreSpec");
|
|
7
7
|
const utils_1 = require("./utils");
|
|
@@ -16,9 +16,12 @@ const validate_1 = require("graphql/validation/validate");
|
|
|
16
16
|
const specifiedRules_1 = require("graphql/validation/specifiedRules");
|
|
17
17
|
const validate_2 = require("./validate");
|
|
18
18
|
const directiveAndTypeSpecification_1 = require("./directiveAndTypeSpecification");
|
|
19
|
+
const suggestions_1 = require("./suggestions");
|
|
20
|
+
const error_2 = require("./error");
|
|
19
21
|
const validationErrorCode = 'GraphQLValidationFailed';
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
+
const DEFAULT_VALIDATION_ERROR_MESSAGE = 'The schema is not a valid GraphQL schema.';
|
|
23
|
+
const ErrGraphQLValidationFailed = (causes, message = DEFAULT_VALIDATION_ERROR_MESSAGE) => (0, core_schema_1.err)(validationErrorCode, {
|
|
24
|
+
message,
|
|
22
25
|
causes
|
|
23
26
|
});
|
|
24
27
|
exports.ErrGraphQLValidationFailed = ErrGraphQLValidationFailed;
|
|
@@ -156,6 +159,19 @@ function isInputType(type) {
|
|
|
156
159
|
}
|
|
157
160
|
}
|
|
158
161
|
exports.isInputType = isInputType;
|
|
162
|
+
function isTypeOfKind(type, kind) {
|
|
163
|
+
return type.kind === kind;
|
|
164
|
+
}
|
|
165
|
+
exports.isTypeOfKind = isTypeOfKind;
|
|
166
|
+
function filterTypesOfKind(types, kind) {
|
|
167
|
+
return types.reduce((acc, type) => {
|
|
168
|
+
if (isTypeOfKind(type, kind)) {
|
|
169
|
+
acc.push(type);
|
|
170
|
+
}
|
|
171
|
+
return acc;
|
|
172
|
+
}, []);
|
|
173
|
+
}
|
|
174
|
+
exports.filterTypesOfKind = filterTypesOfKind;
|
|
159
175
|
function baseType(type) {
|
|
160
176
|
return isWrapperType(type) ? type.baseType() : type;
|
|
161
177
|
}
|
|
@@ -300,7 +316,7 @@ class DirectiveTargetElement {
|
|
|
300
316
|
}
|
|
301
317
|
exports.DirectiveTargetElement = DirectiveTargetElement;
|
|
302
318
|
function sourceASTs(...elts) {
|
|
303
|
-
return elts.map(elt => elt === null || elt === void 0 ? void 0 : elt.sourceAST).filter(elt => elt !== undefined);
|
|
319
|
+
return elts.map(elt => elt === null || elt === void 0 ? void 0 : elt.sourceAST).filter((elt) => elt !== undefined);
|
|
304
320
|
}
|
|
305
321
|
exports.sourceASTs = sourceASTs;
|
|
306
322
|
class Element {
|
|
@@ -371,7 +387,7 @@ class SchemaElement extends Element {
|
|
|
371
387
|
? this.appliedDirectivesOf(nameOrDefinition)
|
|
372
388
|
: this.appliedDirectivesOf(nameOrDefinition)).length !== 0;
|
|
373
389
|
}
|
|
374
|
-
applyDirective(nameOrDefOrDirective, args) {
|
|
390
|
+
applyDirective(nameOrDefOrDirective, args, asFirstDirective = false) {
|
|
375
391
|
var _a;
|
|
376
392
|
let toAdd;
|
|
377
393
|
if (nameOrDefOrDirective instanceof Directive) {
|
|
@@ -385,9 +401,12 @@ class SchemaElement extends Element {
|
|
|
385
401
|
let name;
|
|
386
402
|
if (typeof nameOrDefOrDirective === 'string') {
|
|
387
403
|
this.checkUpdate();
|
|
388
|
-
const def = (_a = this.schema().directive(nameOrDefOrDirective)) !== null && _a !== void 0 ? _a : this.schema().blueprint.onMissingDirectiveDefinition(this.schema(), nameOrDefOrDirective);
|
|
404
|
+
const def = (_a = this.schema().directive(nameOrDefOrDirective)) !== null && _a !== void 0 ? _a : this.schema().blueprint.onMissingDirectiveDefinition(this.schema(), nameOrDefOrDirective, args);
|
|
389
405
|
if (!def) {
|
|
390
|
-
throw new graphql_1.GraphQLError(`
|
|
406
|
+
throw this.schema().blueprint.onGraphQLJSValidationError(this.schema(), new graphql_1.GraphQLError(`Unknown directive "@${nameOrDefOrDirective}".`));
|
|
407
|
+
}
|
|
408
|
+
if (Array.isArray(def)) {
|
|
409
|
+
throw (0, exports.ErrGraphQLValidationFailed)(def);
|
|
391
410
|
}
|
|
392
411
|
name = nameOrDefOrDirective;
|
|
393
412
|
}
|
|
@@ -398,7 +417,12 @@ class SchemaElement extends Element {
|
|
|
398
417
|
toAdd = new Directive(name, args !== null && args !== void 0 ? args : Object.create(null));
|
|
399
418
|
Element.prototype['setParent'].call(toAdd, this);
|
|
400
419
|
}
|
|
401
|
-
|
|
420
|
+
if (asFirstDirective) {
|
|
421
|
+
this._appliedDirectives.unshift(toAdd);
|
|
422
|
+
}
|
|
423
|
+
else {
|
|
424
|
+
this._appliedDirectives.push(toAdd);
|
|
425
|
+
}
|
|
402
426
|
DirectiveDefinition.prototype['addReferencer'].call(toAdd.definition, toAdd);
|
|
403
427
|
this.onModification();
|
|
404
428
|
return toAdd;
|
|
@@ -602,10 +626,11 @@ class BaseExtensionMember extends Element {
|
|
|
602
626
|
}
|
|
603
627
|
}
|
|
604
628
|
class SchemaBlueprint {
|
|
605
|
-
onMissingDirectiveDefinition(_schema, _name) {
|
|
629
|
+
onMissingDirectiveDefinition(_schema, _name, _args) {
|
|
606
630
|
return undefined;
|
|
607
631
|
}
|
|
608
632
|
onDirectiveDefinitionAndSchemaParsed(_) {
|
|
633
|
+
return [];
|
|
609
634
|
}
|
|
610
635
|
ignoreParsedField(_type, _fieldName) {
|
|
611
636
|
return false;
|
|
@@ -622,6 +647,25 @@ class SchemaBlueprint {
|
|
|
622
647
|
validationRules() {
|
|
623
648
|
return specifiedRules_1.specifiedSDLRules;
|
|
624
649
|
}
|
|
650
|
+
onGraphQLJSValidationError(schema, error) {
|
|
651
|
+
var _a;
|
|
652
|
+
const matcher = /^Unknown directive "@(?<directive>[_A-Za-z][_0-9A-Za-z]*)"\.$/.exec(error.message);
|
|
653
|
+
const name = (_a = matcher === null || matcher === void 0 ? void 0 : matcher.groups) === null || _a === void 0 ? void 0 : _a.directive;
|
|
654
|
+
if (!name) {
|
|
655
|
+
return error;
|
|
656
|
+
}
|
|
657
|
+
const allDefinedDirectiveNames = schema.allDirectives().map((d) => d.name);
|
|
658
|
+
const suggestions = (0, suggestions_1.suggestionList)(name, allDefinedDirectiveNames);
|
|
659
|
+
if (suggestions.length === 0) {
|
|
660
|
+
return this.onUnknownDirectiveValidationError(schema, name, error);
|
|
661
|
+
}
|
|
662
|
+
else {
|
|
663
|
+
return (0, error_2.withModifiedErrorMessage)(error, `${error.message}${(0, suggestions_1.didYouMean)(suggestions.map((s) => '@' + s))}`);
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
onUnknownDirectiveValidationError(_schema, _unknownDirectiveName, error) {
|
|
667
|
+
return error;
|
|
668
|
+
}
|
|
625
669
|
}
|
|
626
670
|
exports.SchemaBlueprint = SchemaBlueprint;
|
|
627
671
|
exports.defaultSchemaBlueprint = new SchemaBlueprint();
|
|
@@ -635,7 +679,8 @@ class CoreFeature {
|
|
|
635
679
|
}
|
|
636
680
|
isFeatureDefinition(element) {
|
|
637
681
|
return element.name.startsWith(this.nameInSchema + '__')
|
|
638
|
-
|| (element.kind === 'DirectiveDefinition' && element.name === this.nameInSchema)
|
|
682
|
+
|| (element.kind === 'DirectiveDefinition' && element.name === this.nameInSchema)
|
|
683
|
+
|| !!this.imports.find((i) => { var _a; return element.name === ((_a = i.as) !== null && _a !== void 0 ? _a : i.name); });
|
|
639
684
|
}
|
|
640
685
|
directiveNameInSchema(name) {
|
|
641
686
|
var _a, _b;
|
|
@@ -689,7 +734,7 @@ class CoreFeatures {
|
|
|
689
734
|
if (existing) {
|
|
690
735
|
throw error(`Duplicate inclusion of feature ${url.identity}`);
|
|
691
736
|
}
|
|
692
|
-
const imports = (0, coreSpec_1.extractCoreFeatureImports)(typedDirective);
|
|
737
|
+
const imports = (0, coreSpec_1.extractCoreFeatureImports)(url, typedDirective);
|
|
693
738
|
const feature = new CoreFeature(url, (_b = args.as) !== null && _b !== void 0 ? _b : url.name, directive, imports, args.for);
|
|
694
739
|
this.add(feature);
|
|
695
740
|
directive.schema().blueprint.onAddedCoreFeature(directive.schema(), feature);
|
|
@@ -730,24 +775,25 @@ const graphQLBuiltInDirectivesSpecifications = [
|
|
|
730
775
|
(0, directiveAndTypeSpecification_1.createDirectiveSpecification)({
|
|
731
776
|
name: 'include',
|
|
732
777
|
locations: [graphql_1.DirectiveLocation.FIELD, graphql_1.DirectiveLocation.FRAGMENT_SPREAD, graphql_1.DirectiveLocation.INLINE_FRAGMENT],
|
|
733
|
-
argumentFct: (schema) => [{ name: 'if', type: new NonNullType(schema.booleanType()) }]
|
|
778
|
+
argumentFct: (schema) => ({ args: [{ name: 'if', type: new NonNullType(schema.booleanType()) }], errors: [] })
|
|
734
779
|
}),
|
|
735
780
|
(0, directiveAndTypeSpecification_1.createDirectiveSpecification)({
|
|
736
781
|
name: 'skip',
|
|
737
782
|
locations: [graphql_1.DirectiveLocation.FIELD, graphql_1.DirectiveLocation.FRAGMENT_SPREAD, graphql_1.DirectiveLocation.INLINE_FRAGMENT],
|
|
738
|
-
argumentFct: (schema) => [{ name: 'if', type: new NonNullType(schema.booleanType()) }]
|
|
783
|
+
argumentFct: (schema) => ({ args: [{ name: 'if', type: new NonNullType(schema.booleanType()) }], errors: [] })
|
|
739
784
|
}),
|
|
740
785
|
(0, directiveAndTypeSpecification_1.createDirectiveSpecification)({
|
|
741
786
|
name: 'deprecated',
|
|
742
787
|
locations: [graphql_1.DirectiveLocation.FIELD_DEFINITION, graphql_1.DirectiveLocation.ENUM_VALUE, graphql_1.DirectiveLocation.ARGUMENT_DEFINITION, graphql_1.DirectiveLocation.INPUT_FIELD_DEFINITION],
|
|
743
|
-
argumentFct: (schema) => [{ name: 'reason', type: schema.stringType(), defaultValue: 'No longer supported' }]
|
|
788
|
+
argumentFct: (schema) => ({ args: [{ name: 'reason', type: schema.stringType(), defaultValue: 'No longer supported' }], errors: [] })
|
|
744
789
|
}),
|
|
745
790
|
(0, directiveAndTypeSpecification_1.createDirectiveSpecification)({
|
|
746
791
|
name: 'specifiedBy',
|
|
747
792
|
locations: [graphql_1.DirectiveLocation.SCALAR],
|
|
748
|
-
argumentFct: (schema) => [{ name: 'url', type: new NonNullType(schema.stringType()) }]
|
|
793
|
+
argumentFct: (schema) => ({ args: [{ name: 'url', type: new NonNullType(schema.stringType()) }], errors: [] })
|
|
749
794
|
}),
|
|
750
795
|
];
|
|
796
|
+
const coordinateRegexp = /^@?[_A-Za-z][_0-9A-Za-z]*(\.[_A-Za-z][_0-9A-Za-z]*)?(\([_A-Za-z][_0-9A-Za-z]*:\))?$/;
|
|
751
797
|
class Schema {
|
|
752
798
|
constructor(blueprint = exports.defaultSchemaBlueprint) {
|
|
753
799
|
this.blueprint = blueprint;
|
|
@@ -838,22 +884,38 @@ class Schema {
|
|
|
838
884
|
get schemaDefinition() {
|
|
839
885
|
return this._schemaDefinition;
|
|
840
886
|
}
|
|
841
|
-
types(
|
|
842
|
-
|
|
843
|
-
|
|
887
|
+
types() {
|
|
888
|
+
return this._types.values();
|
|
889
|
+
}
|
|
890
|
+
interfaceTypes() {
|
|
891
|
+
return filterTypesOfKind(this.types(), 'InterfaceType');
|
|
892
|
+
}
|
|
893
|
+
objectTypes() {
|
|
894
|
+
return filterTypesOfKind(this.types(), 'ObjectType');
|
|
844
895
|
}
|
|
845
|
-
|
|
896
|
+
unionTypes() {
|
|
897
|
+
return filterTypesOfKind(this.types(), 'UnionType');
|
|
898
|
+
}
|
|
899
|
+
scalarTypes() {
|
|
900
|
+
return filterTypesOfKind(this.types(), 'ScalarType');
|
|
901
|
+
}
|
|
902
|
+
inputTypes() {
|
|
903
|
+
return filterTypesOfKind(this.types(), 'InputObjectType');
|
|
904
|
+
}
|
|
905
|
+
enumTypes() {
|
|
906
|
+
return filterTypesOfKind(this.types(), 'EnumType');
|
|
907
|
+
}
|
|
908
|
+
builtInTypes(includeShadowed = false) {
|
|
846
909
|
const allBuiltIns = this._builtInTypes.values();
|
|
847
|
-
const forKind = (kind ? allBuiltIns.filter(t => t.kind === kind) : allBuiltIns);
|
|
848
910
|
return includeShadowed
|
|
849
|
-
?
|
|
850
|
-
:
|
|
911
|
+
? allBuiltIns
|
|
912
|
+
: allBuiltIns.filter(t => !this.isShadowedBuiltInType(t));
|
|
851
913
|
}
|
|
852
914
|
isShadowedBuiltInType(type) {
|
|
853
915
|
return type.isBuiltIn && this._types.has(type.name);
|
|
854
916
|
}
|
|
855
|
-
allTypes(
|
|
856
|
-
return this.builtInTypes(
|
|
917
|
+
allTypes() {
|
|
918
|
+
return this.builtInTypes().concat(this.types());
|
|
857
919
|
}
|
|
858
920
|
type(name) {
|
|
859
921
|
const type = this._types.get(name);
|
|
@@ -985,7 +1047,7 @@ class Schema {
|
|
|
985
1047
|
this.runWithBuiltInModificationAllowed(() => {
|
|
986
1048
|
(0, introspection_1.addIntrospectionFields)(this);
|
|
987
1049
|
});
|
|
988
|
-
let errors = (0, validate_1.validateSDL)(this.toAST(), undefined, this.blueprint.validationRules());
|
|
1050
|
+
let errors = (0, validate_1.validateSDL)(this.toAST(), undefined, this.blueprint.validationRules()).map((e) => this.blueprint.onGraphQLJSValidationError(this, e));
|
|
989
1051
|
errors = errors.concat((0, validate_2.validateSchema)(this));
|
|
990
1052
|
if (errors.length === 0) {
|
|
991
1053
|
this.runWithBuiltInModificationAllowed(() => {
|
|
@@ -1022,6 +1084,49 @@ class Schema {
|
|
|
1022
1084
|
specifiedByDirective(schema) {
|
|
1023
1085
|
return this.getBuiltInDirective(schema, 'specifiedBy');
|
|
1024
1086
|
}
|
|
1087
|
+
elementByCoordinate(coordinate) {
|
|
1088
|
+
if (!coordinate.match(coordinateRegexp)) {
|
|
1089
|
+
throw error(`Invalid argument "${coordinate}: it is not a syntactically valid graphQL coordinate."`);
|
|
1090
|
+
}
|
|
1091
|
+
const argStartIdx = coordinate.indexOf('(');
|
|
1092
|
+
const start = argStartIdx < 0 ? coordinate : coordinate.slice(0, argStartIdx);
|
|
1093
|
+
const argName = argStartIdx < 0 ? undefined : coordinate.slice(argStartIdx + 1, coordinate.length - 2);
|
|
1094
|
+
const splittedStart = start.split('.');
|
|
1095
|
+
const typeOrDirectiveName = splittedStart[0];
|
|
1096
|
+
const fieldOrEnumName = splittedStart[1];
|
|
1097
|
+
const isDirective = typeOrDirectiveName.startsWith('@');
|
|
1098
|
+
if (isDirective) {
|
|
1099
|
+
if (fieldOrEnumName) {
|
|
1100
|
+
throw error(`Invalid argument "${coordinate}: it is not a syntactically valid graphQL coordinate."`);
|
|
1101
|
+
}
|
|
1102
|
+
const directive = this.directive(typeOrDirectiveName.slice(1));
|
|
1103
|
+
return argName ? directive === null || directive === void 0 ? void 0 : directive.argument(argName) : directive;
|
|
1104
|
+
}
|
|
1105
|
+
else {
|
|
1106
|
+
const type = this.type(typeOrDirectiveName);
|
|
1107
|
+
if (!type || !fieldOrEnumName) {
|
|
1108
|
+
return type;
|
|
1109
|
+
}
|
|
1110
|
+
switch (type.kind) {
|
|
1111
|
+
case 'ObjectType':
|
|
1112
|
+
case 'InterfaceType':
|
|
1113
|
+
const field = type.field(fieldOrEnumName);
|
|
1114
|
+
return argName ? field === null || field === void 0 ? void 0 : field.argument(argName) : field;
|
|
1115
|
+
case 'InputObjectType':
|
|
1116
|
+
if (argName) {
|
|
1117
|
+
throw error(`Invalid argument "${coordinate}: it is not a syntactically valid graphQL coordinate."`);
|
|
1118
|
+
}
|
|
1119
|
+
return type.field(fieldOrEnumName);
|
|
1120
|
+
case 'EnumType':
|
|
1121
|
+
if (argName) {
|
|
1122
|
+
throw error(`Invalid argument "${coordinate}: it is not a syntactically valid graphQL coordinate."`);
|
|
1123
|
+
}
|
|
1124
|
+
return type.value(fieldOrEnumName);
|
|
1125
|
+
default:
|
|
1126
|
+
throw error(`Invalid argument "${coordinate}: it is not a syntactically valid graphQL coordinate."`);
|
|
1127
|
+
}
|
|
1128
|
+
}
|
|
1129
|
+
}
|
|
1025
1130
|
}
|
|
1026
1131
|
exports.Schema = Schema;
|
|
1027
1132
|
class RootType extends BaseExtensionMember {
|
|
@@ -1048,9 +1153,9 @@ class SchemaDefinition extends SchemaElement {
|
|
|
1048
1153
|
roots() {
|
|
1049
1154
|
return this._roots.values();
|
|
1050
1155
|
}
|
|
1051
|
-
applyDirective(nameOrDefOrDirective, args) {
|
|
1156
|
+
applyDirective(nameOrDefOrDirective, args, asFirstDirective = false) {
|
|
1052
1157
|
var _a, _b;
|
|
1053
|
-
const applied = super.applyDirective(nameOrDefOrDirective, args);
|
|
1158
|
+
const applied = super.applyDirective(nameOrDefOrDirective, args, asFirstDirective);
|
|
1054
1159
|
const schema = this.schema();
|
|
1055
1160
|
const coreFeatures = schema.coreFeatures;
|
|
1056
1161
|
if ((0, coreSpec_1.isCoreSpecDirectiveApplication)(applied)) {
|
|
@@ -1060,9 +1165,12 @@ class SchemaDefinition extends SchemaElement {
|
|
|
1060
1165
|
const schemaDirective = applied;
|
|
1061
1166
|
const args = schemaDirective.arguments();
|
|
1062
1167
|
const url = coreSpec_1.FeatureUrl.parse(((_a = args.url) !== null && _a !== void 0 ? _a : args.feature));
|
|
1063
|
-
const imports = (0, coreSpec_1.extractCoreFeatureImports)(schemaDirective);
|
|
1168
|
+
const imports = (0, coreSpec_1.extractCoreFeatureImports)(url, schemaDirective);
|
|
1064
1169
|
const core = new CoreFeature(url, (_b = args.as) !== null && _b !== void 0 ? _b : url.name, schemaDirective, imports, args.for);
|
|
1065
1170
|
Schema.prototype['markAsCoreSchema'].call(schema, core);
|
|
1171
|
+
this.appliedDirectives
|
|
1172
|
+
.filter((a) => a !== applied)
|
|
1173
|
+
.forEach((other) => CoreFeatures.prototype['maybeAddFeature'].call(schema.coreFeatures, other));
|
|
1066
1174
|
}
|
|
1067
1175
|
else if (coreFeatures) {
|
|
1068
1176
|
CoreFeatures.prototype['maybeAddFeature'].call(coreFeatures, applied);
|
|
@@ -1483,7 +1591,7 @@ class EnumType extends BaseNamedType {
|
|
|
1483
1591
|
this._values = [];
|
|
1484
1592
|
}
|
|
1485
1593
|
get values() {
|
|
1486
|
-
return this._values;
|
|
1594
|
+
return Array.from(this._values);
|
|
1487
1595
|
}
|
|
1488
1596
|
value(name) {
|
|
1489
1597
|
return this._values.find(v => v.name === name);
|
|
@@ -1787,6 +1895,7 @@ class InputFieldDefinition extends NamedSchemaElementWithType {
|
|
|
1787
1895
|
return [];
|
|
1788
1896
|
}
|
|
1789
1897
|
this.onModification();
|
|
1898
|
+
this.removeAppliedDirectives();
|
|
1790
1899
|
InputObjectType.prototype['removeFieldInternal'].call(this._parent, this);
|
|
1791
1900
|
this._parent = undefined;
|
|
1792
1901
|
this.type = undefined;
|
|
@@ -1825,6 +1934,7 @@ class ArgumentDefinition extends NamedSchemaElementWithType {
|
|
|
1825
1934
|
return [];
|
|
1826
1935
|
}
|
|
1827
1936
|
this.onModification();
|
|
1937
|
+
this.removeAppliedDirectives();
|
|
1828
1938
|
if (this._parent instanceof FieldDefinition) {
|
|
1829
1939
|
FieldDefinition.prototype['removeArgumentInternal'].call(this._parent, this.name);
|
|
1830
1940
|
}
|
|
@@ -1874,6 +1984,7 @@ class EnumValue extends NamedSchemaElement {
|
|
|
1874
1984
|
return [];
|
|
1875
1985
|
}
|
|
1876
1986
|
this.onModification();
|
|
1987
|
+
this.removeAppliedDirectives();
|
|
1877
1988
|
EnumType.prototype['removeValueInternal'].call(this._parent, this);
|
|
1878
1989
|
this._parent = undefined;
|
|
1879
1990
|
return [];
|
|
@@ -2108,7 +2219,7 @@ class Directive extends Element {
|
|
|
2108
2219
|
this.onModification();
|
|
2109
2220
|
const coreFeatures = this.schema().coreFeatures;
|
|
2110
2221
|
if (coreFeatures && this.name === coreFeatures.coreItself.nameInSchema) {
|
|
2111
|
-
const url = coreSpec_1.FeatureUrl.parse(this._args[
|
|
2222
|
+
const url = coreSpec_1.FeatureUrl.parse(this._args[coreFeatures.coreDefinition.urlArgName()]);
|
|
2112
2223
|
if (url.identity === coreFeatures.coreItself.url.identity) {
|
|
2113
2224
|
Schema.prototype['unmarkAsCoreSchema'].call(this.schema());
|
|
2114
2225
|
for (const d of this.schema().schemaDefinition.appliedDirectivesOf(coreFeatures.coreItself.nameInSchema)) {
|