-
Notifications
You must be signed in to change notification settings - Fork 259
/
Copy pathhints.ts
277 lines (239 loc) · 11.3 KB
/
hints.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
import { NamedSchemaElement, SubgraphASTNode } from "@apollo/federation-internals";
import { printLocation } from "graphql";
export enum HintLevel {
WARN = 60,
INFO = 40,
DEBUG = 20,
}
export type HintCodeDefinition = {
code: string,
// Note that we keep the name separately, because while it can be obtained easily enough
// with `HintLevel[value]` on the JS/TS-side, the name would otherwise be lost when
// serializing the related objects to JSON for rover.
level: { value: HintLevel, name: string},
description: string,
}
function makeCodeDefinition({
code,
level,
description,
}: {
code: string,
level: HintLevel,
description: string,
}): HintCodeDefinition {
return ({
code,
level: { value: level, name: HintLevel[level]},
description,
});
}
const INCONSISTENT_BUT_COMPATIBLE_FIELD_TYPE = makeCodeDefinition({
code: 'INCONSISTENT_BUT_COMPATIBLE_FIELD_TYPE',
level: HintLevel.INFO,
description: 'Indicates that a field does not have the exact same types in all subgraphs, but that the types are "compatible"'
+ ' (2 types are compatible if one is a non-nullable version of the other, a list version, a subtype, or a'
+ ' combination of the former).',
});
const INCONSISTENT_BUT_COMPATIBLE_ARGUMENT_TYPE = makeCodeDefinition({
code: 'INCONSISTENT_BUT_COMPATIBLE_ARGUMENT_TYPE',
level: HintLevel.INFO,
description: 'Indicates that an argument type (of a field/input field/directive definition) does not have the exact same type'
+ ' in all subgraphs, but that the types are "compatible" (two types are compatible if one is a non-nullable'
+ ' version of the other, a list version, a subtype, or a combination of the former).',
});
const INCONSISTENT_DEFAULT_VALUE_PRESENCE = makeCodeDefinition({
code: 'INCONSISTENT_DEFAULT_VALUE_PRESENCE',
level: HintLevel.WARN,
description: 'Indicates that an argument definition (of a field/input field/directive definition) has a default value in only'
+ ' some of the subgraphs that define the argument.',
});
const INCONSISTENT_ENTITY = makeCodeDefinition({
code: 'INCONSISTENT_ENTITY',
level: HintLevel.INFO,
description: 'Indicates that an object is declared as an entity (has a `@key`) in only some of the subgraphs in which the object is defined.',
});
const INCONSISTENT_OBJECT_VALUE_TYPE_FIELD = makeCodeDefinition({
code: 'INCONSISTENT_OBJECT_VALUE_TYPE_FIELD',
level: HintLevel.DEBUG,
description: 'Indicates that a field of an object "value type" (has no `@key` in any subgraph) is not defined in all the subgraphs that declare the type.',
});
const INCONSISTENT_INTERFACE_VALUE_TYPE_FIELD = makeCodeDefinition({
code: 'INCONSISTENT_INTERFACE_VALUE_TYPE_FIELD',
level: HintLevel.DEBUG,
description: 'Indicates that a field of an interface "value type" (has no `@key` in any subgraph) is not defined in all the subgraphs that declare the type.',
});
const INCONSISTENT_INPUT_OBJECT_FIELD = makeCodeDefinition({
code: 'INCONSISTENT_INPUT_OBJECT_FIELD',
level: HintLevel.WARN,
description: 'Indicates that a field of an input object type definition is only defined in a subset of the subgraphs that declare the input object.',
});
const INCONSISTENT_UNION_MEMBER = makeCodeDefinition({
code: 'INCONSISTENT_UNION_MEMBER',
level: HintLevel.DEBUG,
description: 'Indicates that a member of a union type definition is only defined in a subset of the subgraphs that declare the union.',
});
const INCONSISTENT_ENUM_VALUE_FOR_INPUT_ENUM = makeCodeDefinition({
code: 'INCONSISTENT_ENUM_VALUE_FOR_INPUT_ENUM',
level: HintLevel.WARN,
description: 'Indicates that a value of an enum type definition (that is only used as an Input type) has not been merged into the supergraph because it is defined in only a subset of the subgraphs that declare the enum',
});
const INCONSISTENT_ENUM_VALUE_FOR_OUTPUT_ENUM = makeCodeDefinition({
code: 'INCONSISTENT_ENUM_VALUE_FOR_OUTPUT_ENUM',
level: HintLevel.DEBUG,
description: 'Indicates that a value of an enum type definition (that is only used as an Output type, or is unused) has been merged in the supergraph but is defined in only a subset of the subgraphs that declare the enum',
});
const INCONSISTENT_TYPE_SYSTEM_DIRECTIVE_REPEATABLE = makeCodeDefinition({
code: 'INCONSISTENT_TYPE_SYSTEM_DIRECTIVE_REPEATABLE',
level: HintLevel.DEBUG,
description: 'Indicates that a type system directive definition is marked repeatable in only a subset of the subgraphs that declare the directive (and will be repeatable in the supergraph).',
});
const INCONSISTENT_TYPE_SYSTEM_DIRECTIVE_LOCATIONS = makeCodeDefinition({
code: 'INCONSISTENT_TYPE_SYSTEM_DIRECTIVE_LOCATIONS',
level: HintLevel.DEBUG,
description: 'Indicates that a type system directive definition is declared with inconsistent locations across subgraphs (and will use the union of all locations in the supergraph).',
});
const INCONSISTENT_EXECUTABLE_DIRECTIVE_PRESENCE = makeCodeDefinition({
code: 'INCONSISTENT_EXECUTABLE_DIRECTIVE_PRESENCE',
level: HintLevel.WARN,
description: 'Indicates that an executable directive definition is declared in only some of the subgraphs.',
});
const NO_EXECUTABLE_DIRECTIVE_LOCATIONS_INTERSECTION = makeCodeDefinition({
code: 'NO_EXECUTABLE_DIRECTIVE_INTERSECTION',
level: HintLevel.WARN,
description: 'Indicates that, for an executable directive definition, no location for it appears in all subgraphs.',
});
const INCONSISTENT_EXECUTABLE_DIRECTIVE_REPEATABLE = makeCodeDefinition({
code: 'INCONSISTENT_EXECUTABLE_DIRECTIVE_REPEATABLE',
level: HintLevel.WARN,
description: 'Indicates that an executable directive definition is marked repeatable in only a subset of the subgraphs (and will not be repeatable in the supergraph).',
});
const INCONSISTENT_EXECUTABLE_DIRECTIVE_LOCATIONS = makeCodeDefinition({
code: 'INCONSISTENT_EXECUTABLE_DIRECTIVE_LOCATIONS',
level: HintLevel.WARN,
description: 'Indicates that an executiable directive definition is declared with inconsistent locations across subgraphs (and will use the intersection of all locations in the supergraph).',
});
const INCONSISTENT_DESCRIPTION = makeCodeDefinition({
code: 'INCONSISTENT_DESCRIPTION',
level: HintLevel.WARN,
description: 'Indicates that an element has a description in more than one subgraph, and the descriptions are not equal.',
});
const INCONSISTENT_ARGUMENT_PRESENCE = makeCodeDefinition({
code: 'INCONSISTENT_ARGUMENT_PRESENCE',
level: HintLevel.WARN,
description: 'Indicates that an optional argument (of a field or directive definition) is not present in all subgraphs and will not be part of the supergraph.',
});
const FROM_SUBGRAPH_DOES_NOT_EXIST = makeCodeDefinition({
code: 'FROM_SUBGRAPH_DOES_NOT_EXIST',
level: HintLevel.WARN,
description: 'Source subgraph specified by @override directive does not exist',
});
const OVERRIDDEN_FIELD_CAN_BE_REMOVED = makeCodeDefinition({
code: 'OVERRIDDEN_FIELD_CAN_BE_REMOVED',
level: HintLevel.INFO,
description: 'Field has been overridden by another subgraph. Consider removing.',
});
const OVERRIDE_DIRECTIVE_CAN_BE_REMOVED = makeCodeDefinition({
code: 'OVERRIDE_DIRECTIVE_CAN_BE_REMOVED',
level: HintLevel.INFO,
description: 'Field with @override directive no longer exists in source subgraph, the directive can be safely removed',
});
const UNUSED_ENUM_TYPE = makeCodeDefinition({
code: 'UNUSED_ENUM_TYPE',
level: HintLevel.DEBUG,
description: 'Indicates that an enum type is defined in some subgraphs but is unused (no field/argument references it). All the values from subgraphs defining that enum will be included in the supergraph.',
});
const INCONSISTENT_NON_REPEATABLE_DIRECTIVE_ARGUMENTS = makeCodeDefinition({
code: 'INCONSISTENT_NON_REPEATABLE_DIRECTIVE_ARGUMENTS',
level: HintLevel.WARN,
description: 'A non-repeatable directive is applied to a schema element in different subgraphs but with arguments that are different.',
});
const MERGED_NON_REPEATABLE_DIRECTIVE_ARGUMENTS = makeCodeDefinition({
code: 'MERGED_NON_REPEATABLE_DIRECTIVE_ARGUMENTS',
level: HintLevel.INFO,
description: 'A non-repeatable directive has been applied to a schema element in different subgraphs with different arguments and the arguments values were merged using the directive configured strategies.',
});
const DIRECTIVE_COMPOSITION_INFO = makeCodeDefinition({
code: 'DIRECTIVE_COMPOSITION_INFO',
level: HintLevel.INFO,
description: 'Indicates that an issue was detected when composing custom directives.',
});
const DIRECTIVE_COMPOSITION_WARN = makeCodeDefinition({
code: 'DIRECTIVE_COMPOSITION_WARN',
level: HintLevel.WARN,
description: 'Indicates that an issue was detected when composing custom directives.',
});
const INCONSISTENT_RUNTIME_TYPES_FOR_SHAREABLE_RETURN = makeCodeDefinition({
code: 'INCONSISTENT_RUNTIME_TYPES_FOR_SHAREABLE_RETURN',
level: HintLevel.WARN,
description: 'Indicates that a @shareable field returns different sets of runtime types in the different subgraphs in which it is defined.',
});
const IMPLICITLY_UPGRADED_FEDERATION_VERSION = makeCodeDefinition({
code: 'IMPLICITLY_UPGRADED_FEDERATION_VERSION',
level: HintLevel.INFO,
description: 'Indicates that a directive requires a higher federation version than is explicitly linked.'
+ ' In this case, the supergraph uses the federation version required by the directive.'
});
export const HINTS = {
INCONSISTENT_BUT_COMPATIBLE_FIELD_TYPE,
INCONSISTENT_BUT_COMPATIBLE_ARGUMENT_TYPE,
INCONSISTENT_DEFAULT_VALUE_PRESENCE,
INCONSISTENT_ENTITY,
INCONSISTENT_OBJECT_VALUE_TYPE_FIELD,
INCONSISTENT_INTERFACE_VALUE_TYPE_FIELD,
INCONSISTENT_INPUT_OBJECT_FIELD,
INCONSISTENT_UNION_MEMBER,
INCONSISTENT_ENUM_VALUE_FOR_INPUT_ENUM,
INCONSISTENT_ENUM_VALUE_FOR_OUTPUT_ENUM,
INCONSISTENT_TYPE_SYSTEM_DIRECTIVE_REPEATABLE,
INCONSISTENT_TYPE_SYSTEM_DIRECTIVE_LOCATIONS,
INCONSISTENT_EXECUTABLE_DIRECTIVE_PRESENCE,
NO_EXECUTABLE_DIRECTIVE_LOCATIONS_INTERSECTION,
INCONSISTENT_EXECUTABLE_DIRECTIVE_REPEATABLE,
INCONSISTENT_EXECUTABLE_DIRECTIVE_LOCATIONS,
INCONSISTENT_DESCRIPTION,
INCONSISTENT_ARGUMENT_PRESENCE,
FROM_SUBGRAPH_DOES_NOT_EXIST,
OVERRIDDEN_FIELD_CAN_BE_REMOVED,
OVERRIDE_DIRECTIVE_CAN_BE_REMOVED,
UNUSED_ENUM_TYPE,
INCONSISTENT_NON_REPEATABLE_DIRECTIVE_ARGUMENTS,
MERGED_NON_REPEATABLE_DIRECTIVE_ARGUMENTS,
DIRECTIVE_COMPOSITION_INFO,
DIRECTIVE_COMPOSITION_WARN,
INCONSISTENT_RUNTIME_TYPES_FOR_SHAREABLE_RETURN,
IMPLICITLY_UPGRADED_FEDERATION_VERSION,
}
export class CompositionHint {
public readonly nodes?: readonly SubgraphASTNode[];
public readonly coordinate?: string;
constructor(
readonly definition: HintCodeDefinition,
readonly message: string,
readonly element: NamedSchemaElement<any, any, any> | undefined,
nodes?: readonly SubgraphASTNode[] | SubgraphASTNode
) {
this.nodes = nodes
? (Array.isArray(nodes) ? (nodes.length === 0 ? undefined : nodes) : [nodes])
: undefined;
this.coordinate = element?.coordinate;
}
toString(): string {
return `[${this.definition.code}]: ${this.message}`
}
}
/**
* Prints a composition hint to a string, alongside useful location information
* about relevant positions in the subgraph sources.
*/
export function printHint(hint: CompositionHint): string {
let output = hint.toString();
if (hint.nodes) {
for (const node of hint.nodes) {
if (node.loc) {
output += '\n\n' + printLocation(node.loc);
}
}
}
return output;
}