@apollo/federation-internals 2.0.0-preview.9 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +25 -0
- package/dist/coreSpec.d.ts +1 -1
- package/dist/coreSpec.d.ts.map +1 -1
- package/dist/coreSpec.js +34 -11
- package/dist/coreSpec.js.map +1 -1
- package/dist/definitions.d.ts +20 -8
- package/dist/definitions.d.ts.map +1 -1
- package/dist/definitions.js +97 -58
- package/dist/definitions.js.map +1 -1
- package/dist/directiveAndTypeSpecification.d.ts.map +1 -1
- package/dist/directiveAndTypeSpecification.js +10 -1
- package/dist/directiveAndTypeSpecification.js.map +1 -1
- package/dist/error.d.ts +10 -0
- package/dist/error.d.ts.map +1 -1
- package/dist/error.js +22 -2
- package/dist/error.js.map +1 -1
- package/dist/extractSubgraphsFromSupergraph.js +1 -1
- package/dist/extractSubgraphsFromSupergraph.js.map +1 -1
- package/dist/federation.d.ts +4 -1
- package/dist/federation.d.ts.map +1 -1
- package/dist/federation.js +33 -26
- package/dist/federation.js.map +1 -1
- package/dist/federationSpec.js +1 -1
- package/dist/federationSpec.js.map +1 -1
- package/dist/inaccessibleSpec.d.ts +7 -3
- package/dist/inaccessibleSpec.d.ts.map +1 -1
- package/dist/inaccessibleSpec.js +622 -32
- package/dist/inaccessibleSpec.js.map +1 -1
- package/dist/precompute.d.ts.map +1 -1
- package/dist/precompute.js +2 -2
- package/dist/precompute.js.map +1 -1
- package/dist/schemaUpgrader.d.ts.map +1 -1
- package/dist/schemaUpgrader.js +16 -5
- package/dist/schemaUpgrader.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/validate.js +13 -7
- package/dist/validate.js.map +1 -1
- package/dist/values.d.ts +2 -2
- package/dist/values.d.ts.map +1 -1
- package/dist/values.js +13 -11
- package/dist/values.js.map +1 -1
- package/package.json +3 -3
- package/src/__tests__/coreSpec.test.ts +112 -0
- package/src/__tests__/removeInaccessibleElements.test.ts +2216 -177
- package/src/__tests__/subgraphValidation.test.ts +22 -5
- package/src/__tests__/values.test.ts +315 -3
- package/src/coreSpec.ts +70 -16
- package/src/definitions.ts +201 -83
- package/src/directiveAndTypeSpecification.ts +18 -1
- package/src/error.ts +62 -2
- package/src/extractSubgraphsFromSupergraph.ts +1 -1
- package/src/federation.ts +36 -26
- package/src/federationSpec.ts +2 -2
- package/src/inaccessibleSpec.ts +973 -55
- package/src/precompute.ts +2 -4
- package/src/schemaUpgrader.ts +25 -6
- package/src/supergraphs.ts +1 -0
- package/src/validate.ts +20 -9
- package/src/values.ts +39 -12
- package/tsconfig.test.tsbuildinfo +1 -1
- package/tsconfig.tsbuildinfo +1 -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.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.ErrGraphQLAPISchemaValidationFailed = 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 = exports.RootType = void 0;
|
|
5
5
|
const graphql_1 = require("graphql");
|
|
6
6
|
const coreSpec_1 = require("./coreSpec");
|
|
7
7
|
const utils_1 = require("./utils");
|
|
@@ -21,13 +21,19 @@ const error_2 = require("./error");
|
|
|
21
21
|
const validationErrorCode = 'GraphQLValidationFailed';
|
|
22
22
|
const DEFAULT_VALIDATION_ERROR_MESSAGE = 'The schema is not a valid GraphQL schema.';
|
|
23
23
|
const ErrGraphQLValidationFailed = (causes, message = DEFAULT_VALIDATION_ERROR_MESSAGE) => (0, core_schema_1.err)(validationErrorCode, {
|
|
24
|
-
message,
|
|
24
|
+
message: message + '. Caused by:\n' + causes.map((c) => c.toString()).join('\n\n'),
|
|
25
25
|
causes
|
|
26
26
|
});
|
|
27
27
|
exports.ErrGraphQLValidationFailed = ErrGraphQLValidationFailed;
|
|
28
|
+
const apiSchemaValidationErrorCode = 'GraphQLAPISchemaValidationFailed';
|
|
29
|
+
const ErrGraphQLAPISchemaValidationFailed = (causes) => (0, core_schema_1.err)(apiSchemaValidationErrorCode, {
|
|
30
|
+
message: 'The supergraph schema failed to produce a valid API schema',
|
|
31
|
+
causes
|
|
32
|
+
});
|
|
33
|
+
exports.ErrGraphQLAPISchemaValidationFailed = ErrGraphQLAPISchemaValidationFailed;
|
|
28
34
|
function errorCauses(e) {
|
|
29
35
|
if (e instanceof error_1.GraphQLErrorExt) {
|
|
30
|
-
if (e.code === validationErrorCode) {
|
|
36
|
+
if (e.code === validationErrorCode || e.code === apiSchemaValidationErrorCode) {
|
|
31
37
|
return (e.causes);
|
|
32
38
|
}
|
|
33
39
|
return [e];
|
|
@@ -159,6 +165,19 @@ function isInputType(type) {
|
|
|
159
165
|
}
|
|
160
166
|
}
|
|
161
167
|
exports.isInputType = isInputType;
|
|
168
|
+
function isTypeOfKind(type, kind) {
|
|
169
|
+
return type.kind === kind;
|
|
170
|
+
}
|
|
171
|
+
exports.isTypeOfKind = isTypeOfKind;
|
|
172
|
+
function filterTypesOfKind(types, kind) {
|
|
173
|
+
return types.reduce((acc, type) => {
|
|
174
|
+
if (isTypeOfKind(type, kind)) {
|
|
175
|
+
acc.push(type);
|
|
176
|
+
}
|
|
177
|
+
return acc;
|
|
178
|
+
}, []);
|
|
179
|
+
}
|
|
180
|
+
exports.filterTypesOfKind = filterTypesOfKind;
|
|
162
181
|
function baseType(type) {
|
|
163
182
|
return isWrapperType(type) ? type.baseType() : type;
|
|
164
183
|
}
|
|
@@ -374,36 +393,26 @@ class SchemaElement extends Element {
|
|
|
374
393
|
? this.appliedDirectivesOf(nameOrDefinition)
|
|
375
394
|
: this.appliedDirectivesOf(nameOrDefinition)).length !== 0;
|
|
376
395
|
}
|
|
377
|
-
applyDirective(
|
|
396
|
+
applyDirective(nameOrDef, args, asFirstDirective = false) {
|
|
378
397
|
var _a;
|
|
379
|
-
let
|
|
380
|
-
if (
|
|
381
|
-
this.checkUpdate(
|
|
382
|
-
|
|
383
|
-
if (
|
|
384
|
-
|
|
398
|
+
let name;
|
|
399
|
+
if (typeof nameOrDef === 'string') {
|
|
400
|
+
this.checkUpdate();
|
|
401
|
+
const def = (_a = this.schema().directive(nameOrDef)) !== null && _a !== void 0 ? _a : this.schema().blueprint.onMissingDirectiveDefinition(this.schema(), nameOrDef, args);
|
|
402
|
+
if (!def) {
|
|
403
|
+
throw this.schema().blueprint.onGraphQLJSValidationError(this.schema(), new graphql_1.GraphQLError(`Unknown directive "@${nameOrDef}".`));
|
|
404
|
+
}
|
|
405
|
+
if (Array.isArray(def)) {
|
|
406
|
+
throw (0, exports.ErrGraphQLValidationFailed)(def);
|
|
385
407
|
}
|
|
408
|
+
name = nameOrDef;
|
|
386
409
|
}
|
|
387
410
|
else {
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
this.checkUpdate();
|
|
391
|
-
const def = (_a = this.schema().directive(nameOrDefOrDirective)) !== null && _a !== void 0 ? _a : this.schema().blueprint.onMissingDirectiveDefinition(this.schema(), nameOrDefOrDirective, args);
|
|
392
|
-
if (!def) {
|
|
393
|
-
throw this.schema().blueprint.onGraphQLJSValidationError(this.schema(), new graphql_1.GraphQLError(`Unknown directive "@${nameOrDefOrDirective}".`));
|
|
394
|
-
}
|
|
395
|
-
if (Array.isArray(def)) {
|
|
396
|
-
throw (0, exports.ErrGraphQLValidationFailed)(def);
|
|
397
|
-
}
|
|
398
|
-
name = nameOrDefOrDirective;
|
|
399
|
-
}
|
|
400
|
-
else {
|
|
401
|
-
this.checkUpdate(nameOrDefOrDirective);
|
|
402
|
-
name = nameOrDefOrDirective.name;
|
|
403
|
-
}
|
|
404
|
-
toAdd = new Directive(name, args !== null && args !== void 0 ? args : Object.create(null));
|
|
405
|
-
Element.prototype['setParent'].call(toAdd, this);
|
|
411
|
+
this.checkUpdate(nameOrDef);
|
|
412
|
+
name = nameOrDef.name;
|
|
406
413
|
}
|
|
414
|
+
const toAdd = new Directive(name, args !== null && args !== void 0 ? args : Object.create(null));
|
|
415
|
+
Element.prototype['setParent'].call(toAdd, this);
|
|
407
416
|
if (asFirstDirective) {
|
|
408
417
|
this._appliedDirectives.unshift(toAdd);
|
|
409
418
|
}
|
|
@@ -537,15 +546,15 @@ class BaseNamedType extends NamedSchemaElement {
|
|
|
537
546
|
}
|
|
538
547
|
this.checkRemoval();
|
|
539
548
|
this.onModification();
|
|
540
|
-
this.removeInnerElements();
|
|
541
|
-
Schema.prototype['removeTypeInternal'].call(this._parent, this);
|
|
542
|
-
this.removeAppliedDirectives();
|
|
543
549
|
this.sourceAST = undefined;
|
|
550
|
+
this.removeAppliedDirectives();
|
|
551
|
+
this.removeInnerElements();
|
|
544
552
|
const toReturn = (0, utils_1.setValues)(this._referencers).map(r => {
|
|
545
553
|
SchemaElement.prototype['removeTypeReferenceInternal'].call(r, this);
|
|
546
554
|
return r;
|
|
547
555
|
});
|
|
548
556
|
this._referencers.clear();
|
|
557
|
+
Schema.prototype['removeTypeInternal'].call(this._parent, this);
|
|
549
558
|
this._parent = undefined;
|
|
550
559
|
return toReturn;
|
|
551
560
|
}
|
|
@@ -665,9 +674,12 @@ class CoreFeature {
|
|
|
665
674
|
this.purpose = purpose;
|
|
666
675
|
}
|
|
667
676
|
isFeatureDefinition(element) {
|
|
677
|
+
const importName = element.kind === 'DirectiveDefinition'
|
|
678
|
+
? '@' + element.name
|
|
679
|
+
: element.name;
|
|
668
680
|
return element.name.startsWith(this.nameInSchema + '__')
|
|
669
681
|
|| (element.kind === 'DirectiveDefinition' && element.name === this.nameInSchema)
|
|
670
|
-
|| !!this.imports.find((i) => { var _a; return
|
|
682
|
+
|| !!this.imports.find((i) => { var _a; return importName === ((_a = i.as) !== null && _a !== void 0 ? _a : i.name); });
|
|
671
683
|
}
|
|
672
684
|
directiveNameInSchema(name) {
|
|
673
685
|
var _a, _b;
|
|
@@ -849,12 +861,7 @@ class Schema {
|
|
|
849
861
|
this.validate();
|
|
850
862
|
const apiSchema = this.clone();
|
|
851
863
|
(0, inaccessibleSpec_1.removeInaccessibleElements)(apiSchema);
|
|
852
|
-
|
|
853
|
-
if (coreFeatures) {
|
|
854
|
-
for (const coreFeature of coreFeatures.allFeatures()) {
|
|
855
|
-
(0, coreSpec_1.removeFeatureElements)(apiSchema, coreFeature);
|
|
856
|
-
}
|
|
857
|
-
}
|
|
864
|
+
(0, coreSpec_1.removeAllCoreFeatures)(apiSchema);
|
|
858
865
|
(0, utils_1.assert)(!apiSchema.isCoreSchema(), "The API schema shouldn't be a core schema");
|
|
859
866
|
apiSchema.validate();
|
|
860
867
|
this.apiSchema = apiSchema;
|
|
@@ -871,22 +878,38 @@ class Schema {
|
|
|
871
878
|
get schemaDefinition() {
|
|
872
879
|
return this._schemaDefinition;
|
|
873
880
|
}
|
|
874
|
-
types(
|
|
875
|
-
|
|
876
|
-
|
|
881
|
+
types() {
|
|
882
|
+
return this._types.values();
|
|
883
|
+
}
|
|
884
|
+
interfaceTypes() {
|
|
885
|
+
return filterTypesOfKind(this.types(), 'InterfaceType');
|
|
886
|
+
}
|
|
887
|
+
objectTypes() {
|
|
888
|
+
return filterTypesOfKind(this.types(), 'ObjectType');
|
|
889
|
+
}
|
|
890
|
+
unionTypes() {
|
|
891
|
+
return filterTypesOfKind(this.types(), 'UnionType');
|
|
892
|
+
}
|
|
893
|
+
scalarTypes() {
|
|
894
|
+
return filterTypesOfKind(this.types(), 'ScalarType');
|
|
877
895
|
}
|
|
878
|
-
|
|
896
|
+
inputTypes() {
|
|
897
|
+
return filterTypesOfKind(this.types(), 'InputObjectType');
|
|
898
|
+
}
|
|
899
|
+
enumTypes() {
|
|
900
|
+
return filterTypesOfKind(this.types(), 'EnumType');
|
|
901
|
+
}
|
|
902
|
+
builtInTypes(includeShadowed = false) {
|
|
879
903
|
const allBuiltIns = this._builtInTypes.values();
|
|
880
|
-
const forKind = (kind ? allBuiltIns.filter(t => t.kind === kind) : allBuiltIns);
|
|
881
904
|
return includeShadowed
|
|
882
|
-
?
|
|
883
|
-
:
|
|
905
|
+
? allBuiltIns
|
|
906
|
+
: allBuiltIns.filter(t => !this.isShadowedBuiltInType(t));
|
|
884
907
|
}
|
|
885
908
|
isShadowedBuiltInType(type) {
|
|
886
909
|
return type.isBuiltIn && this._types.has(type.name);
|
|
887
910
|
}
|
|
888
|
-
allTypes(
|
|
889
|
-
return this.builtInTypes(
|
|
911
|
+
allTypes() {
|
|
912
|
+
return this.builtInTypes().concat(this.types());
|
|
890
913
|
}
|
|
891
914
|
type(name) {
|
|
892
915
|
const type = this._types.get(name);
|
|
@@ -1124,9 +1147,9 @@ class SchemaDefinition extends SchemaElement {
|
|
|
1124
1147
|
roots() {
|
|
1125
1148
|
return this._roots.values();
|
|
1126
1149
|
}
|
|
1127
|
-
applyDirective(
|
|
1150
|
+
applyDirective(nameOrDef, args, asFirstDirective = false) {
|
|
1128
1151
|
var _a, _b;
|
|
1129
|
-
const applied = super.applyDirective(
|
|
1152
|
+
const applied = super.applyDirective(nameOrDef, args, asFirstDirective);
|
|
1130
1153
|
const schema = this.schema();
|
|
1131
1154
|
const coreFeatures = schema.coreFeatures;
|
|
1132
1155
|
if ((0, coreSpec_1.isCoreSpecDirectiveApplication)(applied)) {
|
|
@@ -1562,7 +1585,7 @@ class EnumType extends BaseNamedType {
|
|
|
1562
1585
|
this._values = [];
|
|
1563
1586
|
}
|
|
1564
1587
|
get values() {
|
|
1565
|
-
return this._values;
|
|
1588
|
+
return Array.from(this._values);
|
|
1566
1589
|
}
|
|
1567
1590
|
value(name) {
|
|
1568
1591
|
return this._values.find(v => v.name === name);
|
|
@@ -1805,15 +1828,17 @@ class FieldDefinition extends NamedSchemaElementWithType {
|
|
|
1805
1828
|
if (!this._parent) {
|
|
1806
1829
|
return [];
|
|
1807
1830
|
}
|
|
1831
|
+
this.checkRemoval();
|
|
1808
1832
|
this.onModification();
|
|
1809
|
-
this.
|
|
1833
|
+
this.sourceAST = undefined;
|
|
1810
1834
|
this.type = undefined;
|
|
1811
|
-
this.
|
|
1835
|
+
this.removeAppliedDirectives();
|
|
1812
1836
|
for (const arg of this.arguments()) {
|
|
1813
1837
|
arg.remove();
|
|
1814
1838
|
}
|
|
1815
1839
|
FieldBasedType.prototype['removeFieldInternal'].call(this._parent, this);
|
|
1816
1840
|
this._parent = undefined;
|
|
1841
|
+
this._extension = undefined;
|
|
1817
1842
|
return [];
|
|
1818
1843
|
}
|
|
1819
1844
|
removeRecursive() {
|
|
@@ -1865,10 +1890,15 @@ class InputFieldDefinition extends NamedSchemaElementWithType {
|
|
|
1865
1890
|
if (!this._parent) {
|
|
1866
1891
|
return [];
|
|
1867
1892
|
}
|
|
1893
|
+
this.checkRemoval();
|
|
1868
1894
|
this.onModification();
|
|
1895
|
+
this.sourceAST = undefined;
|
|
1896
|
+
this.type = undefined;
|
|
1897
|
+
this.defaultValue = undefined;
|
|
1898
|
+
this.removeAppliedDirectives();
|
|
1869
1899
|
InputObjectType.prototype['removeFieldInternal'].call(this._parent, this);
|
|
1870
1900
|
this._parent = undefined;
|
|
1871
|
-
this.
|
|
1901
|
+
this._extension = undefined;
|
|
1872
1902
|
return [];
|
|
1873
1903
|
}
|
|
1874
1904
|
removeRecursive() {
|
|
@@ -1903,7 +1933,12 @@ class ArgumentDefinition extends NamedSchemaElementWithType {
|
|
|
1903
1933
|
if (!this._parent) {
|
|
1904
1934
|
return [];
|
|
1905
1935
|
}
|
|
1936
|
+
this.checkRemoval();
|
|
1906
1937
|
this.onModification();
|
|
1938
|
+
this.sourceAST = undefined;
|
|
1939
|
+
this.type = undefined;
|
|
1940
|
+
this.defaultValue = undefined;
|
|
1941
|
+
this.removeAppliedDirectives();
|
|
1907
1942
|
if (this._parent instanceof FieldDefinition) {
|
|
1908
1943
|
FieldDefinition.prototype['removeArgumentInternal'].call(this._parent, this.name);
|
|
1909
1944
|
}
|
|
@@ -1911,8 +1946,6 @@ class ArgumentDefinition extends NamedSchemaElementWithType {
|
|
|
1911
1946
|
DirectiveDefinition.prototype['removeArgumentInternal'].call(this._parent, this.name);
|
|
1912
1947
|
}
|
|
1913
1948
|
this._parent = undefined;
|
|
1914
|
-
this.type = undefined;
|
|
1915
|
-
this.defaultValue = undefined;
|
|
1916
1949
|
return [];
|
|
1917
1950
|
}
|
|
1918
1951
|
toString() {
|
|
@@ -1952,9 +1985,13 @@ class EnumValue extends NamedSchemaElement {
|
|
|
1952
1985
|
if (!this._parent) {
|
|
1953
1986
|
return [];
|
|
1954
1987
|
}
|
|
1988
|
+
this.checkRemoval();
|
|
1955
1989
|
this.onModification();
|
|
1990
|
+
this.sourceAST = undefined;
|
|
1991
|
+
this.removeAppliedDirectives();
|
|
1956
1992
|
EnumType.prototype['removeValueInternal'].call(this._parent, this);
|
|
1957
1993
|
this._parent = undefined;
|
|
1994
|
+
this._extension = undefined;
|
|
1958
1995
|
return [];
|
|
1959
1996
|
}
|
|
1960
1997
|
removeTypeReference(type) {
|
|
@@ -2062,15 +2099,17 @@ class DirectiveDefinition extends NamedSchemaElement {
|
|
|
2062
2099
|
if (!this._parent) {
|
|
2063
2100
|
return [];
|
|
2064
2101
|
}
|
|
2102
|
+
this.checkRemoval();
|
|
2065
2103
|
this.onModification();
|
|
2066
|
-
|
|
2067
|
-
this._parent = undefined;
|
|
2104
|
+
this.sourceAST = undefined;
|
|
2068
2105
|
(0, utils_1.assert)(this._appliedDirectives.length === 0, "Directive definition should not have directive applied to it");
|
|
2069
2106
|
for (const arg of this.arguments()) {
|
|
2070
2107
|
arg.remove();
|
|
2071
2108
|
}
|
|
2072
2109
|
const toReturn = (0, utils_1.setValues)(this._referencers);
|
|
2073
2110
|
this._referencers.clear();
|
|
2111
|
+
Schema.prototype['removeDirectiveInternal'].call(this._parent, this);
|
|
2112
|
+
this._parent = undefined;
|
|
2074
2113
|
return toReturn;
|
|
2075
2114
|
}
|
|
2076
2115
|
removeRecursive() {
|