@apollo/federation-internals 2.0.0-preview.7 → 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 +32 -3
- package/dist/buildSchema.d.ts.map +1 -1
- package/dist/buildSchema.js +51 -41
- 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 +205 -53
- package/dist/coreSpec.js.map +1 -1
- package/dist/definitions.d.ts +28 -11
- package/dist/definitions.d.ts.map +1 -1
- package/dist/definitions.js +185 -67
- 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 +17 -0
- package/dist/error.d.ts.map +1 -1
- package/dist/error.js +54 -2
- package/dist/error.js.map +1 -1
- package/dist/extractSubgraphsFromSupergraph.d.ts.map +1 -1
- package/dist/extractSubgraphsFromSupergraph.js +7 -1
- package/dist/extractSubgraphsFromSupergraph.js.map +1 -1
- package/dist/federation.d.ts +22 -5
- package/dist/federation.d.ts.map +1 -1
- package/dist/federation.js +143 -86
- 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 -22
- package/dist/federationSpec.js.map +1 -1
- package/dist/inaccessibleSpec.d.ts +10 -2
- package/dist/inaccessibleSpec.d.ts.map +1 -1
- package/dist/inaccessibleSpec.js +634 -16
- 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 +2 -0
- 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/schemaUpgrader.d.ts.map +1 -1
- package/dist/schemaUpgrader.js +17 -7
- 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 +2 -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 -14
- package/dist/tagSpec.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 +4 -4
- package/src/__tests__/coreSpec.test.ts +212 -0
- package/src/__tests__/definitions.test.ts +75 -0
- package/src/__tests__/removeInaccessibleElements.test.ts +2229 -137
- package/src/__tests__/schemaUpgrader.test.ts +3 -2
- package/src/__tests__/subgraphValidation.test.ts +419 -4
- package/src/__tests__/values.test.ts +315 -3
- package/src/buildSchema.ts +98 -51
- package/src/coreSpec.ts +277 -65
- package/src/definitions.ts +317 -92
- package/src/directiveAndTypeSpecification.ts +98 -21
- package/src/error.ts +119 -1
- package/src/extractSubgraphsFromSupergraph.ts +7 -1
- package/src/federation.ts +184 -102
- package/src/federationSpec.ts +56 -24
- package/src/inaccessibleSpec.ts +985 -39
- 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/schemaUpgrader.ts +29 -13
- package/src/suggestions.ts +1 -1
- package/src/supergraphs.ts +2 -0
- package/src/tagSpec.ts +49 -16
- 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/sharing.d.ts.map +0 -1
- package/dist/sharing.js.map +0 -1
package/src/federationSpec.ts
CHANGED
|
@@ -9,10 +9,12 @@ import {
|
|
|
9
9
|
createDirectiveSpecification,
|
|
10
10
|
createScalarTypeSpecification,
|
|
11
11
|
} from "./directiveAndTypeSpecification";
|
|
12
|
-
import { DirectiveLocation } from "graphql";
|
|
12
|
+
import { DirectiveLocation, GraphQLError } from "graphql";
|
|
13
13
|
import { assert } from "./utils";
|
|
14
|
-
import {
|
|
14
|
+
import { TAG_VERSIONS } from "./tagSpec";
|
|
15
15
|
import { federationMetadata } from "./federation";
|
|
16
|
+
import { registerKnownFeature } from "./knownCoreFeatures";
|
|
17
|
+
import { INACCESSIBLE_VERSIONS } from "./inaccessibleSpec";
|
|
16
18
|
|
|
17
19
|
export const federationIdentity = 'https://specs.apollo.dev/federation';
|
|
18
20
|
|
|
@@ -22,10 +24,13 @@ export const keyDirectiveSpec = createDirectiveSpecification({
|
|
|
22
24
|
name:'key',
|
|
23
25
|
locations: [DirectiveLocation.OBJECT, DirectiveLocation.INTERFACE],
|
|
24
26
|
repeatable: true,
|
|
25
|
-
argumentFct: (schema) =>
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
argumentFct: (schema) => ({
|
|
28
|
+
args: [
|
|
29
|
+
fieldsArgument(schema),
|
|
30
|
+
{ name: 'resolvable', type: schema.booleanType(), defaultValue: true },
|
|
31
|
+
],
|
|
32
|
+
errors: [],
|
|
33
|
+
}),
|
|
29
34
|
});
|
|
30
35
|
|
|
31
36
|
export const extendsDirectiveSpec = createDirectiveSpecification({
|
|
@@ -36,22 +41,28 @@ export const extendsDirectiveSpec = createDirectiveSpecification({
|
|
|
36
41
|
export const externalDirectiveSpec = createDirectiveSpecification({
|
|
37
42
|
name:'external',
|
|
38
43
|
locations: [DirectiveLocation.OBJECT, DirectiveLocation.FIELD_DEFINITION],
|
|
44
|
+
argumentFct: (schema) => ({
|
|
45
|
+
args: [{ name: 'reason', type: schema.stringType() }],
|
|
46
|
+
errors: [],
|
|
47
|
+
}),
|
|
39
48
|
});
|
|
40
49
|
|
|
41
50
|
export const requiresDirectiveSpec = createDirectiveSpecification({
|
|
42
51
|
name:'requires',
|
|
43
52
|
locations: [DirectiveLocation.FIELD_DEFINITION],
|
|
44
|
-
argumentFct: (schema) => {
|
|
45
|
-
|
|
46
|
-
|
|
53
|
+
argumentFct: (schema) => ({
|
|
54
|
+
args: [fieldsArgument(schema)],
|
|
55
|
+
errors: [],
|
|
56
|
+
}),
|
|
47
57
|
});
|
|
48
58
|
|
|
49
59
|
export const providesDirectiveSpec = createDirectiveSpecification({
|
|
50
60
|
name:'provides',
|
|
51
61
|
locations: [DirectiveLocation.FIELD_DEFINITION],
|
|
52
|
-
argumentFct: (schema) => {
|
|
53
|
-
|
|
54
|
-
|
|
62
|
+
argumentFct: (schema) => ({
|
|
63
|
+
args: [fieldsArgument(schema)],
|
|
64
|
+
errors: [],
|
|
65
|
+
}),
|
|
55
66
|
});
|
|
56
67
|
|
|
57
68
|
export const shareableDirectiveSpec = createDirectiveSpecification({
|
|
@@ -59,13 +70,13 @@ export const shareableDirectiveSpec = createDirectiveSpecification({
|
|
|
59
70
|
locations: [DirectiveLocation.OBJECT, DirectiveLocation.FIELD_DEFINITION],
|
|
60
71
|
});
|
|
61
72
|
|
|
62
|
-
export const
|
|
63
|
-
name:'
|
|
64
|
-
locations:
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}
|
|
73
|
+
export const overrideDirectiveSpec = createDirectiveSpecification({
|
|
74
|
+
name: 'override',
|
|
75
|
+
locations: [DirectiveLocation.FIELD_DEFINITION],
|
|
76
|
+
argumentFct: (schema) => ({
|
|
77
|
+
args: [{ name: 'from', type: new NonNullType(schema.stringType()) }],
|
|
78
|
+
errors: [],
|
|
79
|
+
}),
|
|
69
80
|
});
|
|
70
81
|
|
|
71
82
|
function fieldsArgument(schema: Schema): ArgumentSpecification {
|
|
@@ -78,17 +89,28 @@ function fieldSetType(schema: Schema): InputType {
|
|
|
78
89
|
return new NonNullType(metadata.fieldSetType());
|
|
79
90
|
}
|
|
80
91
|
|
|
92
|
+
export const FEDERATION2_ONLY_SPEC_DIRECTIVES = [
|
|
93
|
+
shareableDirectiveSpec,
|
|
94
|
+
INACCESSIBLE_VERSIONS.latest().inaccessibleDirectiveSpec,
|
|
95
|
+
overrideDirectiveSpec,
|
|
96
|
+
];
|
|
97
|
+
|
|
81
98
|
// Note that this is only used for federation 2+ (federation 1 adds the same directive, but not through a core spec).
|
|
82
99
|
export const FEDERATION2_SPEC_DIRECTIVES = [
|
|
83
100
|
keyDirectiveSpec,
|
|
84
101
|
requiresDirectiveSpec,
|
|
85
102
|
providesDirectiveSpec,
|
|
86
103
|
externalDirectiveSpec,
|
|
87
|
-
|
|
88
|
-
tagDirectiveSpec,
|
|
104
|
+
TAG_VERSIONS.latest().tagDirectiveSpec,
|
|
89
105
|
extendsDirectiveSpec, // TODO: should we stop supporting that?
|
|
106
|
+
...FEDERATION2_ONLY_SPEC_DIRECTIVES,
|
|
90
107
|
];
|
|
91
108
|
|
|
109
|
+
// Note that this is meant to contain _all_ federation directive names ever supported, regardless of which version.
|
|
110
|
+
// But currently, fed2 directives are a superset of fed1's so ... (but this may change if we stop supporting `@extends`
|
|
111
|
+
// in fed2).
|
|
112
|
+
export const ALL_FEDERATION_DIRECTIVES_DEFAULT_NAMES = FEDERATION2_SPEC_DIRECTIVES.map((spec) => spec.name);
|
|
113
|
+
|
|
92
114
|
export const FEDERATION_SPEC_TYPES = [
|
|
93
115
|
fieldSetTypeSpec,
|
|
94
116
|
]
|
|
@@ -98,17 +120,27 @@ export class FederationSpecDefinition extends FeatureDefinition {
|
|
|
98
120
|
super(new FeatureUrl(federationIdentity, 'federation', version));
|
|
99
121
|
}
|
|
100
122
|
|
|
101
|
-
addElementsToSchema(schema: Schema) {
|
|
123
|
+
addElementsToSchema(schema: Schema): GraphQLError[] {
|
|
102
124
|
const feature = this.featureInSchema(schema);
|
|
103
125
|
assert(feature, 'The federation specification should have been added to the schema before this is called');
|
|
104
126
|
|
|
105
|
-
|
|
127
|
+
let errors: GraphQLError[] = [];
|
|
128
|
+
errors = errors.concat(this.addTypeSpec(schema, fieldSetTypeSpec));
|
|
106
129
|
|
|
107
130
|
for (const directive of FEDERATION2_SPEC_DIRECTIVES) {
|
|
108
|
-
|
|
131
|
+
errors = errors.concat(this.addDirectiveSpec(schema, directive));
|
|
109
132
|
}
|
|
133
|
+
return errors;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
allElementNames(): string[] {
|
|
137
|
+
return FEDERATION2_SPEC_DIRECTIVES.map((spec) => `@${spec.name}`).concat([
|
|
138
|
+
fieldSetTypeSpec.name,
|
|
139
|
+
])
|
|
110
140
|
}
|
|
111
141
|
}
|
|
112
142
|
|
|
113
143
|
export const FEDERATION_VERSIONS = new FeatureDefinitions<FederationSpecDefinition>(federationIdentity)
|
|
114
144
|
.add(new FederationSpecDefinition(new FeatureVersion(2, 0)));
|
|
145
|
+
|
|
146
|
+
registerKnownFeature(FEDERATION_VERSIONS);
|