@apollo/federation-internals 2.0.0-alpha.1 → 2.0.0-alpha.2
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 +13 -0
- package/dist/buildSchema.js.map +1 -1
- package/dist/coreSpec.d.ts +1 -1
- package/dist/coreSpec.d.ts.map +1 -1
- package/dist/coreSpec.js +2 -0
- package/dist/coreSpec.js.map +1 -1
- package/dist/debug.js +5 -5
- package/dist/debug.js.map +1 -1
- package/dist/definitions.d.ts +10 -6
- package/dist/definitions.d.ts.map +1 -1
- package/dist/definitions.js +52 -45
- package/dist/definitions.js.map +1 -1
- package/dist/extractSubgraphsFromSupergraph.js +20 -5
- package/dist/extractSubgraphsFromSupergraph.js.map +1 -1
- package/dist/federation.d.ts +3 -5
- package/dist/federation.d.ts.map +1 -1
- package/dist/federation.js +31 -24
- package/dist/federation.js.map +1 -1
- package/dist/inaccessibleSpec.d.ts +1 -1
- package/dist/inaccessibleSpec.d.ts.map +1 -1
- package/dist/inaccessibleSpec.js +5 -5
- package/dist/inaccessibleSpec.js.map +1 -1
- package/dist/joinSpec.d.ts.map +1 -1
- package/dist/joinSpec.js.map +1 -1
- package/dist/operations.js +1 -1
- package/dist/operations.js.map +1 -1
- package/dist/print.d.ts +1 -1
- package/dist/print.d.ts.map +1 -1
- package/dist/print.js +4 -4
- package/dist/print.js.map +1 -1
- package/dist/suggestions.js +1 -1
- package/dist/suggestions.js.map +1 -1
- package/dist/tagSpec.js.map +1 -1
- package/dist/utils.d.ts +15 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +64 -1
- package/dist/utils.js.map +1 -1
- package/dist/validate.js.map +1 -1
- package/dist/values.js +2 -3
- package/dist/values.js.map +1 -1
- package/package.json +5 -6
- package/src/__tests__/definitions.test.ts +3 -3
- package/src/__tests__/matchers/toMatchString.ts +2 -2
- package/src/__tests__/removeInaccessibleElements.test.ts +8 -8
- package/src/__tests__/utils.test.ts +92 -0
- package/src/buildSchema.ts +5 -5
- package/src/coreSpec.ts +12 -10
- package/src/debug.ts +6 -6
- package/src/definitions.ts +98 -75
- package/src/extractSubgraphsFromSupergraph.ts +31 -15
- package/src/federation.ts +56 -50
- package/src/inaccessibleSpec.ts +7 -7
- package/src/joinSpec.ts +0 -3
- package/src/operations.ts +20 -20
- package/src/print.ts +8 -8
- package/src/suggestions.ts +1 -1
- package/src/tagSpec.ts +1 -1
- package/src/types.ts +1 -1
- package/src/utils.ts +82 -0
- package/src/validate.ts +4 -4
- package/src/values.ts +4 -4
- package/tsconfig.test.tsbuildinfo +1 -1
- package/tsconfig.tsbuildinfo +1 -1
package/dist/definitions.js
CHANGED
|
@@ -88,28 +88,23 @@ function isCustomScalarType(type) {
|
|
|
88
88
|
}
|
|
89
89
|
exports.isCustomScalarType = isCustomScalarType;
|
|
90
90
|
function isIntType(type) {
|
|
91
|
-
|
|
92
|
-
return type === ((_a = type.schema()) === null || _a === void 0 ? void 0 : _a.intType());
|
|
91
|
+
return type === type.schema().intType();
|
|
93
92
|
}
|
|
94
93
|
exports.isIntType = isIntType;
|
|
95
94
|
function isStringType(type) {
|
|
96
|
-
|
|
97
|
-
return type === ((_a = type.schema()) === null || _a === void 0 ? void 0 : _a.stringType());
|
|
95
|
+
return type === type.schema().stringType();
|
|
98
96
|
}
|
|
99
97
|
exports.isStringType = isStringType;
|
|
100
98
|
function isFloatType(type) {
|
|
101
|
-
|
|
102
|
-
return type === ((_a = type.schema()) === null || _a === void 0 ? void 0 : _a.floatType());
|
|
99
|
+
return type === type.schema().floatType();
|
|
103
100
|
}
|
|
104
101
|
exports.isFloatType = isFloatType;
|
|
105
102
|
function isBooleanType(type) {
|
|
106
|
-
|
|
107
|
-
return type === ((_a = type.schema()) === null || _a === void 0 ? void 0 : _a.booleanType());
|
|
103
|
+
return type === type.schema().booleanType();
|
|
108
104
|
}
|
|
109
105
|
exports.isBooleanType = isBooleanType;
|
|
110
106
|
function isIDType(type) {
|
|
111
|
-
|
|
112
|
-
return type === ((_a = type.schema()) === null || _a === void 0 ? void 0 : _a.idType());
|
|
107
|
+
return type === type.schema().idType();
|
|
113
108
|
}
|
|
114
109
|
exports.isIDType = isIDType;
|
|
115
110
|
function isObjectType(type) {
|
|
@@ -259,7 +254,7 @@ class DirectiveTargetElement {
|
|
|
259
254
|
applyDirective(defOrDirective, args) {
|
|
260
255
|
let toAdd;
|
|
261
256
|
if (defOrDirective instanceof Directive) {
|
|
262
|
-
if (defOrDirective.schema()
|
|
257
|
+
if (defOrDirective.schema() != this.schema()) {
|
|
263
258
|
throw new Error(`Cannot add directive ${defOrDirective} to ${this} as it is attached to another schema`);
|
|
264
259
|
}
|
|
265
260
|
toAdd = defOrDirective;
|
|
@@ -305,19 +300,32 @@ function sourceASTs(...elts) {
|
|
|
305
300
|
exports.sourceASTs = sourceASTs;
|
|
306
301
|
class Element {
|
|
307
302
|
schema() {
|
|
303
|
+
const schema = this.schemaInternal();
|
|
304
|
+
(0, utils_1.assert)(schema, 'requested schema does not exist. Probably because the element is unattached');
|
|
305
|
+
return schema;
|
|
306
|
+
}
|
|
307
|
+
schemaInternal() {
|
|
308
308
|
if (!this._parent) {
|
|
309
309
|
return undefined;
|
|
310
310
|
}
|
|
311
311
|
else if (this._parent instanceof Schema) {
|
|
312
312
|
return this._parent;
|
|
313
313
|
}
|
|
314
|
-
else {
|
|
314
|
+
else if (this._parent instanceof SchemaElement) {
|
|
315
|
+
return this._parent.schemaInternal();
|
|
316
|
+
}
|
|
317
|
+
else if (this._parent instanceof DirectiveTargetElement) {
|
|
315
318
|
return this._parent.schema();
|
|
316
319
|
}
|
|
320
|
+
(0, utils_1.assert)(false, 'unreachable code. parent is of unknown type');
|
|
317
321
|
}
|
|
318
322
|
get parent() {
|
|
323
|
+
(0, utils_1.assert)(this._parent, 'trying to access non-existent parent');
|
|
319
324
|
return this._parent;
|
|
320
325
|
}
|
|
326
|
+
isAttached() {
|
|
327
|
+
return !!this._parent;
|
|
328
|
+
}
|
|
321
329
|
setParent(parent) {
|
|
322
330
|
(0, utils_1.assert)(!this._parent, "Cannot set parent of an already attached element");
|
|
323
331
|
this._parent = parent;
|
|
@@ -326,7 +334,7 @@ class Element {
|
|
|
326
334
|
onAttached() {
|
|
327
335
|
}
|
|
328
336
|
checkUpdate() {
|
|
329
|
-
if (!this.
|
|
337
|
+
if (!this.isAttached()) {
|
|
330
338
|
throw error(`Cannot modify detached element ${this}`);
|
|
331
339
|
}
|
|
332
340
|
}
|
|
@@ -373,7 +381,7 @@ class SchemaElement extends Element {
|
|
|
373
381
|
this.checkUpdate();
|
|
374
382
|
const def = this.schema().directive(nameOrDefOrDirective);
|
|
375
383
|
if (!def) {
|
|
376
|
-
throw new graphql_1.GraphQLError(`Cannot apply
|
|
384
|
+
throw new graphql_1.GraphQLError(`Cannot apply unknown directive "@${nameOrDefOrDirective}"`);
|
|
377
385
|
}
|
|
378
386
|
name = nameOrDefOrDirective;
|
|
379
387
|
}
|
|
@@ -394,7 +402,7 @@ class SchemaElement extends Element {
|
|
|
394
402
|
applied.forEach(d => d.remove());
|
|
395
403
|
}
|
|
396
404
|
onModification() {
|
|
397
|
-
const schema = this.
|
|
405
|
+
const schema = this.schemaInternal();
|
|
398
406
|
if (schema) {
|
|
399
407
|
Schema.prototype['onModification'].call(schema);
|
|
400
408
|
}
|
|
@@ -421,7 +429,7 @@ class SchemaElement extends Element {
|
|
|
421
429
|
thisElement = thisElement.parent;
|
|
422
430
|
}
|
|
423
431
|
}
|
|
424
|
-
if (addedElement) {
|
|
432
|
+
if (addedElement && addedElement.isAttached()) {
|
|
425
433
|
const thatSchema = addedElement.schema();
|
|
426
434
|
if (thatSchema && thatSchema != this.schema()) {
|
|
427
435
|
throw error(`Cannot add element ${addedElement} to ${this} as it is attached to another schema`);
|
|
@@ -559,7 +567,7 @@ class BaseExtensionMember extends Element {
|
|
|
559
567
|
setOfExtension(extension) {
|
|
560
568
|
var _a;
|
|
561
569
|
this.checkUpdate();
|
|
562
|
-
if (extension && !((_a = this.
|
|
570
|
+
if (extension && !((_a = this._parent) === null || _a === void 0 ? void 0 : _a.extensions().has(extension))) {
|
|
563
571
|
throw error(`Cannot set object as part of the provided extension: it is not an extension of parent ${this.parent}`);
|
|
564
572
|
}
|
|
565
573
|
this._extension = extension;
|
|
@@ -883,8 +891,12 @@ class Schema {
|
|
|
883
891
|
}
|
|
884
892
|
return this.apiSchema;
|
|
885
893
|
}
|
|
886
|
-
toGraphQLJSSchema() {
|
|
887
|
-
|
|
894
|
+
toGraphQLJSSchema(isSubgraph = false) {
|
|
895
|
+
if (!isSubgraph) {
|
|
896
|
+
return (0, graphql_1.buildASTSchema)(this.toAST());
|
|
897
|
+
}
|
|
898
|
+
const ast = (0, graphql_1.parse)((0, print_1.printSchema)(this, { ...toASTPrintOptions, mergeTypesAndExtensions: true }), { noLocation: true });
|
|
899
|
+
return (0, graphql_1.buildASTSchema)(ast);
|
|
888
900
|
}
|
|
889
901
|
get schemaDefinition() {
|
|
890
902
|
return this._schemaDefinition;
|
|
@@ -937,7 +949,7 @@ class Schema {
|
|
|
937
949
|
if (existing && !existing.isBuiltIn) {
|
|
938
950
|
throw error(`Type ${type} already exists in this schema`);
|
|
939
951
|
}
|
|
940
|
-
if (type.
|
|
952
|
+
if (type.isAttached()) {
|
|
941
953
|
if (type.parent == this) {
|
|
942
954
|
return type;
|
|
943
955
|
}
|
|
@@ -1002,7 +1014,7 @@ class Schema {
|
|
|
1002
1014
|
if (existing && !existing.isBuiltIn) {
|
|
1003
1015
|
throw error(`Directive ${definition} already exists in this schema`);
|
|
1004
1016
|
}
|
|
1005
|
-
if (definition.
|
|
1017
|
+
if (definition.isAttached()) {
|
|
1006
1018
|
if (definition.parent == this) {
|
|
1007
1019
|
return definition;
|
|
1008
1020
|
}
|
|
@@ -1237,7 +1249,7 @@ class FieldBasedType extends BaseNamedType {
|
|
|
1237
1249
|
this.checkUpdate();
|
|
1238
1250
|
const maybeItf = this.schema().type(nameOrItfOrItfImpl);
|
|
1239
1251
|
if (!maybeItf) {
|
|
1240
|
-
throw new graphql_1.GraphQLError(`Cannot implement
|
|
1252
|
+
throw new graphql_1.GraphQLError(`Cannot implement unknown type ${nameOrItfOrItfImpl}`);
|
|
1241
1253
|
}
|
|
1242
1254
|
else if (maybeItf.kind != 'InterfaceType') {
|
|
1243
1255
|
throw new graphql_1.GraphQLError(`Cannot implement non-interface type ${nameOrItfOrItfImpl} (of type ${maybeItf.kind})`);
|
|
@@ -1348,17 +1360,11 @@ class ObjectType extends FieldBasedType {
|
|
|
1348
1360
|
}
|
|
1349
1361
|
isRootType() {
|
|
1350
1362
|
const schema = this.schema();
|
|
1351
|
-
if (!schema) {
|
|
1352
|
-
return false;
|
|
1353
|
-
}
|
|
1354
1363
|
return schema.schemaDefinition.roots().some(rt => rt.type == this);
|
|
1355
1364
|
}
|
|
1356
1365
|
isQueryRootType() {
|
|
1357
1366
|
var _a;
|
|
1358
1367
|
const schema = this.schema();
|
|
1359
|
-
if (!schema) {
|
|
1360
|
-
return false;
|
|
1361
|
-
}
|
|
1362
1368
|
return ((_a = schema.schemaDefinition.root('query')) === null || _a === void 0 ? void 0 : _a.type) === this;
|
|
1363
1369
|
}
|
|
1364
1370
|
}
|
|
@@ -1427,7 +1433,7 @@ class UnionType extends BaseNamedType {
|
|
|
1427
1433
|
this.checkUpdate();
|
|
1428
1434
|
const maybeObj = this.schema().type(nameOrTypeOrMember);
|
|
1429
1435
|
if (!maybeObj) {
|
|
1430
|
-
throw new graphql_1.GraphQLError(`Cannot add
|
|
1436
|
+
throw new graphql_1.GraphQLError(`Cannot add unknown type ${nameOrTypeOrMember} as member of union type ${this.name}`);
|
|
1431
1437
|
}
|
|
1432
1438
|
else if (maybeObj.kind != 'ObjectType') {
|
|
1433
1439
|
throw new graphql_1.GraphQLError(`Cannot add non-object type ${nameOrTypeOrMember} (of type ${maybeObj.kind}) as member of union type ${this.name}`);
|
|
@@ -1556,7 +1562,7 @@ class InputObjectType extends BaseNamedType {
|
|
|
1556
1562
|
throw error(`Field ${toAdd.name} already exists on ${this}`);
|
|
1557
1563
|
}
|
|
1558
1564
|
if (type && !isInputType(type)) {
|
|
1559
|
-
throw error(`Invalid
|
|
1565
|
+
throw error(`Invalid output type ${type} for field ${toAdd.name}: input field types should be input types.`);
|
|
1560
1566
|
}
|
|
1561
1567
|
this._fields.set(toAdd.name, toAdd);
|
|
1562
1568
|
this._cachedFieldsArray = undefined;
|
|
@@ -1598,6 +1604,9 @@ class BaseWrapperType {
|
|
|
1598
1604
|
schema() {
|
|
1599
1605
|
return this.baseType().schema();
|
|
1600
1606
|
}
|
|
1607
|
+
isAttached() {
|
|
1608
|
+
return this.baseType().isAttached();
|
|
1609
|
+
}
|
|
1601
1610
|
get ofType() {
|
|
1602
1611
|
return this._type;
|
|
1603
1612
|
}
|
|
@@ -1636,7 +1645,7 @@ class FieldDefinition extends NamedSchemaElementWithType {
|
|
|
1636
1645
|
return this.isBuiltIn;
|
|
1637
1646
|
}
|
|
1638
1647
|
get coordinate() {
|
|
1639
|
-
const parent = this.
|
|
1648
|
+
const parent = this._parent;
|
|
1640
1649
|
return `${parent == undefined ? '<detached>' : parent.coordinate}.${this.name}`;
|
|
1641
1650
|
}
|
|
1642
1651
|
hasArguments() {
|
|
@@ -1670,7 +1679,7 @@ class FieldDefinition extends NamedSchemaElementWithType {
|
|
|
1670
1679
|
return existing;
|
|
1671
1680
|
}
|
|
1672
1681
|
if (type && !isInputType(type)) {
|
|
1673
|
-
throw error(`Invalid
|
|
1682
|
+
throw error(`Invalid output type ${type} for argument ${toAdd.name} of ${this}: arguments should be input types.`);
|
|
1674
1683
|
}
|
|
1675
1684
|
this._args.set(toAdd.name, toAdd);
|
|
1676
1685
|
Element.prototype['setParent'].call(toAdd, this);
|
|
@@ -1686,7 +1695,7 @@ class FieldDefinition extends NamedSchemaElementWithType {
|
|
|
1686
1695
|
setOfExtension(extension) {
|
|
1687
1696
|
var _a;
|
|
1688
1697
|
this.checkUpdate();
|
|
1689
|
-
if (extension && !((_a = this.
|
|
1698
|
+
if (extension && !((_a = this._parent) === null || _a === void 0 ? void 0 : _a.extensions().has(extension))) {
|
|
1690
1699
|
throw error(`Cannot mark field ${this.name} as part of the provided extension: it is not an extension of field parent type ${this.parent}`);
|
|
1691
1700
|
}
|
|
1692
1701
|
this._extension = extension;
|
|
@@ -1736,7 +1745,7 @@ class InputFieldDefinition extends NamedSchemaElementWithType {
|
|
|
1736
1745
|
this.kind = 'InputFieldDefinition';
|
|
1737
1746
|
}
|
|
1738
1747
|
get coordinate() {
|
|
1739
|
-
const parent = this.
|
|
1748
|
+
const parent = this._parent;
|
|
1740
1749
|
return `${parent == undefined ? '<detached>' : parent.coordinate}.${this.name}`;
|
|
1741
1750
|
}
|
|
1742
1751
|
isRequired() {
|
|
@@ -1748,7 +1757,7 @@ class InputFieldDefinition extends NamedSchemaElementWithType {
|
|
|
1748
1757
|
setOfExtension(extension) {
|
|
1749
1758
|
var _a;
|
|
1750
1759
|
this.checkUpdate();
|
|
1751
|
-
if (extension && !((_a = this.
|
|
1760
|
+
if (extension && !((_a = this._parent) === null || _a === void 0 ? void 0 : _a.extensions().has(extension))) {
|
|
1752
1761
|
throw error(`Cannot mark field ${this.name} as part of the provided extension: it is not an extension of field parent type ${this.parent}`);
|
|
1753
1762
|
}
|
|
1754
1763
|
this._extension = extension;
|
|
@@ -1779,7 +1788,7 @@ class ArgumentDefinition extends NamedSchemaElementWithType {
|
|
|
1779
1788
|
this.kind = 'ArgumentDefinition';
|
|
1780
1789
|
}
|
|
1781
1790
|
get coordinate() {
|
|
1782
|
-
const parent = this.
|
|
1791
|
+
const parent = this._parent;
|
|
1783
1792
|
return `${parent == undefined ? '<detached>' : parent.coordinate}(${this.name}:)`;
|
|
1784
1793
|
}
|
|
1785
1794
|
isRequired() {
|
|
@@ -1816,7 +1825,7 @@ class EnumValue extends NamedSchemaElement {
|
|
|
1816
1825
|
this.kind = 'EnumValue';
|
|
1817
1826
|
}
|
|
1818
1827
|
get coordinate() {
|
|
1819
|
-
const parent = this.
|
|
1828
|
+
const parent = this._parent;
|
|
1820
1829
|
return `${parent == undefined ? '<detached>' : parent.coordinate}.${this.name}`;
|
|
1821
1830
|
}
|
|
1822
1831
|
ofExtension() {
|
|
@@ -1825,7 +1834,7 @@ class EnumValue extends NamedSchemaElement {
|
|
|
1825
1834
|
setOfExtension(extension) {
|
|
1826
1835
|
var _a;
|
|
1827
1836
|
this.checkUpdate();
|
|
1828
|
-
if (extension && !((_a = this.
|
|
1837
|
+
if (extension && !((_a = this._parent) === null || _a === void 0 ? void 0 : _a.extensions().has(extension))) {
|
|
1829
1838
|
throw error(`Cannot mark field ${this.name} as part of the provided extension: it is not an extension of field parent type ${this.parent}`);
|
|
1830
1839
|
}
|
|
1831
1840
|
this._extension = extension;
|
|
@@ -1971,12 +1980,11 @@ class Directive extends Element {
|
|
|
1971
1980
|
this._args = _args;
|
|
1972
1981
|
}
|
|
1973
1982
|
schema() {
|
|
1974
|
-
|
|
1975
|
-
return (_a = this._parent) === null || _a === void 0 ? void 0 : _a.schema();
|
|
1983
|
+
return this.parent.schema();
|
|
1976
1984
|
}
|
|
1977
1985
|
get definition() {
|
|
1978
1986
|
const doc = this.schema();
|
|
1979
|
-
return doc
|
|
1987
|
+
return doc.directive(this.name);
|
|
1980
1988
|
}
|
|
1981
1989
|
arguments(includeDefaultValues = false) {
|
|
1982
1990
|
if (!includeDefaultValues) {
|
|
@@ -1998,7 +2006,7 @@ class Directive extends Element {
|
|
|
1998
2006
|
}
|
|
1999
2007
|
}
|
|
2000
2008
|
isAttachedToSchemaElement() {
|
|
2001
|
-
return this.
|
|
2009
|
+
return this.isAttached();
|
|
2002
2010
|
}
|
|
2003
2011
|
setArguments(args) {
|
|
2004
2012
|
this._args = args;
|
|
@@ -2013,7 +2021,7 @@ class Directive extends Element {
|
|
|
2013
2021
|
if (entries.length !== Object.keys(expectedArgs).length) {
|
|
2014
2022
|
return false;
|
|
2015
2023
|
}
|
|
2016
|
-
for (
|
|
2024
|
+
for (const [key, val] of entries) {
|
|
2017
2025
|
if (!(key in expectedArgs)) {
|
|
2018
2026
|
return false;
|
|
2019
2027
|
}
|
|
@@ -2059,12 +2067,11 @@ class Directive extends Element {
|
|
|
2059
2067
|
});
|
|
2060
2068
|
}
|
|
2061
2069
|
remove() {
|
|
2062
|
-
var _a;
|
|
2063
2070
|
if (!this._parent) {
|
|
2064
2071
|
return false;
|
|
2065
2072
|
}
|
|
2066
2073
|
this.onModification();
|
|
2067
|
-
const coreFeatures =
|
|
2074
|
+
const coreFeatures = this.schema().coreFeatures;
|
|
2068
2075
|
if (coreFeatures && this.name === coreFeatures.coreItself.nameInSchema) {
|
|
2069
2076
|
const url = coreSpec_1.FeatureUrl.parse(this._args['feature']);
|
|
2070
2077
|
if (url.identity === coreFeatures.coreItself.url.identity) {
|