@apollo/federation-internals 2.7.8 → 2.8.0-alpha.1
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/directiveAndTypeSpecification.d.ts +13 -1
- package/dist/directiveAndTypeSpecification.d.ts.map +1 -1
- package/dist/directiveAndTypeSpecification.js +2 -2
- package/dist/directiveAndTypeSpecification.js.map +1 -1
- package/dist/error.d.ts +6 -0
- package/dist/error.d.ts.map +1 -1
- package/dist/error.js +12 -0
- package/dist/error.js.map +1 -1
- package/dist/extractSubgraphsFromSupergraph.d.ts +1 -1
- package/dist/extractSubgraphsFromSupergraph.d.ts.map +1 -1
- package/dist/extractSubgraphsFromSupergraph.js +62 -7
- package/dist/extractSubgraphsFromSupergraph.js.map +1 -1
- package/dist/federation.d.ts +15 -2
- package/dist/federation.d.ts.map +1 -1
- package/dist/federation.js +394 -4
- package/dist/federation.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/operations.d.ts +10 -8
- package/dist/operations.d.ts.map +1 -1
- package/dist/operations.js +37 -14
- package/dist/operations.js.map +1 -1
- package/dist/specs/contextSpec.d.ts +20 -0
- package/dist/specs/contextSpec.d.ts.map +1 -0
- package/dist/specs/contextSpec.js +62 -0
- package/dist/specs/contextSpec.js.map +1 -0
- package/dist/specs/federationSpec.d.ts +5 -2
- package/dist/specs/federationSpec.d.ts.map +1 -1
- package/dist/specs/federationSpec.js +9 -1
- package/dist/specs/federationSpec.js.map +1 -1
- package/dist/specs/joinSpec.d.ts +6 -0
- package/dist/specs/joinSpec.d.ts.map +1 -1
- package/dist/specs/joinSpec.js +11 -1
- package/dist/specs/joinSpec.js.map +1 -1
- package/dist/supergraphs.d.ts +4 -0
- package/dist/supergraphs.d.ts.map +1 -1
- package/dist/supergraphs.js +35 -2
- package/dist/supergraphs.js.map +1 -1
- package/dist/utils.d.ts +3 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +39 -1
- package/dist/utils.js.map +1 -1
- package/package.json +1 -1
- package/src/directiveAndTypeSpecification.ts +8 -1
- package/src/error.ts +42 -0
- package/src/extractSubgraphsFromSupergraph.ts +76 -14
- package/src/federation.ts +593 -10
- package/src/index.ts +1 -0
- package/src/operations.ts +48 -21
- package/src/specs/contextSpec.ts +87 -0
- package/src/specs/federationSpec.ts +10 -1
- package/src/specs/joinSpec.ts +27 -3
- package/src/supergraphs.ts +37 -1
- package/src/utils.ts +38 -0
package/dist/federation.d.ts
CHANGED
|
@@ -7,6 +7,13 @@ import { PrintOptions as PrintOptions } from "./print";
|
|
|
7
7
|
import { SourceAPIDirectiveArgs, SourceFieldDirectiveArgs, SourceTypeDirectiveArgs } from "./specs/sourceSpec";
|
|
8
8
|
export declare const FEDERATION_RESERVED_SUBGRAPH_NAME = "_";
|
|
9
9
|
export declare const FEDERATION_UNNAMED_SUBGRAPH_NAME = "<unnamed>";
|
|
10
|
+
export declare function parseContext(input: string): {
|
|
11
|
+
context: undefined;
|
|
12
|
+
selection: undefined;
|
|
13
|
+
} | {
|
|
14
|
+
context: string;
|
|
15
|
+
selection: string;
|
|
16
|
+
};
|
|
10
17
|
export declare function collectUsedFields(metadata: FederationMetadata): Set<FieldDefinition<CompositeType>>;
|
|
11
18
|
export declare class FederationMetadata {
|
|
12
19
|
readonly schema: Schema;
|
|
@@ -71,6 +78,12 @@ export declare class FederationMetadata {
|
|
|
71
78
|
sourceAPIDirective(): Post20FederationDirectiveDefinition<SourceAPIDirectiveArgs>;
|
|
72
79
|
sourceTypeDirective(): Post20FederationDirectiveDefinition<SourceTypeDirectiveArgs>;
|
|
73
80
|
sourceFieldDirective(): Post20FederationDirectiveDefinition<SourceFieldDirectiveArgs>;
|
|
81
|
+
fromContextDirective(): Post20FederationDirectiveDefinition<{
|
|
82
|
+
field: string;
|
|
83
|
+
}>;
|
|
84
|
+
contextDirective(): Post20FederationDirectiveDefinition<{
|
|
85
|
+
name: string;
|
|
86
|
+
}>;
|
|
74
87
|
allFederationDirectives(): DirectiveDefinition[];
|
|
75
88
|
entityType(): UnionType | undefined;
|
|
76
89
|
anyType(): ScalarType;
|
|
@@ -106,8 +119,8 @@ export declare class FederationBlueprint extends SchemaBlueprint {
|
|
|
106
119
|
applyDirectivesAfterParsing(): boolean;
|
|
107
120
|
}
|
|
108
121
|
export declare function setSchemaAsFed2Subgraph(schema: Schema, useLatest?: boolean): void;
|
|
109
|
-
export declare const FEDERATION2_LINK_WITH_FULL_IMPORTS = "@link(url: \"https://specs.apollo.dev/federation/v2.
|
|
110
|
-
export declare const FEDERATION2_LINK_WITH_AUTO_EXPANDED_IMPORTS = "@link(url: \"https://specs.apollo.dev/federation/v2.
|
|
122
|
+
export declare const FEDERATION2_LINK_WITH_FULL_IMPORTS = "@link(url: \"https://specs.apollo.dev/federation/v2.8\", import: [\"@key\", \"@requires\", \"@provides\", \"@external\", \"@tag\", \"@extends\", \"@shareable\", \"@inaccessible\", \"@override\", \"@composeDirective\", \"@interfaceObject\", \"@authenticated\", \"@requiresScopes\", \"@policy\", \"@sourceAPI\", \"@sourceType\", \"@sourceField\", \"@context\", \"@fromContext\"])";
|
|
123
|
+
export declare const FEDERATION2_LINK_WITH_AUTO_EXPANDED_IMPORTS = "@link(url: \"https://specs.apollo.dev/federation/v2.8\", import: [\"@key\", \"@requires\", \"@provides\", \"@external\", \"@tag\", \"@extends\", \"@shareable\", \"@inaccessible\", \"@override\", \"@composeDirective\", \"@interfaceObject\"])";
|
|
111
124
|
export declare const FEDERATION2_LINK_WITH_AUTO_EXPANDED_IMPORTS_UPGRADED = "@link(url: \"https://specs.apollo.dev/federation/v2.4\", import: [\"@key\", \"@requires\", \"@provides\", \"@external\", \"@tag\", \"@extends\", \"@shareable\", \"@inaccessible\", \"@override\", \"@composeDirective\", \"@interfaceObject\"])";
|
|
112
125
|
export declare function asFed2SubgraphDocument(document: DocumentNode, options?: {
|
|
113
126
|
addAsSchemaExtension?: boolean;
|
package/dist/federation.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"federation.d.ts","sourceRoot":"","sources":["../src/federation.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,aAAa,EACb,WAAW,EAEX,SAAS,EACT,mBAAmB,EAGnB,eAAe,EACf,oBAAoB,EACpB,aAAa,EAMb,SAAS,EAET,UAAU,EACV,UAAU,EACV,MAAM,EACN,eAAe,EACf,YAAY,EAEZ,aAAa,EAEb,SAAS,
|
|
1
|
+
{"version":3,"file":"federation.d.ts","sourceRoot":"","sources":["../src/federation.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,aAAa,EACb,WAAW,EAEX,SAAS,EACT,mBAAmB,EAGnB,eAAe,EACf,oBAAoB,EACpB,aAAa,EAMb,SAAS,EAET,UAAU,EACV,UAAU,EACV,MAAM,EACN,eAAe,EACf,YAAY,EAEZ,aAAa,EAEb,SAAS,EAUV,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAC;AAEzE,OAAO,EACL,OAAO,EACP,YAAY,EACZ,YAAY,EAWb,MAAM,SAAS,CAAC;AAGjB,OAAO,EAAiG,YAAY,EAAE,MAAM,cAAc,CAAC;AAE3I,OAAO,EAEL,mBAAmB,EAMpB,MAAM,SAAS,CAAC;AAuBjB,OAAO,EAAuB,YAAY,IAAI,YAAY,EAAe,MAAM,SAAS,CAAC;AAKzF,OAAO,EACL,sBAAsB,EACtB,wBAAwB,EACxB,uBAAuB,EACxB,MAAM,oBAAoB,CAAC;AAqB5B,eAAO,MAAM,iCAAiC,MAAM,CAAC;AAErD,eAAO,MAAM,gCAAgC,cAAc,CAAC;AA+N5D,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM;;;;;;EAYzC;AA8ZD,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,kBAAkB,GAAG,GAAG,CAAC,eAAe,CAAC,aAAa,CAAC,CAA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AO,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC;AAE7D,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,GAAG,eAAe,CAYrF;AAED,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,mBAAmB,GAAG,YAAY,CAoBvH;AAyGD,MAAM,MAAM,6BAA6B,GAAG,SAAS,CAAC,eAAe,CAAC,UAAU,GAAG,aAAa,CAAC,EAAE;IAAC,MAAM,EAAE,GAAG,CAAA;CAAC,CAAC,CAAA;AAajH,wBAAgB,iCAAiC,CAC/C,MAAM,EAAE,MAAM,EACd,UAAU,GAAE,CAAC,KAAK,EAAE,eAAe,CAAC,GAAG,CAAC,EAAE,QAAQ,EAAE,6BAA6B,EAAE,OAAO,CAAC,EAAE,6BAA6B,KAAK,IAAe,QAoB/I"}
|
package/dist/federation.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.removeInactiveProvidesAndRequires = exports.addSubgraphToError = exports.addSubgraphToASTNode = exports.Subgraph = exports.FEDERATION_OPERATION_FIELDS = exports.entitiesFieldName = exports.serviceFieldName = exports.FEDERATION_OPERATION_TYPES = exports.entityTypeSpec = exports.serviceTypeSpec = exports.anyTypeSpec = exports.Subgraphs = exports.subgraphsFromServiceList = exports.collectTargetFields = exports.parseFieldSetArgument = exports.newEmptyFederation2Schema = exports.buildSubgraph = exports.isInterfaceObjectType = exports.isEntityType = exports.isFederationField = exports.isFederationSubgraphSchema = exports.federationMetadata = exports.printSubgraphNames = exports.asFed2SubgraphDocument = exports.FEDERATION2_LINK_WITH_AUTO_EXPANDED_IMPORTS_UPGRADED = exports.FEDERATION2_LINK_WITH_AUTO_EXPANDED_IMPORTS = exports.FEDERATION2_LINK_WITH_FULL_IMPORTS = exports.setSchemaAsFed2Subgraph = exports.FederationBlueprint = exports.hasAppliedDirective = exports.isFederationDirectiveDefinedInSchema = exports.FederationMetadata = exports.collectUsedFields = exports.FEDERATION_UNNAMED_SUBGRAPH_NAME = exports.FEDERATION_RESERVED_SUBGRAPH_NAME = void 0;
|
|
3
|
+
exports.removeInactiveProvidesAndRequires = exports.addSubgraphToError = exports.addSubgraphToASTNode = exports.Subgraph = exports.FEDERATION_OPERATION_FIELDS = exports.entitiesFieldName = exports.serviceFieldName = exports.FEDERATION_OPERATION_TYPES = exports.entityTypeSpec = exports.serviceTypeSpec = exports.anyTypeSpec = exports.Subgraphs = exports.subgraphsFromServiceList = exports.collectTargetFields = exports.parseFieldSetArgument = exports.newEmptyFederation2Schema = exports.buildSubgraph = exports.isInterfaceObjectType = exports.isEntityType = exports.isFederationField = exports.isFederationSubgraphSchema = exports.federationMetadata = exports.printSubgraphNames = exports.asFed2SubgraphDocument = exports.FEDERATION2_LINK_WITH_AUTO_EXPANDED_IMPORTS_UPGRADED = exports.FEDERATION2_LINK_WITH_AUTO_EXPANDED_IMPORTS = exports.FEDERATION2_LINK_WITH_FULL_IMPORTS = exports.setSchemaAsFed2Subgraph = exports.FederationBlueprint = exports.hasAppliedDirective = exports.isFederationDirectiveDefinedInSchema = exports.FederationMetadata = exports.collectUsedFields = exports.parseContext = exports.FEDERATION_UNNAMED_SUBGRAPH_NAME = exports.FEDERATION_RESERVED_SUBGRAPH_NAME = void 0;
|
|
4
4
|
const definitions_1 = require("./definitions");
|
|
5
5
|
const utils_1 = require("./utils");
|
|
6
6
|
const specifiedRules_1 = require("graphql/validation/specifiedRules");
|
|
@@ -160,6 +160,261 @@ function fieldSetTargetDescription(directive) {
|
|
|
160
160
|
const targetKind = directive.parent instanceof definitions_1.FieldDefinition ? "field" : "type";
|
|
161
161
|
return `${targetKind} "${(_a = directive.parent) === null || _a === void 0 ? void 0 : _a.coordinate}"`;
|
|
162
162
|
}
|
|
163
|
+
function parseContext(input) {
|
|
164
|
+
const regex = /^(?:[\n\r\t ,]|#[^\n\r]*(?![^\n\r]))*\$(?:[\n\r\t ,]|#[^\n\r]*(?![^\n\r]))*([A-Za-z_]\w*(?!\w))([\s\S]*)$/;
|
|
165
|
+
const match = input.match(regex);
|
|
166
|
+
if (!match) {
|
|
167
|
+
return { context: undefined, selection: undefined };
|
|
168
|
+
}
|
|
169
|
+
const [, context, selection] = match;
|
|
170
|
+
return {
|
|
171
|
+
context,
|
|
172
|
+
selection,
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
exports.parseContext = parseContext;
|
|
176
|
+
const wrapResolvedType = ({ originalType, resolvedType, }) => {
|
|
177
|
+
const stack = [];
|
|
178
|
+
let unwrappedType = originalType;
|
|
179
|
+
while (unwrappedType.kind === 'NonNullType' || unwrappedType.kind === 'ListType') {
|
|
180
|
+
stack.push(unwrappedType.kind);
|
|
181
|
+
unwrappedType = unwrappedType.ofType;
|
|
182
|
+
}
|
|
183
|
+
let type = resolvedType;
|
|
184
|
+
while (stack.length > 0) {
|
|
185
|
+
const kind = stack.pop();
|
|
186
|
+
if (kind === 'ListType') {
|
|
187
|
+
type = new definitions_1.ListType(type);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
return type;
|
|
191
|
+
};
|
|
192
|
+
const validateFieldValueType = ({ currentType, selectionSet, errorCollector, metadata, fromContextParent, }) => {
|
|
193
|
+
const selections = selectionSet.selections();
|
|
194
|
+
const interfaceObjectDirective = metadata.interfaceObjectDirective();
|
|
195
|
+
if (currentType.kind === 'ObjectType' && isFederationDirectiveDefinedInSchema(interfaceObjectDirective) && (currentType.appliedDirectivesOf(interfaceObjectDirective).length > 0)) {
|
|
196
|
+
errorCollector.push(error_1.ERRORS.CONTEXT_INVALID_SELECTION.err(`Context "is used in "${fromContextParent.coordinate}" but the selection is invalid: One of the types in the selection is an interfaceObject: "${currentType.name}"`, { nodes: (0, definitions_1.sourceASTs)(fromContextParent) }));
|
|
197
|
+
}
|
|
198
|
+
const typesArray = selections.map((selection) => {
|
|
199
|
+
if (selection.kind !== 'FieldSelection') {
|
|
200
|
+
return { resolvedType: undefined };
|
|
201
|
+
}
|
|
202
|
+
const { element, selectionSet: childSelectionSet } = selection;
|
|
203
|
+
(0, utils_1.assert)(element.definition.type, 'Element type definition should exist');
|
|
204
|
+
const type = element.definition.type;
|
|
205
|
+
if (childSelectionSet) {
|
|
206
|
+
(0, utils_1.assert)((0, definitions_1.isCompositeType)(type), 'Child selection sets should only exist on composite types');
|
|
207
|
+
const { resolvedType } = validateFieldValueType({
|
|
208
|
+
currentType: type,
|
|
209
|
+
selectionSet: childSelectionSet,
|
|
210
|
+
errorCollector,
|
|
211
|
+
metadata,
|
|
212
|
+
fromContextParent,
|
|
213
|
+
});
|
|
214
|
+
if (!resolvedType) {
|
|
215
|
+
return { resolvedType: undefined };
|
|
216
|
+
}
|
|
217
|
+
return { resolvedType: wrapResolvedType({ originalType: type, resolvedType }) };
|
|
218
|
+
}
|
|
219
|
+
(0, utils_1.assert)((0, definitions_1.isLeafType)((0, definitions_1.baseType)(type)), 'Expected a leaf type');
|
|
220
|
+
return {
|
|
221
|
+
resolvedType: wrapResolvedType({
|
|
222
|
+
originalType: type,
|
|
223
|
+
resolvedType: (0, definitions_1.baseType)(type)
|
|
224
|
+
})
|
|
225
|
+
};
|
|
226
|
+
});
|
|
227
|
+
return typesArray.reduce((acc, { resolvedType }) => {
|
|
228
|
+
var _a;
|
|
229
|
+
if (((_a = acc.resolvedType) === null || _a === void 0 ? void 0 : _a.toString()) === (resolvedType === null || resolvedType === void 0 ? void 0 : resolvedType.toString())) {
|
|
230
|
+
return { resolvedType };
|
|
231
|
+
}
|
|
232
|
+
return { resolvedType: undefined };
|
|
233
|
+
});
|
|
234
|
+
};
|
|
235
|
+
const validateSelectionFormat = ({ context, selection, fromContextParent, errorCollector, }) => {
|
|
236
|
+
try {
|
|
237
|
+
const node = (0, operations_1.parseOperationAST)(selection.trim().startsWith('{') ? selection : `{${selection}}`);
|
|
238
|
+
const selections = node.selectionSet.selections;
|
|
239
|
+
if (selections.length === 0) {
|
|
240
|
+
errorCollector.push(error_1.ERRORS.CONTEXT_INVALID_SELECTION.err(`Context "${context}" is used in "${fromContextParent.coordinate}" but the selection is invalid: no selection is made`, { nodes: (0, definitions_1.sourceASTs)(fromContextParent) }));
|
|
241
|
+
return { selectionType: 'error' };
|
|
242
|
+
}
|
|
243
|
+
const firstSelectionKind = selections[0].kind;
|
|
244
|
+
if (firstSelectionKind === 'Field') {
|
|
245
|
+
if (selections.length !== 1) {
|
|
246
|
+
errorCollector.push(error_1.ERRORS.CONTEXT_INVALID_SELECTION.err(`Context "${context}" is used in "${fromContextParent.coordinate}" but the selection is invalid: multiple selections are made`, { nodes: (0, definitions_1.sourceASTs)(fromContextParent) }));
|
|
247
|
+
return { selectionType: 'error' };
|
|
248
|
+
}
|
|
249
|
+
return { selectionType: 'field' };
|
|
250
|
+
}
|
|
251
|
+
else if (firstSelectionKind === 'InlineFragment') {
|
|
252
|
+
const inlineFragmentTypeConditions = new Set();
|
|
253
|
+
if (!selections.every((s) => s.kind === 'InlineFragment')) {
|
|
254
|
+
errorCollector.push(error_1.ERRORS.CONTEXT_INVALID_SELECTION.err(`Context "${context}" is used in "${fromContextParent.coordinate}" but the selection is invalid: multiple fields could be selected`, { nodes: (0, definitions_1.sourceASTs)(fromContextParent) }));
|
|
255
|
+
return { selectionType: 'error' };
|
|
256
|
+
}
|
|
257
|
+
selections.forEach((s) => {
|
|
258
|
+
(0, utils_1.assert)(s.kind === 'InlineFragment', 'Expected an inline fragment');
|
|
259
|
+
const { typeCondition } = s;
|
|
260
|
+
if (typeCondition) {
|
|
261
|
+
inlineFragmentTypeConditions.add(typeCondition.name.value);
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
if (inlineFragmentTypeConditions.size !== selections.length) {
|
|
265
|
+
errorCollector.push(error_1.ERRORS.CONTEXT_INVALID_SELECTION.err(`Context "${context}" is used in "${fromContextParent.coordinate}" but the selection is invalid: type conditions have same name`, { nodes: (0, definitions_1.sourceASTs)(fromContextParent) }));
|
|
266
|
+
return { selectionType: 'error' };
|
|
267
|
+
}
|
|
268
|
+
return {
|
|
269
|
+
selectionType: 'inlineFragment',
|
|
270
|
+
typeConditions: inlineFragmentTypeConditions,
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
else if (firstSelectionKind === 'FragmentSpread') {
|
|
274
|
+
errorCollector.push(error_1.ERRORS.CONTEXT_INVALID_SELECTION.err(`Context "${context}" is used in "${fromContextParent.coordinate}" but the selection is invalid: fragment spread is not allowed`, { nodes: (0, definitions_1.sourceASTs)(fromContextParent) }));
|
|
275
|
+
return { selectionType: 'error' };
|
|
276
|
+
}
|
|
277
|
+
else {
|
|
278
|
+
(0, utils_1.assertUnreachable)(firstSelectionKind);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
catch (err) {
|
|
282
|
+
errorCollector.push(error_1.ERRORS.CONTEXT_INVALID_SELECTION.err(`Context "${context}" is used in "${fromContextParent.coordinate}" but the selection is invalid: ${err.message}`, { nodes: (0, definitions_1.sourceASTs)(fromContextParent) }));
|
|
283
|
+
return { selectionType: 'error' };
|
|
284
|
+
}
|
|
285
|
+
};
|
|
286
|
+
function isValidImplementationFieldType(fieldType, implementedFieldType) {
|
|
287
|
+
if ((0, definitions_1.isNonNullType)(fieldType)) {
|
|
288
|
+
if ((0, definitions_1.isNonNullType)(implementedFieldType)) {
|
|
289
|
+
return isValidImplementationFieldType(fieldType.ofType, implementedFieldType.ofType);
|
|
290
|
+
}
|
|
291
|
+
else {
|
|
292
|
+
return isValidImplementationFieldType(fieldType.ofType, implementedFieldType);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
if ((0, definitions_1.isListType)(fieldType) && (0, definitions_1.isListType)(implementedFieldType)) {
|
|
296
|
+
return isValidImplementationFieldType(fieldType.ofType, implementedFieldType.ofType);
|
|
297
|
+
}
|
|
298
|
+
return !(0, definitions_1.isWrapperType)(fieldType) &&
|
|
299
|
+
!(0, definitions_1.isWrapperType)(implementedFieldType) &&
|
|
300
|
+
fieldType.name === implementedFieldType.name;
|
|
301
|
+
}
|
|
302
|
+
function selectionSetHasDirectives(selectionSet) {
|
|
303
|
+
return (0, operations_1.hasSelectionWithPredicate)(selectionSet, (s) => {
|
|
304
|
+
if (s.kind === 'FieldSelection') {
|
|
305
|
+
return s.element.appliedDirectives.length > 0;
|
|
306
|
+
}
|
|
307
|
+
else if (s.kind === 'FragmentSelection') {
|
|
308
|
+
return s.element.appliedDirectives.length > 0;
|
|
309
|
+
}
|
|
310
|
+
else {
|
|
311
|
+
(0, utils_1.assertUnreachable)(s);
|
|
312
|
+
}
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
function selectionSetHasAlias(selectionSet) {
|
|
316
|
+
return (0, operations_1.hasSelectionWithPredicate)(selectionSet, (s) => {
|
|
317
|
+
if (s.kind === 'FieldSelection') {
|
|
318
|
+
return s.element.alias !== undefined;
|
|
319
|
+
}
|
|
320
|
+
return false;
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
function validateFieldValue({ context, selection, fromContextParent, setContextLocations, errorCollector, metadata, }) {
|
|
324
|
+
const expectedType = fromContextParent.type;
|
|
325
|
+
(0, utils_1.assert)(expectedType, 'Expected a type');
|
|
326
|
+
const validateSelectionFormatResults = validateSelectionFormat({ context, selection, fromContextParent, errorCollector });
|
|
327
|
+
const selectionType = validateSelectionFormatResults.selectionType;
|
|
328
|
+
if (selectionType === 'error') {
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
331
|
+
const usedTypeConditions = new Set;
|
|
332
|
+
for (const location of setContextLocations) {
|
|
333
|
+
let selectionSet;
|
|
334
|
+
try {
|
|
335
|
+
selectionSet = (0, operations_1.parseSelectionSet)({ parentType: location, source: selection });
|
|
336
|
+
}
|
|
337
|
+
catch (e) {
|
|
338
|
+
errorCollector.push(error_1.ERRORS.CONTEXT_INVALID_SELECTION.err(`Context "${context}" is used in "${fromContextParent.coordinate}" but the selection is invalid for type ${location.name}. Error: ${e.message}`, { nodes: (0, definitions_1.sourceASTs)(fromContextParent) }));
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
341
|
+
if (selectionSetHasDirectives(selectionSet)) {
|
|
342
|
+
errorCollector.push(error_1.ERRORS.CONTEXT_INVALID_SELECTION.err(`Context "${context}" is used in "${fromContextParent.coordinate}" but the selection is invalid: directives are not allowed in the selection`, { nodes: (0, definitions_1.sourceASTs)(fromContextParent) }));
|
|
343
|
+
}
|
|
344
|
+
if (selectionSetHasAlias(selectionSet)) {
|
|
345
|
+
errorCollector.push(error_1.ERRORS.CONTEXT_INVALID_SELECTION.err(`Context "${context}" is used in "${fromContextParent.coordinate}" but the selection is invalid: aliases are not allowed in the selection`, { nodes: (0, definitions_1.sourceASTs)(fromContextParent) }));
|
|
346
|
+
}
|
|
347
|
+
if (selectionType === 'field') {
|
|
348
|
+
const { resolvedType } = validateFieldValueType({
|
|
349
|
+
currentType: location,
|
|
350
|
+
selectionSet,
|
|
351
|
+
errorCollector,
|
|
352
|
+
metadata,
|
|
353
|
+
fromContextParent,
|
|
354
|
+
});
|
|
355
|
+
if (resolvedType === undefined || !isValidImplementationFieldType(resolvedType, expectedType)) {
|
|
356
|
+
errorCollector.push(error_1.ERRORS.CONTEXT_INVALID_SELECTION.err(`Context "${context}" is used in "${fromContextParent.coordinate}" but the selection is invalid: the type of the selection "${resolvedType}" does not match the expected type "${expectedType === null || expectedType === void 0 ? void 0 : expectedType.toString()}"`, { nodes: (0, definitions_1.sourceASTs)(fromContextParent) }));
|
|
357
|
+
return;
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
else if (selectionType === 'inlineFragment') {
|
|
361
|
+
const selections = [];
|
|
362
|
+
for (const selection of selectionSet.selections()) {
|
|
363
|
+
if (selection.kind !== 'FragmentSelection') {
|
|
364
|
+
errorCollector.push(error_1.ERRORS.CONTEXT_INVALID_SELECTION.err(`Context "${context}" is used in "${fromContextParent.coordinate}" but the selection is invalid: selection should only contain a single field or at least one inline fragment}"`, { nodes: (0, definitions_1.sourceASTs)(fromContextParent) }));
|
|
365
|
+
continue;
|
|
366
|
+
}
|
|
367
|
+
const { typeCondition } = selection.element;
|
|
368
|
+
if (!typeCondition) {
|
|
369
|
+
errorCollector.push(error_1.ERRORS.CONTEXT_INVALID_SELECTION.err(`Context "${context}" is used in "${fromContextParent.coordinate}" but the selection is invalid: inline fragments must have type conditions"`, { nodes: (0, definitions_1.sourceASTs)(fromContextParent) }));
|
|
370
|
+
continue;
|
|
371
|
+
}
|
|
372
|
+
if (typeCondition.kind === 'ObjectType') {
|
|
373
|
+
if ((0, definitions_1.possibleRuntimeTypes)(location).includes(typeCondition)) {
|
|
374
|
+
selections.push(selection);
|
|
375
|
+
usedTypeConditions.add(typeCondition.name);
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
else {
|
|
379
|
+
errorCollector.push(error_1.ERRORS.CONTEXT_INVALID_SELECTION.err(`Context "${context}" is used in "${fromContextParent.coordinate}" but the selection is invalid: type conditions must be an object type"`, { nodes: (0, definitions_1.sourceASTs)(fromContextParent) }));
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
if (selections.length === 0) {
|
|
383
|
+
errorCollector.push(error_1.ERRORS.CONTEXT_INVALID_SELECTION.err(`Context "${context}" is used in "${fromContextParent.coordinate}" but the selection is invalid: no type condition matches the location "${location.coordinate}"`, { nodes: (0, definitions_1.sourceASTs)(fromContextParent) }));
|
|
384
|
+
return;
|
|
385
|
+
}
|
|
386
|
+
else {
|
|
387
|
+
for (const selection of selections) {
|
|
388
|
+
let { resolvedType } = validateFieldValueType({
|
|
389
|
+
currentType: selection.element.typeCondition,
|
|
390
|
+
selectionSet: selection.selectionSet,
|
|
391
|
+
errorCollector,
|
|
392
|
+
metadata,
|
|
393
|
+
fromContextParent,
|
|
394
|
+
});
|
|
395
|
+
if (resolvedType === undefined) {
|
|
396
|
+
errorCollector.push(error_1.ERRORS.CONTEXT_INVALID_SELECTION.err(`Context "${context}" is used in "${fromContextParent.coordinate}" but the selection is invalid: the type of the selection does not match the expected type "${expectedType === null || expectedType === void 0 ? void 0 : expectedType.toString()}"`, { nodes: (0, definitions_1.sourceASTs)(fromContextParent) }));
|
|
397
|
+
return;
|
|
398
|
+
}
|
|
399
|
+
if ((0, definitions_1.isNonNullType)(resolvedType)) {
|
|
400
|
+
resolvedType = resolvedType.ofType;
|
|
401
|
+
}
|
|
402
|
+
if (!isValidImplementationFieldType(resolvedType, expectedType)) {
|
|
403
|
+
errorCollector.push(error_1.ERRORS.CONTEXT_INVALID_SELECTION.err(`Context "${context}" is used in "${fromContextParent.coordinate}" but the selection is invalid: the type of the selection "${resolvedType === null || resolvedType === void 0 ? void 0 : resolvedType.toString()}" does not match the expected type "${expectedType === null || expectedType === void 0 ? void 0 : expectedType.toString()}"`, { nodes: (0, definitions_1.sourceASTs)(fromContextParent) }));
|
|
404
|
+
return;
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
if (validateSelectionFormatResults.selectionType === 'inlineFragment') {
|
|
411
|
+
for (const typeCondition of validateSelectionFormatResults.typeConditions) {
|
|
412
|
+
if (!usedTypeConditions.has(typeCondition)) {
|
|
413
|
+
errorCollector.push(error_1.ERRORS.CONTEXT_INVALID_SELECTION.err(`Context "${context}" is used in "${fromContextParent.coordinate}" but the selection is invalid: type condition "${typeCondition}" is never used.`, { nodes: (0, definitions_1.sourceASTs)(fromContextParent) }));
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
}
|
|
163
418
|
function validateAllFieldSet({ definition, targetTypeExtractor, errorCollector, metadata, isOnParentType = false, allowOnNonExternalLeafFields = false, allowFieldsWithArguments = false, allowOnInterface = false, onFields, }) {
|
|
164
419
|
for (const application of definition.applications()) {
|
|
165
420
|
const elt = application.parent;
|
|
@@ -190,6 +445,7 @@ function collectUsedFields(metadata) {
|
|
|
190
445
|
const type = (0, definitions_1.baseType)(field.type);
|
|
191
446
|
return (0, definitions_1.isCompositeType)(type) ? type : undefined;
|
|
192
447
|
}, usedFields);
|
|
448
|
+
collectUsedFieldsForFromContext(metadata, usedFields);
|
|
193
449
|
for (const itfType of metadata.schema.interfaceTypes()) {
|
|
194
450
|
const runtimeTypes = itfType.possibleRuntimeTypes();
|
|
195
451
|
for (const field of itfType.fields()) {
|
|
@@ -204,6 +460,62 @@ function collectUsedFields(metadata) {
|
|
|
204
460
|
return usedFields;
|
|
205
461
|
}
|
|
206
462
|
exports.collectUsedFields = collectUsedFields;
|
|
463
|
+
function collectUsedFieldsForFromContext(metadata, usedFieldDefs) {
|
|
464
|
+
const fromContextDirective = metadata.fromContextDirective();
|
|
465
|
+
const contextDirective = metadata.contextDirective();
|
|
466
|
+
if (!isFederationDirectiveDefinedInSchema(fromContextDirective) || !isFederationDirectiveDefinedInSchema(contextDirective)) {
|
|
467
|
+
return;
|
|
468
|
+
}
|
|
469
|
+
const entryPoints = new Map();
|
|
470
|
+
for (const application of contextDirective.applications()) {
|
|
471
|
+
const type = application.parent;
|
|
472
|
+
if (!type) {
|
|
473
|
+
continue;
|
|
474
|
+
}
|
|
475
|
+
const context = application.arguments().name;
|
|
476
|
+
if (!entryPoints.has(context)) {
|
|
477
|
+
entryPoints.set(context, new Set());
|
|
478
|
+
}
|
|
479
|
+
entryPoints.get(context).add(type);
|
|
480
|
+
}
|
|
481
|
+
for (const application of fromContextDirective.applications()) {
|
|
482
|
+
const type = application.parent;
|
|
483
|
+
if (!type) {
|
|
484
|
+
continue;
|
|
485
|
+
}
|
|
486
|
+
const fieldValue = application.arguments().field;
|
|
487
|
+
const { context, selection } = parseContext(fieldValue);
|
|
488
|
+
if (!context) {
|
|
489
|
+
continue;
|
|
490
|
+
}
|
|
491
|
+
const contextTypes = entryPoints.get(context);
|
|
492
|
+
if (!contextTypes) {
|
|
493
|
+
continue;
|
|
494
|
+
}
|
|
495
|
+
for (const contextType of contextTypes) {
|
|
496
|
+
try {
|
|
497
|
+
const fieldAccessor = (t, f) => {
|
|
498
|
+
const field = t.field(f);
|
|
499
|
+
if (field) {
|
|
500
|
+
usedFieldDefs.add(field);
|
|
501
|
+
if ((0, definitions_1.isInterfaceType)(t)) {
|
|
502
|
+
for (const implType of t.possibleRuntimeTypes()) {
|
|
503
|
+
const implField = implType.field(f);
|
|
504
|
+
if (implField) {
|
|
505
|
+
usedFieldDefs.add(implField);
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
return field;
|
|
511
|
+
};
|
|
512
|
+
(0, operations_1.parseSelectionSet)({ parentType: contextType, source: selection, fieldAccessor });
|
|
513
|
+
}
|
|
514
|
+
catch (e) {
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
}
|
|
207
519
|
function collectUsedFieldsForDirective(definition, targetTypeExtractor, usedFieldDefs) {
|
|
208
520
|
for (const application of definition.applications()) {
|
|
209
521
|
const type = targetTypeExtractor(application.parent);
|
|
@@ -471,6 +783,12 @@ class FederationMetadata {
|
|
|
471
783
|
sourceFieldDirective() {
|
|
472
784
|
return this.getPost20FederationDirective(federationSpec_1.FederationDirectiveName.SOURCE_FIELD);
|
|
473
785
|
}
|
|
786
|
+
fromContextDirective() {
|
|
787
|
+
return this.getPost20FederationDirective(federationSpec_1.FederationDirectiveName.FROM_CONTEXT);
|
|
788
|
+
}
|
|
789
|
+
contextDirective() {
|
|
790
|
+
return this.getPost20FederationDirective(federationSpec_1.FederationDirectiveName.CONTEXT);
|
|
791
|
+
}
|
|
474
792
|
allFederationDirectives() {
|
|
475
793
|
const baseDirectives = [
|
|
476
794
|
this.keyDirective(),
|
|
@@ -518,6 +836,14 @@ class FederationMetadata {
|
|
|
518
836
|
if (isFederationDirectiveDefinedInSchema(sourceFieldDirective)) {
|
|
519
837
|
baseDirectives.push(sourceFieldDirective);
|
|
520
838
|
}
|
|
839
|
+
const contextDirective = this.contextDirective();
|
|
840
|
+
if (isFederationDirectiveDefinedInSchema(contextDirective)) {
|
|
841
|
+
baseDirectives.push(contextDirective);
|
|
842
|
+
}
|
|
843
|
+
const fromContextDirective = this.fromContextDirective();
|
|
844
|
+
if (isFederationDirectiveDefinedInSchema(fromContextDirective)) {
|
|
845
|
+
baseDirectives.push(fromContextDirective);
|
|
846
|
+
}
|
|
521
847
|
return baseDirectives;
|
|
522
848
|
}
|
|
523
849
|
entityType() {
|
|
@@ -621,7 +947,7 @@ class FederationBlueprint extends definitions_1.SchemaBlueprint {
|
|
|
621
947
|
FederationMetadata.prototype['onInvalidate'].call(metadata);
|
|
622
948
|
}
|
|
623
949
|
onValidation(schema) {
|
|
624
|
-
var _a;
|
|
950
|
+
var _a, _b, _c;
|
|
625
951
|
const errorCollector = super.onValidation(schema);
|
|
626
952
|
if (this.withRootTypeRenaming) {
|
|
627
953
|
for (const k of definitions_1.allSchemaRootKinds) {
|
|
@@ -683,6 +1009,70 @@ class FederationBlueprint extends definitions_1.SchemaBlueprint {
|
|
|
683
1009
|
errorCollector,
|
|
684
1010
|
metadata,
|
|
685
1011
|
});
|
|
1012
|
+
const contextDirective = metadata.contextDirective();
|
|
1013
|
+
const contextToTypeMap = new Map();
|
|
1014
|
+
for (const application of contextDirective.applications()) {
|
|
1015
|
+
const parent = application.parent;
|
|
1016
|
+
const name = application.arguments().name;
|
|
1017
|
+
if (name.includes('_')) {
|
|
1018
|
+
errorCollector.push(error_1.ERRORS.CONTEXT_NAME_INVALID.err(`Context name "${name}" may not contain an underscore.`, { nodes: (0, definitions_1.sourceASTs)(application) }));
|
|
1019
|
+
}
|
|
1020
|
+
const types = contextToTypeMap.get(name);
|
|
1021
|
+
if (types) {
|
|
1022
|
+
types.push(parent);
|
|
1023
|
+
}
|
|
1024
|
+
else {
|
|
1025
|
+
contextToTypeMap.set(name, [parent]);
|
|
1026
|
+
}
|
|
1027
|
+
}
|
|
1028
|
+
const fromContextDirective = metadata.fromContextDirective();
|
|
1029
|
+
for (const application of fromContextDirective.applications()) {
|
|
1030
|
+
const { field } = application.arguments();
|
|
1031
|
+
const { context, selection } = parseContext(field);
|
|
1032
|
+
if (application.parent.parent.kind === 'DirectiveDefinition') {
|
|
1033
|
+
errorCollector.push(error_1.ERRORS.CONTEXT_NOT_SET.err(`@fromContext argument cannot be used on a directive definition "${application.parent.coordinate}".`, { nodes: (0, definitions_1.sourceASTs)(application) }));
|
|
1034
|
+
continue;
|
|
1035
|
+
}
|
|
1036
|
+
const parent = application.parent;
|
|
1037
|
+
if (((_c = (_b = parent === null || parent === void 0 ? void 0 : parent.parent) === null || _b === void 0 ? void 0 : _b.parent) === null || _c === void 0 ? void 0 : _c.kind) !== 'ObjectType') {
|
|
1038
|
+
errorCollector.push(error_1.ERRORS.CONTEXT_NOT_SET.err(`@fromContext argument cannot be used on a field that exists on an abstract type "${application.parent.coordinate}".`, { nodes: (0, definitions_1.sourceASTs)(application) }));
|
|
1039
|
+
continue;
|
|
1040
|
+
}
|
|
1041
|
+
const objectType = parent.parent.parent;
|
|
1042
|
+
for (const implementedInterfaceType of objectType.interfaces()) {
|
|
1043
|
+
const implementedInterfaceField = implementedInterfaceType.field(parent.parent.name);
|
|
1044
|
+
if (implementedInterfaceField) {
|
|
1045
|
+
errorCollector.push(error_1.ERRORS.CONTEXT_NOT_SET.err(`@fromContext argument cannot be used on a field implementing an interface field "${implementedInterfaceField.coordinate}".`, { nodes: (0, definitions_1.sourceASTs)(application) }));
|
|
1046
|
+
}
|
|
1047
|
+
}
|
|
1048
|
+
if (parent.defaultValue !== undefined) {
|
|
1049
|
+
errorCollector.push(error_1.ERRORS.CONTEXT_NOT_SET.err(`@fromContext arguments may not have a default value: "${parent.coordinate}".`, { nodes: (0, definitions_1.sourceASTs)(application) }));
|
|
1050
|
+
}
|
|
1051
|
+
if (!context || !selection) {
|
|
1052
|
+
errorCollector.push(error_1.ERRORS.NO_CONTEXT_IN_SELECTION.err(`@fromContext argument does not reference a context "${field}".`, { nodes: (0, definitions_1.sourceASTs)(application) }));
|
|
1053
|
+
}
|
|
1054
|
+
else {
|
|
1055
|
+
const locations = contextToTypeMap.get(context);
|
|
1056
|
+
if (!locations) {
|
|
1057
|
+
errorCollector.push(error_1.ERRORS.CONTEXT_NOT_SET.err(`Context "${context}" is used at location "${parent.coordinate}" but is never set.`, { nodes: (0, definitions_1.sourceASTs)(application) }));
|
|
1058
|
+
}
|
|
1059
|
+
else {
|
|
1060
|
+
validateFieldValue({
|
|
1061
|
+
context,
|
|
1062
|
+
selection,
|
|
1063
|
+
fromContextParent: parent,
|
|
1064
|
+
setContextLocations: locations,
|
|
1065
|
+
errorCollector,
|
|
1066
|
+
metadata,
|
|
1067
|
+
});
|
|
1068
|
+
}
|
|
1069
|
+
const keyDirective = metadata.keyDirective();
|
|
1070
|
+
const keyApplications = objectType.appliedDirectivesOf(keyDirective);
|
|
1071
|
+
if (!keyApplications.some(app => app.arguments().resolvable || app.arguments().resolvable === undefined)) {
|
|
1072
|
+
errorCollector.push(error_1.ERRORS.CONTEXT_NO_RESOLVABLE_KEY.err(`Object "${objectType.coordinate}" has no resolvable key but has an a field with a contextual argument.`, { nodes: (0, definitions_1.sourceASTs)(objectType) }));
|
|
1073
|
+
}
|
|
1074
|
+
}
|
|
1075
|
+
}
|
|
686
1076
|
validateNoExternalOnInterfaceFields(metadata, errorCollector);
|
|
687
1077
|
validateAllExternalFieldsUsed(metadata, errorCollector);
|
|
688
1078
|
validateKeyOnInterfacesAreAlsoOnAllImplementations(metadata, errorCollector);
|
|
@@ -786,8 +1176,8 @@ function setSchemaAsFed2Subgraph(schema, useLatest = false) {
|
|
|
786
1176
|
}
|
|
787
1177
|
}
|
|
788
1178
|
exports.setSchemaAsFed2Subgraph = setSchemaAsFed2Subgraph;
|
|
789
|
-
exports.FEDERATION2_LINK_WITH_FULL_IMPORTS = '@link(url: "https://specs.apollo.dev/federation/v2.
|
|
790
|
-
exports.FEDERATION2_LINK_WITH_AUTO_EXPANDED_IMPORTS = '@link(url: "https://specs.apollo.dev/federation/v2.
|
|
1179
|
+
exports.FEDERATION2_LINK_WITH_FULL_IMPORTS = '@link(url: "https://specs.apollo.dev/federation/v2.8", import: ["@key", "@requires", "@provides", "@external", "@tag", "@extends", "@shareable", "@inaccessible", "@override", "@composeDirective", "@interfaceObject", "@authenticated", "@requiresScopes", "@policy", "@sourceAPI", "@sourceType", "@sourceField", "@context", "@fromContext"])';
|
|
1180
|
+
exports.FEDERATION2_LINK_WITH_AUTO_EXPANDED_IMPORTS = '@link(url: "https://specs.apollo.dev/federation/v2.8", import: ["@key", "@requires", "@provides", "@external", "@tag", "@extends", "@shareable", "@inaccessible", "@override", "@composeDirective", "@interfaceObject"])';
|
|
791
1181
|
exports.FEDERATION2_LINK_WITH_AUTO_EXPANDED_IMPORTS_UPGRADED = '@link(url: "https://specs.apollo.dev/federation/v2.4", import: ["@key", "@requires", "@provides", "@external", "@tag", "@extends", "@shareable", "@inaccessible", "@override", "@composeDirective", "@interfaceObject"])';
|
|
792
1182
|
function asFed2SubgraphDocument(document, options) {
|
|
793
1183
|
var _a, _b;
|