@apollo/federation-internals 2.9.0-connectors.8 → 2.10.0-alpha.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/dist/argumentCompositionStrategies.d.ts +17 -0
- package/dist/argumentCompositionStrategies.d.ts.map +1 -1
- package/dist/argumentCompositionStrategies.js +38 -0
- package/dist/argumentCompositionStrategies.js.map +1 -1
- package/dist/extractSubgraphsFromSupergraph.d.ts.map +1 -1
- package/dist/extractSubgraphsFromSupergraph.js +59 -8
- package/dist/extractSubgraphsFromSupergraph.js.map +1 -1
- package/dist/federation.d.ts +5 -2
- package/dist/federation.d.ts.map +1 -1
- package/dist/federation.js +20 -5
- 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/schemaUpgrader.d.ts.map +1 -1
- package/dist/schemaUpgrader.js +50 -31
- package/dist/schemaUpgrader.js.map +1 -1
- package/dist/specs/connectSpec.d.ts +0 -30
- package/dist/specs/connectSpec.d.ts.map +1 -1
- package/dist/specs/connectSpec.js +3 -3
- package/dist/specs/connectSpec.js.map +1 -1
- package/dist/specs/coreSpec.d.ts +1 -0
- package/dist/specs/coreSpec.d.ts.map +1 -1
- package/dist/specs/coreSpec.js +20 -2
- package/dist/specs/coreSpec.js.map +1 -1
- package/dist/specs/costSpec.d.ts +17 -0
- package/dist/specs/costSpec.d.ts.map +1 -0
- package/dist/specs/costSpec.js +49 -0
- package/dist/specs/costSpec.js.map +1 -0
- package/dist/specs/federationSpec.d.ts +3 -1
- package/dist/specs/federationSpec.d.ts.map +1 -1
- package/dist/specs/federationSpec.js +10 -2
- package/dist/specs/federationSpec.js.map +1 -1
- package/dist/supergraphs.d.ts +1 -1
- package/dist/supergraphs.d.ts.map +1 -1
- package/dist/supergraphs.js +2 -0
- package/dist/supergraphs.js.map +1 -1
- package/package.json +1 -1
- package/src/argumentCompositionStrategies.ts +37 -0
- package/src/extractSubgraphsFromSupergraph.ts +94 -7
- package/src/federation.ts +32 -11
- package/src/index.ts +1 -0
- package/src/schemaUpgrader.ts +55 -31
- package/src/specs/connectSpec.ts +4 -39
- package/src/specs/coreSpec.ts +23 -2
- package/src/specs/costSpec.ts +60 -0
- package/src/specs/federationSpec.ts +11 -2
- package/src/supergraphs.ts +3 -1
package/src/specs/coreSpec.ts
CHANGED
|
@@ -547,6 +547,27 @@ export class CoreSpecDefinition extends FeatureDefinition {
|
|
|
547
547
|
return feature.addElementsToSchema(schema);
|
|
548
548
|
}
|
|
549
549
|
|
|
550
|
+
applyFeatureAsLink(schema: Schema, feature: FeatureDefinition, purpose?: CorePurpose, imports?: CoreImport[]): GraphQLError[] {
|
|
551
|
+
const existing = schema.schemaDefinition.appliedDirectivesOf(linkDirectiveDefaultName).find((link) => link.arguments().url === feature.toString());
|
|
552
|
+
if (existing) {
|
|
553
|
+
existing.remove();
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
const coreDirective = this.coreDirective(schema);
|
|
557
|
+
const args: LinkDirectiveArgs = {
|
|
558
|
+
url: feature.toString(),
|
|
559
|
+
import: (existing?.arguments().import ?? []).concat(imports?.map((i) => i.as ? { name: `@${i.name}`, as: `@${i.as}` } : `@${i.name}`)),
|
|
560
|
+
feature: undefined,
|
|
561
|
+
};
|
|
562
|
+
|
|
563
|
+
if (this.supportPurposes() && purpose) {
|
|
564
|
+
args.for = purpose;
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
schema.schemaDefinition.applyDirective(coreDirective, args);
|
|
568
|
+
return feature.addElementsToSchema(schema);
|
|
569
|
+
}
|
|
570
|
+
|
|
550
571
|
extractFeatureUrl(args: CoreOrLinkDirectiveArgs): FeatureUrl {
|
|
551
572
|
return FeatureUrl.parse(args[this.urlArgName()]!);
|
|
552
573
|
}
|
|
@@ -597,7 +618,7 @@ export class FeatureDefinitions<T extends FeatureDefinition = FeatureDefinition>
|
|
|
597
618
|
// this._definitions is already sorted with the most recent first
|
|
598
619
|
// get the first definition that is compatible with the federation version
|
|
599
620
|
// if the minimum version is not present, assume that we won't look for an older version
|
|
600
|
-
const def = this._definitions.find(def => def.minimumFederationVersion ? fedVersion
|
|
621
|
+
const def = this._definitions.find(def => def.minimumFederationVersion ? fedVersion.gte(def.minimumFederationVersion) : true);
|
|
601
622
|
assert(def, `No compatible definition exists for federation version ${fedVersion}`);
|
|
602
623
|
|
|
603
624
|
// note that it's necessary that we can only get versions that have the same major version as the latest,
|
|
@@ -649,7 +670,7 @@ export class FeatureVersion {
|
|
|
649
670
|
let max: FeatureVersion | undefined;
|
|
650
671
|
|
|
651
672
|
for (const version of versions) {
|
|
652
|
-
if (!max || version
|
|
673
|
+
if (!max || version.gt(max)) {
|
|
653
674
|
max = version;
|
|
654
675
|
}
|
|
655
676
|
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { DirectiveLocation } from 'graphql';
|
|
2
|
+
import { createDirectiveSpecification } from '../directiveAndTypeSpecification';
|
|
3
|
+
import { FeatureDefinition, FeatureDefinitions, FeatureUrl, FeatureVersion } from './coreSpec';
|
|
4
|
+
import { ListType, NonNullType } from '../definitions';
|
|
5
|
+
import { registerKnownFeature } from '../knownCoreFeatures';
|
|
6
|
+
import { ARGUMENT_COMPOSITION_STRATEGIES } from '../argumentCompositionStrategies';
|
|
7
|
+
|
|
8
|
+
export const costIdentity = 'https://specs.apollo.dev/cost';
|
|
9
|
+
|
|
10
|
+
export class CostSpecDefinition extends FeatureDefinition {
|
|
11
|
+
constructor(version: FeatureVersion, readonly minimumFederationVersion: FeatureVersion) {
|
|
12
|
+
super(new FeatureUrl(costIdentity, 'cost', version), minimumFederationVersion);
|
|
13
|
+
|
|
14
|
+
this.registerDirective(createDirectiveSpecification({
|
|
15
|
+
name: 'cost',
|
|
16
|
+
locations: [
|
|
17
|
+
DirectiveLocation.ARGUMENT_DEFINITION,
|
|
18
|
+
DirectiveLocation.ENUM,
|
|
19
|
+
DirectiveLocation.FIELD_DEFINITION,
|
|
20
|
+
DirectiveLocation.INPUT_FIELD_DEFINITION,
|
|
21
|
+
DirectiveLocation.OBJECT,
|
|
22
|
+
DirectiveLocation.SCALAR
|
|
23
|
+
],
|
|
24
|
+
args: [{ name: 'weight', type: (schema) => new NonNullType(schema.intType()), compositionStrategy: ARGUMENT_COMPOSITION_STRATEGIES.MAX }],
|
|
25
|
+
composes: true,
|
|
26
|
+
repeatable: false,
|
|
27
|
+
supergraphSpecification: (fedVersion) => COST_VERSIONS.getMinimumRequiredVersion(fedVersion),
|
|
28
|
+
}));
|
|
29
|
+
|
|
30
|
+
this.registerDirective(createDirectiveSpecification({
|
|
31
|
+
name: 'listSize',
|
|
32
|
+
locations: [DirectiveLocation.FIELD_DEFINITION],
|
|
33
|
+
args: [
|
|
34
|
+
{ name: 'assumedSize', type: (schema) => schema.intType(), compositionStrategy: ARGUMENT_COMPOSITION_STRATEGIES.NULLABLE_MAX },
|
|
35
|
+
{ name: 'slicingArguments', type: (schema) => new ListType(new NonNullType(schema.stringType())), compositionStrategy: ARGUMENT_COMPOSITION_STRATEGIES.NULLABLE_UNION },
|
|
36
|
+
{ name: 'sizedFields', type: (schema) => new ListType(new NonNullType(schema.stringType())), compositionStrategy: ARGUMENT_COMPOSITION_STRATEGIES.NULLABLE_UNION },
|
|
37
|
+
{ name: 'requireOneSlicingArgument', type: (schema) => schema.booleanType(), defaultValue: true, compositionStrategy: ARGUMENT_COMPOSITION_STRATEGIES.NULLABLE_AND },
|
|
38
|
+
],
|
|
39
|
+
composes: true,
|
|
40
|
+
repeatable: false,
|
|
41
|
+
supergraphSpecification: (fedVersion) => COST_VERSIONS.getMinimumRequiredVersion(fedVersion)
|
|
42
|
+
}));
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export const COST_VERSIONS = new FeatureDefinitions<CostSpecDefinition>(costIdentity)
|
|
47
|
+
.add(new CostSpecDefinition(new FeatureVersion(0, 1), new FeatureVersion(2, 9)));
|
|
48
|
+
|
|
49
|
+
registerKnownFeature(COST_VERSIONS);
|
|
50
|
+
|
|
51
|
+
export interface CostDirectiveArguments {
|
|
52
|
+
weight: number;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface ListSizeDirectiveArguments {
|
|
56
|
+
assumedSize?: number;
|
|
57
|
+
slicingArguments?: string[];
|
|
58
|
+
sizedFields?: string[];
|
|
59
|
+
requireOneSlicingArgument?: boolean;
|
|
60
|
+
}
|
|
@@ -19,6 +19,7 @@ import { AUTHENTICATED_VERSIONS } from "./authenticatedSpec";
|
|
|
19
19
|
import { REQUIRES_SCOPES_VERSIONS } from "./requiresScopesSpec";
|
|
20
20
|
import { POLICY_VERSIONS } from './policySpec';
|
|
21
21
|
import { CONTEXT_VERSIONS } from './contextSpec';
|
|
22
|
+
import { COST_VERSIONS } from "./costSpec";
|
|
22
23
|
|
|
23
24
|
export const federationIdentity = 'https://specs.apollo.dev/federation';
|
|
24
25
|
|
|
@@ -44,6 +45,8 @@ export enum FederationDirectiveName {
|
|
|
44
45
|
POLICY = 'policy',
|
|
45
46
|
CONTEXT = 'context',
|
|
46
47
|
FROM_CONTEXT = 'fromContext',
|
|
48
|
+
COST = 'cost',
|
|
49
|
+
LIST_SIZE = 'listSize',
|
|
47
50
|
}
|
|
48
51
|
|
|
49
52
|
const fieldSetTypeSpec = createScalarTypeSpecification({ name: FederationTypeName.FIELD_SET });
|
|
@@ -128,7 +131,7 @@ export class FederationSpecDefinition extends FeatureDefinition {
|
|
|
128
131
|
|
|
129
132
|
this.registerSubFeature(INACCESSIBLE_VERSIONS.getMinimumRequiredVersion(version));
|
|
130
133
|
|
|
131
|
-
if (version
|
|
134
|
+
if (version.gte(new FeatureVersion(2, 7))) {
|
|
132
135
|
this.registerDirective(createDirectiveSpecification({
|
|
133
136
|
name: FederationDirectiveName.OVERRIDE,
|
|
134
137
|
locations: [DirectiveLocation.FIELD_DEFINITION],
|
|
@@ -174,6 +177,10 @@ export class FederationSpecDefinition extends FeatureDefinition {
|
|
|
174
177
|
if (version.gte(new FeatureVersion(2, 8))) {
|
|
175
178
|
this.registerSubFeature(CONTEXT_VERSIONS.find(new FeatureVersion(0, 1))!);
|
|
176
179
|
}
|
|
180
|
+
|
|
181
|
+
if (version.gte(new FeatureVersion(2, 9))) {
|
|
182
|
+
this.registerSubFeature(COST_VERSIONS.find(new FeatureVersion(0, 1))!);
|
|
183
|
+
}
|
|
177
184
|
}
|
|
178
185
|
}
|
|
179
186
|
|
|
@@ -186,6 +193,8 @@ export const FEDERATION_VERSIONS = new FeatureDefinitions<FederationSpecDefiniti
|
|
|
186
193
|
.add(new FederationSpecDefinition(new FeatureVersion(2, 5)))
|
|
187
194
|
.add(new FederationSpecDefinition(new FeatureVersion(2, 6)))
|
|
188
195
|
.add(new FederationSpecDefinition(new FeatureVersion(2, 7)))
|
|
189
|
-
.add(new FederationSpecDefinition(new FeatureVersion(2, 8)))
|
|
196
|
+
.add(new FederationSpecDefinition(new FeatureVersion(2, 8)))
|
|
197
|
+
.add(new FederationSpecDefinition(new FeatureVersion(2, 9)))
|
|
198
|
+
.add(new FederationSpecDefinition(new FeatureVersion(2, 10)));
|
|
190
199
|
|
|
191
200
|
registerKnownFeature(FEDERATION_VERSIONS);
|
package/src/supergraphs.ts
CHANGED
|
@@ -40,6 +40,8 @@ export const ROUTER_SUPPORTED_SUPERGRAPH_FEATURES = new Set([
|
|
|
40
40
|
'https://specs.apollo.dev/policy/v0.1',
|
|
41
41
|
'https://specs.apollo.dev/source/v0.1',
|
|
42
42
|
'https://specs.apollo.dev/context/v0.1',
|
|
43
|
+
'https://specs.apollo.dev/cost/v0.1',
|
|
44
|
+
'https://specs.apollo.dev/connect/v0.1',
|
|
43
45
|
]);
|
|
44
46
|
|
|
45
47
|
const coreVersionZeroDotOneUrl = FeatureUrl.parse('https://specs.apollo.dev/core/v0.1');
|
|
@@ -127,7 +129,7 @@ export class Supergraph {
|
|
|
127
129
|
this.containedSubgraphs = extractSubgraphsNamesAndUrlsFromSupergraph(schema);
|
|
128
130
|
}
|
|
129
131
|
|
|
130
|
-
static build(supergraphSdl: string | DocumentNode, options?: { supportedFeatures?: Set<string
|
|
132
|
+
static build(supergraphSdl: string | DocumentNode, options?: { supportedFeatures?: Set<string> | null, validateSupergraph?: boolean }) {
|
|
131
133
|
// We delay validation because `checkFeatureSupport` in the constructor gives slightly more useful errors if, say, 'for' is used with core v0.1.
|
|
132
134
|
const schema = typeof supergraphSdl === 'string'
|
|
133
135
|
? buildSchema(supergraphSdl, { validate: false })
|