@apollo/federation-internals 2.0.0-preview.1 → 2.0.0-preview.12
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 +44 -3
- package/dist/buildSchema.d.ts.map +1 -1
- package/dist/buildSchema.js +59 -45
- package/dist/buildSchema.js.map +1 -1
- package/dist/coreSpec.d.ts +17 -9
- 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 +18 -0
- package/dist/error.d.ts.map +1 -1
- package/dist/error.js +56 -2
- package/dist/error.js.map +1 -1
- package/dist/extractSubgraphsFromSupergraph.d.ts.map +1 -1
- package/dist/extractSubgraphsFromSupergraph.js +15 -5
- package/dist/extractSubgraphsFromSupergraph.js.map +1 -1
- package/dist/federation.d.ts +18 -4
- package/dist/federation.d.ts.map +1 -1
- package/dist/federation.js +118 -67
- 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 -21
- 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 +7 -1
- 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/print.js +12 -12
- package/dist/print.js.map +1 -1
- package/dist/schemaUpgrader.d.ts.map +1 -1
- package/dist/schemaUpgrader.js +5 -6
- 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 -13
- 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 +79 -0
- package/src/__tests__/extractSubgraphsFromSupergraph.test.ts +64 -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 +104 -53
- package/src/coreSpec.ts +277 -65
- package/src/definitions.ts +317 -92
- package/src/directiveAndTypeSpecification.ts +98 -21
- package/src/error.ts +125 -1
- package/src/extractSubgraphsFromSupergraph.ts +23 -5
- package/src/federation.ts +157 -82
- package/src/federationSpec.ts +56 -23
- 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/print.ts +13 -11
- package/src/schemaUpgrader.ts +8 -12
- package/src/suggestions.ts +1 -1
- package/src/supergraphs.ts +2 -0
- package/src/tagSpec.ts +49 -15
- package/src/validate.ts +20 -9
- package/src/values.ts +39 -12
- package/tsconfig.test.tsbuildinfo +1 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/sharing.d.ts.map +0 -1
- package/dist/sharing.js.map +0 -1
package/src/index.ts
CHANGED
|
@@ -10,8 +10,10 @@ export * from './debug';
|
|
|
10
10
|
export * from './coreSpec';
|
|
11
11
|
export * from './joinSpec';
|
|
12
12
|
export * from './tagSpec';
|
|
13
|
+
export * from './inaccessibleSpec';
|
|
13
14
|
export * from './federationSpec';
|
|
14
15
|
export * from './supergraphs';
|
|
15
16
|
export * from './extractSubgraphsFromSupergraph';
|
|
16
17
|
export * from './error';
|
|
17
18
|
export * from './schemaUpgrader';
|
|
19
|
+
export * from './suggestions';
|
package/src/introspection.ts
CHANGED
|
@@ -35,13 +35,15 @@ export function addIntrospectionFields(schema: Schema) {
|
|
|
35
35
|
typeType.addField('possibleTypes', new ListType(new NonNullType(typeType)));
|
|
36
36
|
typeType.addField('enumValues', new ListType(new NonNullType(enumValueType)))
|
|
37
37
|
.addArgument('includeDeprecated', schema.booleanType(), false);
|
|
38
|
-
typeType.addField('inputFields', new ListType(new NonNullType(inputValueType)))
|
|
38
|
+
typeType.addField('inputFields', new ListType(new NonNullType(inputValueType)))
|
|
39
|
+
.addArgument('includeDeprecated', schema.booleanType(), false);
|
|
39
40
|
typeType.addField('ofType', typeType);
|
|
40
41
|
typeType.addField('specifiedByURL', schema.stringType());
|
|
41
42
|
|
|
42
43
|
fieldType.addField('name', new NonNullType(schema.stringType()));
|
|
43
44
|
fieldType.addField('description', schema.stringType());
|
|
44
|
-
fieldType.addField('args', new NonNullType(new ListType(new NonNullType(inputValueType))))
|
|
45
|
+
fieldType.addField('args', new NonNullType(new ListType(new NonNullType(inputValueType))))
|
|
46
|
+
.addArgument('includeDeprecated', schema.booleanType(), false);
|
|
45
47
|
fieldType.addField('type', new NonNullType(typeType));
|
|
46
48
|
fieldType.addField('isDeprecated', new NonNullType(schema.booleanType()));
|
|
47
49
|
fieldType.addField('deprecationReason', schema.stringType());
|
|
@@ -50,6 +52,8 @@ export function addIntrospectionFields(schema: Schema) {
|
|
|
50
52
|
inputValueType.addField('description', schema.stringType());
|
|
51
53
|
inputValueType.addField('type', new NonNullType(typeType));
|
|
52
54
|
inputValueType.addField('defaultValue', schema.stringType());
|
|
55
|
+
inputValueType.addField('isDeprecated', new NonNullType(schema.booleanType()));
|
|
56
|
+
inputValueType.addField('deprecationReason', schema.stringType());
|
|
53
57
|
|
|
54
58
|
enumValueType.addField('name', new NonNullType(schema.stringType()));
|
|
55
59
|
enumValueType.addField('description', schema.stringType());
|
|
@@ -65,7 +69,8 @@ export function addIntrospectionFields(schema: Schema) {
|
|
|
65
69
|
directiveType.addField('name', new NonNullType(schema.stringType()));
|
|
66
70
|
directiveType.addField('description', schema.stringType());
|
|
67
71
|
directiveType.addField('locations', new NonNullType(new ListType(new NonNullType(directiveLocationEnum))));
|
|
68
|
-
directiveType.addField('args', new NonNullType(new ListType(new NonNullType(inputValueType))))
|
|
72
|
+
directiveType.addField('args', new NonNullType(new ListType(new NonNullType(inputValueType))))
|
|
73
|
+
.addArgument('includeDeprecated', schema.booleanType(), false);
|
|
69
74
|
directiveType.addField('isRepeatable', new NonNullType(schema.booleanType()));
|
|
70
75
|
|
|
71
76
|
const schemaType = schema.addType(new ObjectType('__Schema', true));
|
package/src/joinSpec.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DirectiveLocation } from 'graphql';
|
|
1
|
+
import { DirectiveLocation, GraphQLError } from 'graphql';
|
|
2
2
|
import { FeatureDefinition, FeatureDefinitions, FeatureUrl, FeatureVersion } from "./coreSpec";
|
|
3
3
|
import {
|
|
4
4
|
DirectiveDefinition,
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
NonNullType,
|
|
9
9
|
} from "./definitions";
|
|
10
10
|
import { Subgraph, Subgraphs } from "./federation";
|
|
11
|
+
import { registerKnownFeature } from './knownCoreFeatures';
|
|
11
12
|
import { MultiMap } from "./utils";
|
|
12
13
|
|
|
13
14
|
export const joinIdentity = 'https://specs.apollo.dev/join';
|
|
@@ -38,7 +39,7 @@ export class JoinSpecDefinition extends FeatureDefinition {
|
|
|
38
39
|
return this.version.equals(new FeatureVersion(0, 1));
|
|
39
40
|
}
|
|
40
41
|
|
|
41
|
-
addElementsToSchema(schema: Schema) {
|
|
42
|
+
addElementsToSchema(schema: Schema): GraphQLError[] {
|
|
42
43
|
const joinGraph = this.addDirective(schema, 'graph').addLocations(DirectiveLocation.ENUM_VALUE);
|
|
43
44
|
joinGraph.addArgument('name', new NonNullType(schema.stringType()));
|
|
44
45
|
joinGraph.addArgument('url', new NonNullType(schema.stringType()));
|
|
@@ -73,6 +74,8 @@ export class JoinSpecDefinition extends FeatureDefinition {
|
|
|
73
74
|
if (!this.isV01()) {
|
|
74
75
|
joinField.addArgument('type', schema.stringType());
|
|
75
76
|
joinField.addArgument('external', schema.booleanType());
|
|
77
|
+
joinField.addArgument('override', schema.stringType());
|
|
78
|
+
joinField.addArgument('usedOverridden', schema.booleanType());
|
|
76
79
|
}
|
|
77
80
|
|
|
78
81
|
if (!this.isV01()) {
|
|
@@ -88,6 +91,23 @@ export class JoinSpecDefinition extends FeatureDefinition {
|
|
|
88
91
|
const joinOwner = this.addDirective(schema, 'owner').addLocations(DirectiveLocation.OBJECT);
|
|
89
92
|
joinOwner.addArgument('graph', new NonNullType(graphEnum));
|
|
90
93
|
}
|
|
94
|
+
return [];
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
allElementNames(): string[] {
|
|
98
|
+
const names = [
|
|
99
|
+
'graph',
|
|
100
|
+
'Graph',
|
|
101
|
+
'FieldSet',
|
|
102
|
+
'@type',
|
|
103
|
+
'@field',
|
|
104
|
+
];
|
|
105
|
+
if (this.isV01()) {
|
|
106
|
+
names.push('@owner');
|
|
107
|
+
} else {
|
|
108
|
+
names.push('@implements');
|
|
109
|
+
}
|
|
110
|
+
return names;
|
|
91
111
|
}
|
|
92
112
|
|
|
93
113
|
populateGraphEnum(schema: Schema, subgraphs: Subgraphs): Map<string, string> {
|
|
@@ -141,7 +161,15 @@ export class JoinSpecDefinition extends FeatureDefinition {
|
|
|
141
161
|
return this.directive(schema, 'implements');
|
|
142
162
|
}
|
|
143
163
|
|
|
144
|
-
fieldDirective(schema: Schema): DirectiveDefinition<{
|
|
164
|
+
fieldDirective(schema: Schema): DirectiveDefinition<{
|
|
165
|
+
graph: string,
|
|
166
|
+
requires?: string,
|
|
167
|
+
provides?: string,
|
|
168
|
+
override?: string,
|
|
169
|
+
type?: string,
|
|
170
|
+
external?: boolean,
|
|
171
|
+
usedOverridden?: boolean,
|
|
172
|
+
}> {
|
|
145
173
|
return this.directive(schema, 'field')!;
|
|
146
174
|
}
|
|
147
175
|
|
|
@@ -160,3 +188,5 @@ export class JoinSpecDefinition extends FeatureDefinition {
|
|
|
160
188
|
export const JOIN_VERSIONS = new FeatureDefinitions<JoinSpecDefinition>(joinIdentity)
|
|
161
189
|
.add(new JoinSpecDefinition(new FeatureVersion(0, 1)))
|
|
162
190
|
.add(new JoinSpecDefinition(new FeatureVersion(0, 2)));
|
|
191
|
+
|
|
192
|
+
registerKnownFeature(JOIN_VERSIONS);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { FeatureDefinition, FeatureDefinitions, FeatureUrl } from "./coreSpec";
|
|
2
|
+
|
|
3
|
+
const registeredFeatures: Map<string, FeatureDefinitions> = new Map();
|
|
4
|
+
|
|
5
|
+
export function registerKnownFeature(definitions: FeatureDefinitions) {
|
|
6
|
+
if (!registeredFeatures.has(definitions.identity)) {
|
|
7
|
+
registeredFeatures.set(definitions.identity, definitions);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function coreFeatureDefinitionIfKnown(url: FeatureUrl): FeatureDefinition | undefined {
|
|
12
|
+
return registeredFeatures.get(url.identity)?.find(url.version);
|
|
13
|
+
}
|
package/src/operations.ts
CHANGED
|
@@ -862,6 +862,21 @@ export class SelectionSet {
|
|
|
862
862
|
}
|
|
863
863
|
}
|
|
864
864
|
|
|
865
|
+
export function allFieldDefinitionsInSelectionSet(selection: SelectionSet): FieldDefinition<CompositeType>[] {
|
|
866
|
+
const stack = Array.from(selection.selections());
|
|
867
|
+
const allFields: FieldDefinition<CompositeType>[] = [];
|
|
868
|
+
while (stack.length > 0) {
|
|
869
|
+
const selection = stack.pop()!;
|
|
870
|
+
if (selection.kind === 'FieldSelection') {
|
|
871
|
+
allFields.push(selection.field.definition);
|
|
872
|
+
}
|
|
873
|
+
if (selection.selectionSet) {
|
|
874
|
+
stack.push(...selection.selectionSet.selections());
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
return allFields;
|
|
878
|
+
}
|
|
879
|
+
|
|
865
880
|
export function selectionSetOfElement(element: OperationElement, subSelection?: SelectionSet): SelectionSet {
|
|
866
881
|
const selectionSet = new SelectionSet(element.parentType);
|
|
867
882
|
selectionSet.add(selectionOfElement(element, subSelection));
|
|
@@ -5,9 +5,7 @@ import {
|
|
|
5
5
|
federationMetadata,
|
|
6
6
|
FieldDefinition,
|
|
7
7
|
collectTargetFields,
|
|
8
|
-
|
|
9
|
-
ObjectType,
|
|
10
|
-
Schema
|
|
8
|
+
Schema,
|
|
11
9
|
} from ".";
|
|
12
10
|
|
|
13
11
|
export function computeShareables(schema: Schema): (field: FieldDefinition<CompositeType>) => boolean {
|
|
@@ -33,7 +31,7 @@ export function computeShareables(schema: Schema): (field: FieldDefinition<Compo
|
|
|
33
31
|
}
|
|
34
32
|
};
|
|
35
33
|
|
|
36
|
-
for (const type of schema.
|
|
34
|
+
for (const type of schema.objectTypes()) {
|
|
37
35
|
addKeyFields(type);
|
|
38
36
|
const shareablesOnType = shareableDirective ? type.appliedDirectivesOf(shareableDirective) : [];
|
|
39
37
|
for (const field of type.fields()) {
|
|
@@ -59,10 +57,9 @@ export function computeShareables(schema: Schema): (field: FieldDefinition<Compo
|
|
|
59
57
|
}
|
|
60
58
|
}
|
|
61
59
|
|
|
62
|
-
for (const type of schema.
|
|
60
|
+
for (const type of schema.interfaceTypes()) {
|
|
63
61
|
addKeyFields(type);
|
|
64
62
|
}
|
|
65
63
|
|
|
66
64
|
return (field) => shareableFields.has(field.coordinate);
|
|
67
65
|
}
|
|
68
|
-
|
package/src/print.ts
CHANGED
|
@@ -140,7 +140,7 @@ function printSchemaDefinitionOrExtension(
|
|
|
140
140
|
}
|
|
141
141
|
const rootEntries = orderRoots(roots, options).map((rootType) => `${options.indentString}${rootType.rootKind}: ${rootType.type}`);
|
|
142
142
|
// Note that that the description is never written with the extension as `extend schema` doesn _not_ support descriptions
|
|
143
|
-
return
|
|
143
|
+
return printDescription(schemaDefinition, options, extension)
|
|
144
144
|
+ printIsExtension(extension)
|
|
145
145
|
+ 'schema'
|
|
146
146
|
+ printAppliedDirectives(directives, options, true, rootEntries.length !== 0)
|
|
@@ -187,7 +187,7 @@ export function printTypeDefinitionAndExtensions(type: NamedType, options: Print
|
|
|
187
187
|
|
|
188
188
|
export function printDirectiveDefinition(directive: DirectiveDefinition, options: PrintOptions): string {
|
|
189
189
|
const locations = directive.locations.join(' | ');
|
|
190
|
-
return `${printDescription(directive, options)}directive ${directive}${printArgs(directive.arguments(), options)}${directive.repeatable ? ' repeatable' : ''} on ${locations}`;
|
|
190
|
+
return `${printDescription(directive, options, null)}directive ${directive}${printArgs(directive.arguments(), options)}${directive.repeatable ? ' repeatable' : ''} on ${locations}`;
|
|
191
191
|
}
|
|
192
192
|
|
|
193
193
|
function printAppliedDirectives(
|
|
@@ -207,10 +207,12 @@ function printAppliedDirectives(
|
|
|
207
207
|
function printDescription(
|
|
208
208
|
element: SchemaElement<any, any>,
|
|
209
209
|
options: PrintOptions,
|
|
210
|
+
extension: Extension<any> | undefined | null,
|
|
210
211
|
indentation: string = '',
|
|
211
212
|
firstInBlock: boolean = true
|
|
212
213
|
): string {
|
|
213
|
-
|
|
214
|
+
// Note that extensions cannot have descriptions (it's not syntactically valid)
|
|
215
|
+
if (extension || element.description === undefined || options.noDescriptions) {
|
|
214
216
|
return '';
|
|
215
217
|
}
|
|
216
218
|
|
|
@@ -227,7 +229,7 @@ function printScalarDefinitionOrExtension(type: ScalarType, options: PrintOption
|
|
|
227
229
|
if (extension && !directives.length) {
|
|
228
230
|
return undefined;
|
|
229
231
|
}
|
|
230
|
-
return `${printDescription(type, options)}${printIsExtension(extension)}scalar ${type.name}${printAppliedDirectives(directives, options, true, false)}`
|
|
232
|
+
return `${printDescription(type, options, extension)}${printIsExtension(extension)}scalar ${type.name}${printAppliedDirectives(directives, options, true, false)}`
|
|
231
233
|
}
|
|
232
234
|
|
|
233
235
|
function printImplementedInterfaces(implementations: readonly InterfaceImplementation<any>[]): string {
|
|
@@ -246,7 +248,7 @@ function printFieldBasedTypeDefinitionOrExtension(kind: string, type: ObjectType
|
|
|
246
248
|
if (!directives.length && !interfaces.length && !fields.length) {
|
|
247
249
|
return undefined;
|
|
248
250
|
}
|
|
249
|
-
return printDescription(type, options)
|
|
251
|
+
return printDescription(type, options, extension)
|
|
250
252
|
+ printIsExtension(extension)
|
|
251
253
|
+ kind + ' ' + type
|
|
252
254
|
+ printImplementedInterfaces(interfaces)
|
|
@@ -262,7 +264,7 @@ function printUnionDefinitionOrExtension(type: UnionType, options: PrintOptions,
|
|
|
262
264
|
return undefined;
|
|
263
265
|
}
|
|
264
266
|
const possibleTypes = members.length ? ' = ' + members.map(m => m.type).join(' | ') : '';
|
|
265
|
-
return printDescription(type, options)
|
|
267
|
+
return printDescription(type, options, extension)
|
|
266
268
|
+ printIsExtension(extension)
|
|
267
269
|
+ 'union ' + type
|
|
268
270
|
+ printAppliedDirectives(directives, options, true, members.length > 0)
|
|
@@ -276,11 +278,11 @@ function printEnumDefinitionOrExtension(type: EnumType, options: PrintOptions, e
|
|
|
276
278
|
return undefined;
|
|
277
279
|
}
|
|
278
280
|
const vals = values.map((v, i) =>
|
|
279
|
-
printDescription(v, options, options.indentString, !i)
|
|
281
|
+
printDescription(v, options, extension, options.indentString, !i)
|
|
280
282
|
+ options.indentString
|
|
281
283
|
+ v
|
|
282
284
|
+ printAppliedDirectives(v.appliedDirectives, options));
|
|
283
|
-
return printDescription(type, options)
|
|
285
|
+
return printDescription(type, options, extension)
|
|
284
286
|
+ printIsExtension(extension)
|
|
285
287
|
+ 'enum ' + type
|
|
286
288
|
+ printAppliedDirectives(directives, options, true, vals.length > 0)
|
|
@@ -294,7 +296,7 @@ function printInputDefinitionOrExtension(type: InputObjectType, options: PrintOp
|
|
|
294
296
|
if (!directives.length && !fields.length) {
|
|
295
297
|
return undefined;
|
|
296
298
|
}
|
|
297
|
-
return printDescription(type, options)
|
|
299
|
+
return printDescription(type, options, extension)
|
|
298
300
|
+ printIsExtension(extension)
|
|
299
301
|
+ 'input ' + type
|
|
300
302
|
+ printAppliedDirectives(directives, options, true, fields.length > 0)
|
|
@@ -304,7 +306,7 @@ function printInputDefinitionOrExtension(type: InputObjectType, options: PrintOp
|
|
|
304
306
|
|
|
305
307
|
function printFields(fields: readonly (FieldDefinition<any> | InputFieldDefinition)[], options: PrintOptions): string {
|
|
306
308
|
return printBlock(fields.map((f, i) =>
|
|
307
|
-
printDescription(f, options, options.indentString, !i)
|
|
309
|
+
printDescription(f, options, undefined, options.indentString, !i)
|
|
308
310
|
+ options.indentString
|
|
309
311
|
+ printField(f, options)
|
|
310
312
|
+ printAppliedDirectives(f.appliedDirectives, options)));
|
|
@@ -332,7 +334,7 @@ function printArgs(args: readonly ArgumentDefinition<any>[], options: PrintOptio
|
|
|
332
334
|
}
|
|
333
335
|
|
|
334
336
|
const formattedArgs = args
|
|
335
|
-
.map((arg, i) => printDescription(arg, options, ' ' + indentation, !i) + ' ' + indentation + printArg(arg, options))
|
|
337
|
+
.map((arg, i) => printDescription(arg, options, null, ' ' + indentation, !i) + ' ' + indentation + printArg(arg, options))
|
|
336
338
|
.join('\n');
|
|
337
339
|
return `(\n${formattedArgs}\n${indentation})`;
|
|
338
340
|
}
|
package/src/schemaUpgrader.ts
CHANGED
|
@@ -11,7 +11,6 @@ import {
|
|
|
11
11
|
errorCauses,
|
|
12
12
|
Extension,
|
|
13
13
|
FieldDefinition,
|
|
14
|
-
InterfaceType,
|
|
15
14
|
isCompositeType,
|
|
16
15
|
isInterfaceType,
|
|
17
16
|
isObjectType,
|
|
@@ -24,7 +23,6 @@ import {
|
|
|
24
23
|
import {
|
|
25
24
|
addSubgraphToError,
|
|
26
25
|
collectTargetFields,
|
|
27
|
-
collectUsedExternalFieldsCoordinates,
|
|
28
26
|
federationMetadata,
|
|
29
27
|
FederationMetadata,
|
|
30
28
|
printSubgraphNames,
|
|
@@ -43,7 +41,7 @@ type UpgradeChanges = MultiMap<UpgradeChangeID, UpgradeChange>;
|
|
|
43
41
|
export type UpgradeSuccess = {
|
|
44
42
|
subgraphs: Subgraphs,
|
|
45
43
|
changes: Map<string, UpgradeChanges>,
|
|
46
|
-
errors?: never,
|
|
44
|
+
errors?: never,
|
|
47
45
|
}
|
|
48
46
|
|
|
49
47
|
export type UpgradeFailure = {
|
|
@@ -235,7 +233,7 @@ export function upgradeSubgraphsIfNecessary(inputs: Subgraphs): UpgradeResult {
|
|
|
235
233
|
* 2. do not have a definition for the same type in the same subgraph (this is a GraphQL extension otherwise).
|
|
236
234
|
*
|
|
237
235
|
* Not that type extensions in federation 1 generally have a @key but in really the code consider something a type extension even without
|
|
238
|
-
* it (which I'd argue is a unintended bug of fed1 since this leads to various problems) so we don't check for the presence of @key here.
|
|
236
|
+
* it (which I'd argue is a unintended bug of fed1 since this leads to various problems) so we don't check for the presence of @key here.
|
|
239
237
|
*/
|
|
240
238
|
function isFederationTypeExtension(type: NamedType): boolean {
|
|
241
239
|
const metadata = federationMetadata(type.schema());
|
|
@@ -435,7 +433,7 @@ class SchemaUpgrader {
|
|
|
435
433
|
}
|
|
436
434
|
|
|
437
435
|
private removeExternalOnInterface() {
|
|
438
|
-
for (const itf of this.schema.
|
|
436
|
+
for (const itf of this.schema.interfaceTypes()) {
|
|
439
437
|
for (const field of itf.fields()) {
|
|
440
438
|
const external = this.external(field);
|
|
441
439
|
if (external) {
|
|
@@ -522,7 +520,7 @@ class SchemaUpgrader {
|
|
|
522
520
|
continue;
|
|
523
521
|
}
|
|
524
522
|
assert(isCompositeType(typeInOther), () => `Type ${type} is of kind ${type.kind} in ${this.subgraph.name} but ${typeInOther.kind} in ${other.name}`);
|
|
525
|
-
const keysInOther = typeInOther.appliedDirectivesOf(other.metadata().keyDirective());
|
|
523
|
+
const keysInOther = typeInOther.appliedDirectivesOf(other.metadata().keyDirective());
|
|
526
524
|
if (keysInOther.length === 0) {
|
|
527
525
|
continue;
|
|
528
526
|
}
|
|
@@ -564,14 +562,12 @@ class SchemaUpgrader {
|
|
|
564
562
|
}
|
|
565
563
|
|
|
566
564
|
private removeUnusedExternals() {
|
|
567
|
-
const usedExternalFieldsCoordinates = collectUsedExternalFieldsCoordinates(this.metadata);
|
|
568
|
-
|
|
569
565
|
for (const type of this.schema.types()) {
|
|
570
566
|
if (!isObjectType(type) && !isInterfaceType(type)) {
|
|
571
567
|
continue;
|
|
572
568
|
}
|
|
573
569
|
for (const field of type.fields()) {
|
|
574
|
-
if (this.metadata.isFieldExternal(field) && !
|
|
570
|
+
if (this.metadata.isFieldExternal(field) && !this.metadata.isFieldUsed(field)) {
|
|
575
571
|
this.addChange(new UnusedExternalRemoval(field.coordinate));
|
|
576
572
|
field.remove();
|
|
577
573
|
}
|
|
@@ -593,7 +589,7 @@ class SchemaUpgrader {
|
|
|
593
589
|
}
|
|
594
590
|
|
|
595
591
|
private removeDirectivesOnInterface() {
|
|
596
|
-
for (const type of this.schema.
|
|
592
|
+
for (const type of this.schema.interfaceTypes()) {
|
|
597
593
|
for (const application of type.appliedDirectivesOf(this.metadata.keyDirective())) {
|
|
598
594
|
this.addChange(new KeyOnInterfaceRemoval(type.name));
|
|
599
595
|
application.remove();
|
|
@@ -610,7 +606,7 @@ class SchemaUpgrader {
|
|
|
610
606
|
}
|
|
611
607
|
|
|
612
608
|
private removeProvidesOnNonComposite() {
|
|
613
|
-
for (const type of this.schema.
|
|
609
|
+
for (const type of this.schema.objectTypes()) {
|
|
614
610
|
for (const field of type.fields()) {
|
|
615
611
|
if (isCompositeType(baseType(field.type!))) {
|
|
616
612
|
continue;
|
|
@@ -630,7 +626,7 @@ class SchemaUpgrader {
|
|
|
630
626
|
// We add shareable:
|
|
631
627
|
// - to every "value type" (in the fed1 sense of non-root type and non-entity) if it is used in any other subgraphs
|
|
632
628
|
// - to any (non-external) field of an entity/root-type that is not a key field and if another subgraphs resolve it (fully or partially through @provides)
|
|
633
|
-
for (const type of this.schema.
|
|
629
|
+
for (const type of this.schema.objectTypes()) {
|
|
634
630
|
if (type.hasAppliedDirective(keyDirective) || type.isRootType()) {
|
|
635
631
|
for (const field of type.fields()) {
|
|
636
632
|
// To know if the field is a "key" field which doesn't need shareable, we rely on whether the field is shareable in the original
|
package/src/suggestions.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { mapKeys } from './utils';
|
|
|
5
5
|
* Given an invalid input string and a list of valid options, returns a filtered
|
|
6
6
|
* list of valid options sorted based on their similarity with the input.
|
|
7
7
|
*/
|
|
8
|
-
export function suggestionList(input: string, options: string[]): string[] {
|
|
8
|
+
export function suggestionList(input: string, options: readonly string[]): string[] {
|
|
9
9
|
const optionsByDistance = new Map<string, number>();
|
|
10
10
|
|
|
11
11
|
const threshold = Math.floor(input.length * 0.4) + 1;
|
package/src/supergraphs.ts
CHANGED
|
@@ -12,7 +12,9 @@ const SUPPORTED_FEATURES = new Set([
|
|
|
12
12
|
'https://specs.apollo.dev/join/v0.1',
|
|
13
13
|
'https://specs.apollo.dev/join/v0.2',
|
|
14
14
|
'https://specs.apollo.dev/tag/v0.1',
|
|
15
|
+
'https://specs.apollo.dev/tag/v0.2',
|
|
15
16
|
'https://specs.apollo.dev/inaccessible/v0.1',
|
|
17
|
+
'https://specs.apollo.dev/inaccessible/v0.2',
|
|
16
18
|
]);
|
|
17
19
|
|
|
18
20
|
export function ErrUnsupportedFeature(feature: CoreFeature): Error {
|
package/src/tagSpec.ts
CHANGED
|
@@ -1,28 +1,55 @@
|
|
|
1
1
|
import { DirectiveLocation, GraphQLError } from "graphql";
|
|
2
2
|
import { FeatureDefinition, FeatureDefinitions, FeatureUrl, FeatureVersion } from "./coreSpec";
|
|
3
3
|
import { DirectiveDefinition, NonNullType, Schema } from "./definitions";
|
|
4
|
+
import { createDirectiveSpecification, DirectiveSpecification } from "./directiveAndTypeSpecification";
|
|
4
5
|
import { ERRORS } from "./error";
|
|
6
|
+
import { registerKnownFeature } from "./knownCoreFeatures";
|
|
5
7
|
import { sameType } from "./types";
|
|
6
8
|
|
|
7
9
|
export const tagIdentity = 'https://specs.apollo.dev/tag';
|
|
8
10
|
|
|
9
|
-
export const tagLocations = [
|
|
10
|
-
DirectiveLocation.FIELD_DEFINITION,
|
|
11
|
-
DirectiveLocation.OBJECT,
|
|
12
|
-
DirectiveLocation.INTERFACE,
|
|
13
|
-
DirectiveLocation.UNION,
|
|
14
|
-
];
|
|
15
|
-
|
|
16
|
-
const printedTagDefinition = 'directive @tag(name: String!) repeatable on FIELD_DEFINITION | INTERFACE | OBJECT | UNION';
|
|
17
|
-
|
|
18
11
|
export class TagSpecDefinition extends FeatureDefinition {
|
|
12
|
+
public readonly tagLocations: DirectiveLocation[];
|
|
13
|
+
public readonly tagDirectiveSpec: DirectiveSpecification;
|
|
14
|
+
private readonly printedTagDefinition: string;
|
|
15
|
+
|
|
19
16
|
constructor(version: FeatureVersion) {
|
|
20
17
|
super(new FeatureUrl(tagIdentity, 'tag', version));
|
|
18
|
+
this.tagLocations = [
|
|
19
|
+
DirectiveLocation.FIELD_DEFINITION,
|
|
20
|
+
DirectiveLocation.OBJECT,
|
|
21
|
+
DirectiveLocation.INTERFACE,
|
|
22
|
+
DirectiveLocation.UNION,
|
|
23
|
+
];
|
|
24
|
+
this.printedTagDefinition = 'directive @tag(name: String!) repeatable on FIELD_DEFINITION | INTERFACE | OBJECT | UNION';
|
|
25
|
+
if (!this.isV01()) {
|
|
26
|
+
this.tagLocations.push(
|
|
27
|
+
DirectiveLocation.ARGUMENT_DEFINITION,
|
|
28
|
+
DirectiveLocation.SCALAR,
|
|
29
|
+
DirectiveLocation.ENUM,
|
|
30
|
+
DirectiveLocation.ENUM_VALUE,
|
|
31
|
+
DirectiveLocation.INPUT_OBJECT,
|
|
32
|
+
DirectiveLocation.INPUT_FIELD_DEFINITION,
|
|
33
|
+
);
|
|
34
|
+
this.printedTagDefinition = 'directive @tag(name: String!) repeatable on FIELD_DEFINITION | INTERFACE | OBJECT | UNION | ARGUMENT_DEFINITION | SCALAR | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION';
|
|
35
|
+
}
|
|
36
|
+
this.tagDirectiveSpec = createDirectiveSpecification({
|
|
37
|
+
name:'tag',
|
|
38
|
+
locations: this.tagLocations,
|
|
39
|
+
repeatable: true,
|
|
40
|
+
argumentFct: (schema) => ({
|
|
41
|
+
args: [{ name: 'name', type: new NonNullType(schema.stringType()) }],
|
|
42
|
+
errors: [],
|
|
43
|
+
}),
|
|
44
|
+
});
|
|
21
45
|
}
|
|
22
46
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
47
|
+
private isV01() {
|
|
48
|
+
return this.version.equals(new FeatureVersion(0, 1));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
addElementsToSchema(schema: Schema): GraphQLError[] {
|
|
52
|
+
return this.addDirectiveSpec(schema, this.tagDirectiveSpec);
|
|
26
53
|
}
|
|
27
54
|
|
|
28
55
|
tagDirective(schema: Schema): DirectiveDefinition<{name: string}> {
|
|
@@ -33,16 +60,23 @@ export class TagSpecDefinition extends FeatureDefinition {
|
|
|
33
60
|
const hasUnknownArguments = Object.keys(definition.arguments()).length > 1;
|
|
34
61
|
const nameArg = definition.argument('name');
|
|
35
62
|
const hasValidNameArg = nameArg && sameType(nameArg.type!, new NonNullType(definition.schema().stringType()));
|
|
36
|
-
const hasValidLocations = definition.locations.every(loc => tagLocations.includes(loc));
|
|
63
|
+
const hasValidLocations = definition.locations.every(loc => this.tagLocations.includes(loc));
|
|
37
64
|
if (hasUnknownArguments || !hasValidNameArg || !hasValidLocations) {
|
|
38
65
|
return ERRORS.DIRECTIVE_DEFINITION_INVALID.err({
|
|
39
|
-
message: `Found invalid @tag directive definition. Please ensure the directive definition in your schema's definitions matches the following:\n\t${printedTagDefinition}`,
|
|
66
|
+
message: `Found invalid @tag directive definition. Please ensure the directive definition in your schema's definitions matches the following:\n\t${this.printedTagDefinition}`,
|
|
40
67
|
}
|
|
41
68
|
);
|
|
42
69
|
}
|
|
43
70
|
return undefined;
|
|
44
71
|
}
|
|
72
|
+
|
|
73
|
+
allElementNames(): string[] {
|
|
74
|
+
return ["@tag"];
|
|
75
|
+
}
|
|
45
76
|
}
|
|
46
77
|
|
|
47
78
|
export const TAG_VERSIONS = new FeatureDefinitions<TagSpecDefinition>(tagIdentity)
|
|
48
|
-
.add(new TagSpecDefinition(new FeatureVersion(0, 1)))
|
|
79
|
+
.add(new TagSpecDefinition(new FeatureVersion(0, 1)))
|
|
80
|
+
.add(new TagSpecDefinition(new FeatureVersion(0, 2)));
|
|
81
|
+
|
|
82
|
+
registerKnownFeature(TAG_VERSIONS);
|
package/src/validate.ts
CHANGED
|
@@ -129,13 +129,14 @@ class Validator {
|
|
|
129
129
|
return this.errors;
|
|
130
130
|
}
|
|
131
131
|
|
|
132
|
-
private validateHasType(elt: { type?: Type, coordinate: string, sourceAST?: ASTNode }) {
|
|
132
|
+
private validateHasType(elt: { type?: Type, coordinate: string, sourceAST?: ASTNode }): boolean {
|
|
133
133
|
// Note that this error can't happen if you parse the schema since it wouldn't be valid syntax, but it can happen for
|
|
134
134
|
// programmatically constructed schema.
|
|
135
135
|
if (!elt.type) {
|
|
136
136
|
this.errors.push(new GraphQLError(`Element ${elt.coordinate} does not have a type set`, elt.sourceAST));
|
|
137
137
|
this.hasMissingTypes = false;
|
|
138
138
|
}
|
|
139
|
+
return !!elt.type;
|
|
139
140
|
}
|
|
140
141
|
|
|
141
142
|
private validateName(elt: { name: string, sourceAST?: ASTNode}) {
|
|
@@ -183,8 +184,7 @@ class Validator {
|
|
|
183
184
|
// Note that we may not have validated the interface yet, so making sure we have a meaningful error
|
|
184
185
|
// if the type is not set, even if that means a bit of cpu wasted since we'll re-check later (and
|
|
185
186
|
// as many type as the interface is implemented); it's a cheap check anyway.
|
|
186
|
-
this.validateHasType(itfField)
|
|
187
|
-
if (!isSubtype(itfField.type!, field.type!)) {
|
|
187
|
+
if (this.validateHasType(itfField) && !isSubtype(itfField.type!, field.type!)) {
|
|
188
188
|
this.errors.push(new GraphQLError(
|
|
189
189
|
`Interface field ${itfField.coordinate} expects type ${itfField.type} but ${field.coordinate} of type ${field.type} is not a proper subtype.`,
|
|
190
190
|
sourceASTs(itfField, field)
|
|
@@ -200,10 +200,8 @@ class Validator {
|
|
|
200
200
|
));
|
|
201
201
|
continue;
|
|
202
202
|
}
|
|
203
|
-
// Same as above for the field
|
|
204
|
-
this.validateHasType(itfArg);
|
|
205
203
|
// Note that we could use contra-variance but as graphQL-js currently doesn't allow it, we mimic that.
|
|
206
|
-
if (!sameType(itfArg.type!, arg.type!)) {
|
|
204
|
+
if (this.validateHasType(itfArg) && !sameType(itfArg.type!, arg.type!)) {
|
|
207
205
|
this.errors.push(new GraphQLError(
|
|
208
206
|
`Interface field argument ${itfArg.coordinate} expects type ${itfArg.type} but ${arg.coordinate} is type ${arg.type}.`,
|
|
209
207
|
sourceASTs(itfArg, arg)
|
|
@@ -247,19 +245,29 @@ class Validator {
|
|
|
247
245
|
}
|
|
248
246
|
for (const field of type.fields()) {
|
|
249
247
|
this.validateName(field);
|
|
250
|
-
this.validateHasType(field)
|
|
248
|
+
if (!this.validateHasType(field)) {
|
|
249
|
+
continue;
|
|
250
|
+
}
|
|
251
251
|
if (field.isRequired() && field.isDeprecated()) {
|
|
252
252
|
this.errors.push(new GraphQLError(
|
|
253
253
|
`Required input field ${field.coordinate} cannot be deprecated.`,
|
|
254
254
|
sourceASTs(field.appliedDirectivesOf('deprecated')[0], field)
|
|
255
255
|
));
|
|
256
256
|
}
|
|
257
|
+
if (field.defaultValue !== undefined && !isValidValue(field.defaultValue, field, new VariableDefinitions())) {
|
|
258
|
+
this.errors.push(new GraphQLError(
|
|
259
|
+
`Invalid default value (got: ${valueToString(field.defaultValue)}) provided for input field ${field.coordinate} of type ${field.type}.`,
|
|
260
|
+
sourceASTs(field)
|
|
261
|
+
));
|
|
262
|
+
}
|
|
257
263
|
}
|
|
258
264
|
}
|
|
259
265
|
|
|
260
266
|
private validateArg(arg: ArgumentDefinition<any>) {
|
|
261
267
|
this.validateName(arg);
|
|
262
|
-
this.validateHasType(arg)
|
|
268
|
+
if (!this.validateHasType(arg)) {
|
|
269
|
+
return;
|
|
270
|
+
}
|
|
263
271
|
if (arg.isRequired() && arg.isDeprecated()) {
|
|
264
272
|
this.errors.push(new GraphQLError(
|
|
265
273
|
`Required argument ${arg.coordinate} cannot be deprecated.`,
|
|
@@ -305,7 +313,10 @@ class Validator {
|
|
|
305
313
|
// Again, that implies that value is not required.
|
|
306
314
|
continue;
|
|
307
315
|
}
|
|
308
|
-
if
|
|
316
|
+
// Note that we validate if the definition argument has a type set separatly
|
|
317
|
+
// and log an error if necesary, but we just want to avoid calling
|
|
318
|
+
// `isValidValue` if there is not type as it may throw.
|
|
319
|
+
if (argument.type && !isValidValue(value, argument, this.emptyVariables)) {
|
|
309
320
|
const parent = application.parent;
|
|
310
321
|
// The only non-named SchemaElement is the `schema` definition.
|
|
311
322
|
const parentDesc = parent instanceof NamedSchemaElement
|