@apollo/federation-internals 2.4.4 → 2.4.6
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/Subgraph.d.ts +1 -0
- package/dist/Subgraph.d.ts.map +1 -0
- package/dist/Subgraph.js +2 -0
- package/dist/Subgraph.js.map +1 -0
- package/dist/argumentCompositionStrategies.d.ts +34 -0
- package/dist/argumentCompositionStrategies.d.ts.map +1 -0
- package/dist/argumentCompositionStrategies.js +35 -0
- package/dist/argumentCompositionStrategies.js.map +1 -0
- package/dist/buildSchema.d.ts +10 -0
- package/dist/buildSchema.d.ts.map +1 -0
- package/dist/buildSchema.js +362 -0
- package/dist/buildSchema.js.map +1 -0
- package/dist/coreSpec.d.ts +127 -0
- package/dist/coreSpec.d.ts.map +1 -0
- package/dist/coreSpec.js +590 -0
- package/dist/coreSpec.js.map +1 -0
- package/dist/debug.d.ts +15 -0
- package/dist/debug.d.ts.map +1 -0
- package/dist/debug.js +122 -0
- package/dist/debug.js.map +1 -0
- package/dist/definitions.d.ts +663 -0
- package/dist/definitions.d.ts.map +1 -0
- package/dist/definitions.js +2841 -0
- package/dist/definitions.js.map +1 -0
- package/dist/directiveAndTypeSpecification.d.ts +67 -0
- package/dist/directiveAndTypeSpecification.d.ts.map +1 -0
- package/dist/directiveAndTypeSpecification.js +271 -0
- package/dist/directiveAndTypeSpecification.js.map +1 -0
- package/dist/error.d.ts +128 -0
- package/dist/error.d.ts.map +1 -0
- package/dist/error.js +315 -0
- package/dist/error.js.map +1 -0
- package/dist/extractSubgraphsFromSupergraph.d.ts +8 -0
- package/dist/extractSubgraphsFromSupergraph.d.ts.map +1 -0
- package/dist/extractSubgraphsFromSupergraph.js +576 -0
- package/dist/extractSubgraphsFromSupergraph.js.map +1 -0
- package/dist/federation.d.ts +175 -0
- package/dist/federation.d.ts.map +1 -0
- package/dist/federation.js +1414 -0
- package/dist/federation.js.map +1 -0
- package/dist/federationSpec.d.ts +25 -0
- package/dist/federationSpec.d.ts.map +1 -0
- package/dist/federationSpec.js +125 -0
- package/dist/federationSpec.js.map +1 -0
- package/dist/genErrorCodeDoc.d.ts +2 -0
- package/dist/genErrorCodeDoc.d.ts.map +1 -0
- package/dist/genErrorCodeDoc.js +61 -0
- package/dist/genErrorCodeDoc.js.map +1 -0
- package/dist/graphQLJSSchemaToAST.d.ts +8 -0
- package/dist/graphQLJSSchemaToAST.d.ts.map +1 -0
- package/dist/graphQLJSSchemaToAST.js +96 -0
- package/dist/graphQLJSSchemaToAST.js.map +1 -0
- package/dist/inaccessibleSpec.d.ts +18 -0
- package/dist/inaccessibleSpec.d.ts.map +1 -0
- package/dist/inaccessibleSpec.js +655 -0
- package/dist/inaccessibleSpec.js.map +1 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +42 -0
- package/dist/index.js.map +1 -0
- package/dist/introspection.d.ts +6 -0
- package/dist/introspection.d.ts.map +1 -0
- package/dist/introspection.js +96 -0
- package/dist/introspection.js.map +1 -0
- package/dist/joinSpec.d.ts +51 -0
- package/dist/joinSpec.d.ts.map +1 -0
- package/dist/joinSpec.js +160 -0
- package/dist/joinSpec.js.map +1 -0
- package/dist/knownCoreFeatures.d.ts +5 -0
- package/dist/knownCoreFeatures.d.ts.map +1 -0
- package/dist/knownCoreFeatures.js +20 -0
- package/dist/knownCoreFeatures.js.map +1 -0
- package/dist/operations.d.ts +418 -0
- package/dist/operations.d.ts.map +1 -0
- package/dist/operations.js +2068 -0
- package/dist/operations.js.map +1 -0
- package/dist/precompute.d.ts +3 -0
- package/dist/precompute.d.ts.map +1 -0
- package/dist/precompute.js +54 -0
- package/dist/precompute.js.map +1 -0
- package/dist/print.d.ts +28 -0
- package/dist/print.d.ts.map +1 -0
- package/dist/print.js +299 -0
- package/dist/print.js.map +1 -0
- package/dist/schemaUpgrader.d.ts +121 -0
- package/dist/schemaUpgrader.d.ts.map +1 -0
- package/dist/schemaUpgrader.js +570 -0
- package/dist/schemaUpgrader.js.map +1 -0
- package/dist/suggestions.d.ts +3 -0
- package/dist/suggestions.d.ts.map +1 -0
- package/dist/suggestions.js +44 -0
- package/dist/suggestions.js.map +1 -0
- package/dist/supergraphs.d.ts +10 -0
- package/dist/supergraphs.d.ts.map +1 -0
- package/dist/supergraphs.js +76 -0
- package/dist/supergraphs.js.map +1 -0
- package/dist/tagSpec.d.ts +19 -0
- package/dist/tagSpec.d.ts.map +1 -0
- package/dist/tagSpec.js +66 -0
- package/dist/tagSpec.js.map +1 -0
- package/dist/types.d.ts +9 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +64 -0
- package/dist/types.js.map +1 -0
- package/dist/utils.d.ts +64 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +326 -0
- package/dist/utils.js.map +1 -0
- package/dist/validate.d.ts +4 -0
- package/dist/validate.d.ts.map +1 -0
- package/dist/validate.js +239 -0
- package/dist/validate.js.map +1 -0
- package/dist/validation/KnownTypeNamesInFederationRule.d.ts +4 -0
- package/dist/validation/KnownTypeNamesInFederationRule.d.ts.map +1 -0
- package/dist/validation/KnownTypeNamesInFederationRule.js +41 -0
- package/dist/validation/KnownTypeNamesInFederationRule.js.map +1 -0
- package/dist/values.d.ts +23 -0
- package/dist/values.d.ts.map +1 -0
- package/dist/values.js +580 -0
- package/dist/values.js.map +1 -0
- package/package.json +1 -1
- package/src/operations.ts +145 -20
- package/src/utils.ts +1 -1
- package/CHANGELOG.md +0 -205
- package/jest.config.js +0 -11
- package/src/__tests__/coreSpec.test.ts +0 -212
- package/src/__tests__/definitions.test.ts +0 -982
- package/src/__tests__/directiveAndTypeSpecifications.test.ts +0 -41
- package/src/__tests__/extractSubgraphsFromSupergraph.test.ts +0 -748
- package/src/__tests__/federation.test.ts +0 -31
- package/src/__tests__/graphQLJSSchemaToAST.test.ts +0 -156
- package/src/__tests__/matchers/index.ts +0 -1
- package/src/__tests__/matchers/toMatchString.ts +0 -87
- package/src/__tests__/operations.test.ts +0 -1266
- package/src/__tests__/removeInaccessibleElements.test.ts +0 -2471
- package/src/__tests__/schemaUpgrader.test.ts +0 -287
- package/src/__tests__/subgraphValidation.test.ts +0 -1254
- package/src/__tests__/supergraphSdl.graphql +0 -281
- package/src/__tests__/testUtils.ts +0 -28
- package/src/__tests__/toAPISchema.test.ts +0 -53
- package/src/__tests__/tsconfig.json +0 -7
- package/src/__tests__/utils.test.ts +0 -92
- package/src/__tests__/values.test.ts +0 -390
- package/tsconfig.json +0 -10
- package/tsconfig.test.json +0 -8
|
@@ -1,2471 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ArgumentDefinition,
|
|
3
|
-
FieldDefinition,
|
|
4
|
-
InterfaceType,
|
|
5
|
-
ObjectType,
|
|
6
|
-
UnionType,
|
|
7
|
-
} from "../definitions";
|
|
8
|
-
import { buildSchema } from "../buildSchema";
|
|
9
|
-
import { removeInaccessibleElements } from "../inaccessibleSpec";
|
|
10
|
-
import { GraphQLError } from "graphql";
|
|
11
|
-
import { errorCauses } from "../error";
|
|
12
|
-
|
|
13
|
-
describe("removeInaccessibleElements", () => {
|
|
14
|
-
const INACCESSIBLE_V02_HEADER = `
|
|
15
|
-
directive @core(feature: String!, as: String, for: core__Purpose) repeatable on SCHEMA
|
|
16
|
-
|
|
17
|
-
enum core__Purpose {
|
|
18
|
-
EXECUTION
|
|
19
|
-
SECURITY
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
directive @inaccessible on FIELD_DEFINITION | OBJECT | INTERFACE | UNION | ARGUMENT_DEFINITION | SCALAR | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION
|
|
23
|
-
|
|
24
|
-
schema
|
|
25
|
-
@core(feature: "https://specs.apollo.dev/core/v0.2")
|
|
26
|
-
@core(feature: "https://specs.apollo.dev/inaccessible/v0.2")
|
|
27
|
-
{
|
|
28
|
-
query: Query
|
|
29
|
-
}
|
|
30
|
-
`;
|
|
31
|
-
|
|
32
|
-
function getCauses(e: unknown): GraphQLError[] {
|
|
33
|
-
const causes = errorCauses(e as Error);
|
|
34
|
-
expect(causes).toBeDefined();
|
|
35
|
-
expect(Array.isArray(causes)).toBeTruthy();
|
|
36
|
-
for (const cause of causes!) {
|
|
37
|
-
expect(cause instanceof GraphQLError).toBeTruthy();
|
|
38
|
-
}
|
|
39
|
-
return causes!;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function expectErrors(expectedCauseCount: number, f: () => void): string[] {
|
|
43
|
-
let error: unknown = undefined;
|
|
44
|
-
try {
|
|
45
|
-
f();
|
|
46
|
-
} catch (e) {
|
|
47
|
-
error = e;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
expect(error).toBeDefined();
|
|
51
|
-
const causes = getCauses(error);
|
|
52
|
-
expect(causes).toHaveLength(expectedCauseCount);
|
|
53
|
-
const messages = causes.map((cause) => cause.message);
|
|
54
|
-
for (const message of messages) {
|
|
55
|
-
expect(typeof message === "string").toBeTruthy();
|
|
56
|
-
}
|
|
57
|
-
messages.sort();
|
|
58
|
-
return messages;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
it(`succeeds for no inaccessible spec`, () => {
|
|
62
|
-
const schema = buildSchema(`
|
|
63
|
-
directive @core(feature: String!, as: String, for: core__Purpose) repeatable on SCHEMA
|
|
64
|
-
|
|
65
|
-
enum core__Purpose {
|
|
66
|
-
EXECUTION
|
|
67
|
-
SECURITY
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
schema
|
|
71
|
-
@core(feature: "https://specs.apollo.dev/core/v0.2")
|
|
72
|
-
{
|
|
73
|
-
query: Query
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
type Query {
|
|
77
|
-
someField: String
|
|
78
|
-
}
|
|
79
|
-
`);
|
|
80
|
-
|
|
81
|
-
removeInaccessibleElements(schema);
|
|
82
|
-
schema.validate();
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
it(`doesn't affect non-core @inaccessible`, () => {
|
|
86
|
-
const schema = buildSchema(`
|
|
87
|
-
directive @core(feature: String!, as: String, for: core__Purpose) repeatable on SCHEMA
|
|
88
|
-
|
|
89
|
-
enum core__Purpose {
|
|
90
|
-
EXECUTION
|
|
91
|
-
SECURITY
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
schema
|
|
95
|
-
@core(feature: "https://specs.apollo.dev/core/v0.2")
|
|
96
|
-
{
|
|
97
|
-
query: Query
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
type Query {
|
|
101
|
-
someField: String @inaccessible
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
directive @inaccessible on FIELD_DEFINITION | OBJECT | INTERFACE | UNION | ARGUMENT_DEFINITION | SCALAR | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION
|
|
105
|
-
`);
|
|
106
|
-
|
|
107
|
-
removeInaccessibleElements(schema);
|
|
108
|
-
schema.validate();
|
|
109
|
-
expect(schema.elementByCoordinate("Query.someField")).toBeDefined();
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
it(`fails for no @inaccessible definition`, () => {
|
|
113
|
-
const schema = buildSchema(`
|
|
114
|
-
directive @core(feature: String!, as: String, for: core__Purpose) repeatable on SCHEMA
|
|
115
|
-
|
|
116
|
-
enum core__Purpose {
|
|
117
|
-
EXECUTION
|
|
118
|
-
SECURITY
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
schema
|
|
122
|
-
@core(feature: "https://specs.apollo.dev/core/v0.2")
|
|
123
|
-
@core(feature: "https://specs.apollo.dev/inaccessible/v0.1")
|
|
124
|
-
{
|
|
125
|
-
query: Query
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
type Query {
|
|
129
|
-
someField: String
|
|
130
|
-
}
|
|
131
|
-
`);
|
|
132
|
-
|
|
133
|
-
const errorMessages = expectErrors(1, () => {
|
|
134
|
-
removeInaccessibleElements(schema);
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
expect(errorMessages).toMatchInlineSnapshot(`
|
|
138
|
-
Array [
|
|
139
|
-
"Invalid schema: declares https://specs.apollo.dev/inaccessible/v0.1 spec but does not define a @inaccessible directive.",
|
|
140
|
-
]
|
|
141
|
-
`);
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
it(`fails for incompatible @inaccessible definition`, () => {
|
|
145
|
-
const schema = buildSchema(`
|
|
146
|
-
directive @core(feature: String!, as: String, for: core__Purpose) repeatable on SCHEMA
|
|
147
|
-
|
|
148
|
-
enum core__Purpose {
|
|
149
|
-
EXECUTION
|
|
150
|
-
SECURITY
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
directive @inaccessible on FIELD_DEFINITION | OBJECT | INTERFACE | UNION | ARGUMENT_DEFINITION | SCALAR | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION
|
|
154
|
-
|
|
155
|
-
schema
|
|
156
|
-
@core(feature: "https://specs.apollo.dev/core/v0.2")
|
|
157
|
-
@core(feature: "https://specs.apollo.dev/inaccessible/v0.1")
|
|
158
|
-
{
|
|
159
|
-
query: Query
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
type Query {
|
|
163
|
-
someField: String
|
|
164
|
-
}
|
|
165
|
-
`);
|
|
166
|
-
|
|
167
|
-
const errorMessages = expectErrors(1, () => {
|
|
168
|
-
removeInaccessibleElements(schema);
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
expect(errorMessages).toMatchInlineSnapshot(`
|
|
172
|
-
Array [
|
|
173
|
-
"Found invalid @inaccessible directive definition. Please ensure the directive definition in your schema's definitions matches the following:
|
|
174
|
-
directive @inaccessible on FIELD_DEFINITION | INTERFACE | OBJECT | UNION",
|
|
175
|
-
]
|
|
176
|
-
`);
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
it(`handles renames of @inaccessible via core "as"`, () => {
|
|
180
|
-
const schema = buildSchema(`
|
|
181
|
-
directive @core(feature: String!, as: String, for: core__Purpose) repeatable on SCHEMA
|
|
182
|
-
|
|
183
|
-
enum core__Purpose {
|
|
184
|
-
EXECUTION
|
|
185
|
-
SECURITY
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
directive @foo on FIELD_DEFINITION | OBJECT | INTERFACE | UNION | ARGUMENT_DEFINITION | SCALAR | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION
|
|
189
|
-
|
|
190
|
-
schema
|
|
191
|
-
@core(feature: "https://specs.apollo.dev/core/v0.2")
|
|
192
|
-
@core(feature: "https://specs.apollo.dev/inaccessible/v0.2", as: "foo")
|
|
193
|
-
{
|
|
194
|
-
query: Query
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
type Query {
|
|
198
|
-
someField: Bar @inaccessible
|
|
199
|
-
privateField: String @foo
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
scalar Bar
|
|
203
|
-
|
|
204
|
-
directive @inaccessible on FIELD_DEFINITION | OBJECT | INTERFACE | UNION | ARGUMENT_DEFINITION | SCALAR | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION
|
|
205
|
-
`);
|
|
206
|
-
|
|
207
|
-
removeInaccessibleElements(schema);
|
|
208
|
-
schema.validate();
|
|
209
|
-
expect(schema.elementByCoordinate("Query.someField")).toBeDefined();
|
|
210
|
-
expect(schema.elementByCoordinate("Query.privateField")).toBeUndefined();
|
|
211
|
-
});
|
|
212
|
-
|
|
213
|
-
it(`handles renames of @inaccessible via import "as"`, () => {
|
|
214
|
-
const schema = buildSchema(`
|
|
215
|
-
directive @link(url: String, as: String, for: link__Purpose, import: [link__Import]) repeatable on SCHEMA
|
|
216
|
-
|
|
217
|
-
enum link__Purpose {
|
|
218
|
-
EXECUTION
|
|
219
|
-
SECURITY
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
scalar link__Import
|
|
223
|
-
|
|
224
|
-
directive @foo on FIELD_DEFINITION | OBJECT | INTERFACE | UNION | ARGUMENT_DEFINITION | SCALAR | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION
|
|
225
|
-
|
|
226
|
-
schema
|
|
227
|
-
@link(url: "https://specs.apollo.dev/link/v1.0")
|
|
228
|
-
@link(url: "https://specs.apollo.dev/inaccessible/v0.2", import: [{name: "@inaccessible", as: "@foo"}])
|
|
229
|
-
{
|
|
230
|
-
query: Query
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
type Query {
|
|
234
|
-
someField: Bar @inaccessible
|
|
235
|
-
privateField: String @foo
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
scalar Bar
|
|
239
|
-
|
|
240
|
-
directive @inaccessible on FIELD_DEFINITION | OBJECT | INTERFACE | UNION | ARGUMENT_DEFINITION | SCALAR | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION
|
|
241
|
-
`);
|
|
242
|
-
|
|
243
|
-
removeInaccessibleElements(schema);
|
|
244
|
-
schema.validate();
|
|
245
|
-
expect(schema.elementByCoordinate("Query.someField")).toBeDefined();
|
|
246
|
-
expect(schema.elementByCoordinate("Query.privateField")).toBeUndefined();
|
|
247
|
-
});
|
|
248
|
-
|
|
249
|
-
it(`fails for @inaccessible built-ins`, () => {
|
|
250
|
-
const schema = buildSchema(`
|
|
251
|
-
${INACCESSIBLE_V02_HEADER}
|
|
252
|
-
|
|
253
|
-
type Query {
|
|
254
|
-
someField: String
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
# Built-in scalar
|
|
258
|
-
scalar String @inaccessible
|
|
259
|
-
|
|
260
|
-
# Built-in directive
|
|
261
|
-
directive @deprecated(
|
|
262
|
-
reason: String = "No longer supported" @inaccessible
|
|
263
|
-
) on FIELD_DEFINITION | ENUM_VALUE
|
|
264
|
-
`);
|
|
265
|
-
|
|
266
|
-
const errorMessages = expectErrors(2, () => {
|
|
267
|
-
removeInaccessibleElements(schema);
|
|
268
|
-
});
|
|
269
|
-
|
|
270
|
-
expect(errorMessages).toMatchInlineSnapshot(`
|
|
271
|
-
Array [
|
|
272
|
-
"Built-in directive \\"@deprecated\\" cannot use @inaccessible.",
|
|
273
|
-
"Built-in type \\"String\\" cannot use @inaccessible.",
|
|
274
|
-
]
|
|
275
|
-
`);
|
|
276
|
-
});
|
|
277
|
-
|
|
278
|
-
it(`fails for @inaccessible core feature definitions`, () => {
|
|
279
|
-
const schema = buildSchema(`
|
|
280
|
-
directive @core(feature: String! @inaccessible, as: String, for: core__Purpose) repeatable on SCHEMA
|
|
281
|
-
|
|
282
|
-
enum core__Purpose {
|
|
283
|
-
EXECUTION @inaccessible
|
|
284
|
-
SECURITY
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
directive @inaccessible on FIELD_DEFINITION | OBJECT | INTERFACE | UNION | ARGUMENT_DEFINITION | SCALAR | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION
|
|
288
|
-
|
|
289
|
-
schema
|
|
290
|
-
@core(feature: "https://specs.apollo.dev/core/v0.2")
|
|
291
|
-
@core(feature: "https://specs.apollo.dev/inaccessible/v0.2")
|
|
292
|
-
@core(feature: "http://localhost/foo/v1.0")
|
|
293
|
-
{
|
|
294
|
-
query: Query
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
type Query {
|
|
298
|
-
someField: String!
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
# Object type
|
|
302
|
-
type foo__Object1 @inaccessible {
|
|
303
|
-
foo__Field: String!
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
# Object field
|
|
307
|
-
type foo__Object2 implements foo__Interface2 {
|
|
308
|
-
foo__Field: foo__Enum1! @inaccessible
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
# Object field argument
|
|
312
|
-
type foo__Object3 {
|
|
313
|
-
someField(someArg: foo__Enum1 @inaccessible): foo__Enum2!
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
# Interface type
|
|
317
|
-
interface foo__Interface1 @inaccessible {
|
|
318
|
-
foo__Field: String!
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
# Interface field
|
|
322
|
-
interface foo__Interface2 {
|
|
323
|
-
foo__Field: foo__Enum1! @inaccessible
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
# Interface field argument
|
|
327
|
-
interface foo__Interface3 {
|
|
328
|
-
someField(someArg: foo__InputObject1 @inaccessible): foo__Enum2!
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
# Union type
|
|
332
|
-
union foo__Union @inaccessible = foo__Object1 | foo__Object2 | foo__Object3
|
|
333
|
-
|
|
334
|
-
# Input object type
|
|
335
|
-
input foo__InputObject1 @inaccessible {
|
|
336
|
-
someField: foo__Enum1
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
# Input object field
|
|
340
|
-
input foo__InputObject2 {
|
|
341
|
-
someField: foo__Scalar @inaccessible
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
# Enum type
|
|
345
|
-
enum foo__Enum1 @inaccessible {
|
|
346
|
-
someValue
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
# Enum value
|
|
350
|
-
enum foo__Enum2 {
|
|
351
|
-
someValue @inaccessible
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
# Scalar type
|
|
355
|
-
scalar foo__Scalar @inaccessible
|
|
356
|
-
|
|
357
|
-
# Directive argument
|
|
358
|
-
directive @foo(arg: foo__InputObject2 @inaccessible) repeatable on OBJECT
|
|
359
|
-
`);
|
|
360
|
-
|
|
361
|
-
// 15 = 6 type kinds + 3 field kinds + 3 argument kinds + 1 enum value + 2 extras on special core elements
|
|
362
|
-
const errorMessages = expectErrors(15, () => {
|
|
363
|
-
removeInaccessibleElements(schema);
|
|
364
|
-
});
|
|
365
|
-
|
|
366
|
-
expect(errorMessages).toMatchInlineSnapshot(`
|
|
367
|
-
Array [
|
|
368
|
-
"Core feature directive \\"@core\\" cannot use @inaccessible.",
|
|
369
|
-
"Core feature directive \\"@foo\\" cannot use @inaccessible.",
|
|
370
|
-
"Core feature type \\"core__Purpose\\" cannot use @inaccessible.",
|
|
371
|
-
"Core feature type \\"foo__Enum1\\" cannot use @inaccessible.",
|
|
372
|
-
"Core feature type \\"foo__Enum2\\" cannot use @inaccessible.",
|
|
373
|
-
"Core feature type \\"foo__InputObject1\\" cannot use @inaccessible.",
|
|
374
|
-
"Core feature type \\"foo__InputObject2\\" cannot use @inaccessible.",
|
|
375
|
-
"Core feature type \\"foo__Interface1\\" cannot use @inaccessible.",
|
|
376
|
-
"Core feature type \\"foo__Interface2\\" cannot use @inaccessible.",
|
|
377
|
-
"Core feature type \\"foo__Interface3\\" cannot use @inaccessible.",
|
|
378
|
-
"Core feature type \\"foo__Object1\\" cannot use @inaccessible.",
|
|
379
|
-
"Core feature type \\"foo__Object2\\" cannot use @inaccessible.",
|
|
380
|
-
"Core feature type \\"foo__Object3\\" cannot use @inaccessible.",
|
|
381
|
-
"Core feature type \\"foo__Scalar\\" cannot use @inaccessible.",
|
|
382
|
-
"Core feature type \\"foo__Union\\" cannot use @inaccessible.",
|
|
383
|
-
]
|
|
384
|
-
`);
|
|
385
|
-
});
|
|
386
|
-
|
|
387
|
-
it(`fails for @inaccessible directive definitions that aren't only executable`, () => {
|
|
388
|
-
const schema = buildSchema(`
|
|
389
|
-
${INACCESSIBLE_V02_HEADER}
|
|
390
|
-
|
|
391
|
-
type Query {
|
|
392
|
-
someField: String
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
directive @foo(arg1: String @inaccessible) repeatable on OBJECT
|
|
396
|
-
|
|
397
|
-
directive @bar(arg2: String, arg3: String @inaccessible) repeatable on SCHEMA | FIELD
|
|
398
|
-
`);
|
|
399
|
-
|
|
400
|
-
const errorMessages = expectErrors(2, () => {
|
|
401
|
-
removeInaccessibleElements(schema);
|
|
402
|
-
});
|
|
403
|
-
|
|
404
|
-
expect(errorMessages).toMatchInlineSnapshot(`
|
|
405
|
-
Array [
|
|
406
|
-
"Directive \\"@bar\\" cannot use @inaccessible because it may be applied to these type-system locations: SCHEMA.",
|
|
407
|
-
"Directive \\"@foo\\" cannot use @inaccessible because it may be applied to these type-system locations: OBJECT.",
|
|
408
|
-
]
|
|
409
|
-
`);
|
|
410
|
-
});
|
|
411
|
-
|
|
412
|
-
it(`removes @inaccessible object types`, () => {
|
|
413
|
-
const schema = buildSchema(`
|
|
414
|
-
${INACCESSIBLE_V02_HEADER}
|
|
415
|
-
|
|
416
|
-
extend schema {
|
|
417
|
-
mutation: Mutation
|
|
418
|
-
subscription: Subscription
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
# Non-inaccessible object type
|
|
422
|
-
type Query {
|
|
423
|
-
someField: String
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
# Inaccessible mutation types should be removed
|
|
427
|
-
type Mutation @inaccessible {
|
|
428
|
-
someObject: Object
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
# Inaccessible subscription types should be removed
|
|
432
|
-
type Subscription @inaccessible {
|
|
433
|
-
someField: String
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
# Inaccessible object type
|
|
437
|
-
type Object @inaccessible {
|
|
438
|
-
someField: String
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
# Inaccessible object type referenced by inaccessible object field
|
|
442
|
-
type Referencer1 implements Referencer3 {
|
|
443
|
-
someField: String
|
|
444
|
-
privatefield: Object! @inaccessible
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
# Inaccessible object type referenced by non-inaccessible object field
|
|
448
|
-
# with inaccessible parent
|
|
449
|
-
type Referencer2 implements Referencer4 @inaccessible {
|
|
450
|
-
privateField: [Object!]!
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
# Inaccessible object type referenced by inaccessible interface field
|
|
454
|
-
interface Referencer3 {
|
|
455
|
-
someField: String
|
|
456
|
-
privatefield: Object @inaccessible
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
# Inaccessible object type referenced by non-inaccessible interface field
|
|
460
|
-
# with inaccessible parent
|
|
461
|
-
interface Referencer4 @inaccessible {
|
|
462
|
-
privateField: [Object]
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
# Inaccessible object type referenced by union member with
|
|
466
|
-
# non-inaccessible siblings and parent
|
|
467
|
-
union Referencer5 = Query | Object
|
|
468
|
-
|
|
469
|
-
# Inaccessible object type referenced by union member with no siblings
|
|
470
|
-
# but with inaccessible parent
|
|
471
|
-
union Referencer6 @inaccessible = Object
|
|
472
|
-
`);
|
|
473
|
-
|
|
474
|
-
removeInaccessibleElements(schema);
|
|
475
|
-
schema.validate();
|
|
476
|
-
expect(schema.elementByCoordinate("Query")).toBeDefined();
|
|
477
|
-
expect(schema.elementByCoordinate("Mutation")).toBeUndefined();
|
|
478
|
-
expect(schema.elementByCoordinate("Subscription")).toBeUndefined();
|
|
479
|
-
expect(schema.elementByCoordinate("Object")).toBeUndefined();
|
|
480
|
-
expect(schema.elementByCoordinate("Referencer1.someField")).toBeDefined();
|
|
481
|
-
expect(
|
|
482
|
-
schema.elementByCoordinate("Referencer1.privatefield")
|
|
483
|
-
).toBeUndefined();
|
|
484
|
-
expect(schema.elementByCoordinate("Referencer2")).toBeUndefined();
|
|
485
|
-
expect(schema.elementByCoordinate("Referencer3.someField")).toBeDefined();
|
|
486
|
-
expect(
|
|
487
|
-
schema.elementByCoordinate("Referencer3.privatefield")
|
|
488
|
-
).toBeUndefined();
|
|
489
|
-
expect(schema.elementByCoordinate("Referencer4")).toBeUndefined();
|
|
490
|
-
const unionType = schema.elementByCoordinate("Referencer5");
|
|
491
|
-
expect(unionType instanceof UnionType).toBeTruthy();
|
|
492
|
-
expect((unionType as UnionType).hasTypeMember("Query")).toBeTruthy();
|
|
493
|
-
expect((unionType as UnionType).hasTypeMember("Object")).toBeFalsy();
|
|
494
|
-
expect(schema.elementByCoordinate("Referencer6")).toBeUndefined();
|
|
495
|
-
});
|
|
496
|
-
|
|
497
|
-
it(`fails to remove @inaccessible object types for breaking removals`, () => {
|
|
498
|
-
const schema = buildSchema(`
|
|
499
|
-
${INACCESSIBLE_V02_HEADER}
|
|
500
|
-
|
|
501
|
-
# Query types can't be inaccessible
|
|
502
|
-
type Query @inaccessible {
|
|
503
|
-
someField: String
|
|
504
|
-
}
|
|
505
|
-
|
|
506
|
-
# Inaccessible object type
|
|
507
|
-
type Object @inaccessible {
|
|
508
|
-
someField: String
|
|
509
|
-
}
|
|
510
|
-
|
|
511
|
-
# Inaccessible object type can't be referenced by object field in the API
|
|
512
|
-
# schema
|
|
513
|
-
type Referencer1 implements Referencer2 {
|
|
514
|
-
someField: Object!
|
|
515
|
-
}
|
|
516
|
-
|
|
517
|
-
# Inaccessible object type can't be referenced by interface field in the
|
|
518
|
-
# API schema
|
|
519
|
-
interface Referencer2 {
|
|
520
|
-
someField: Object
|
|
521
|
-
}
|
|
522
|
-
|
|
523
|
-
# Inaccessible object type can't be referenced by union member with a
|
|
524
|
-
# non-inaccessible parent and no non-inaccessible siblings
|
|
525
|
-
union Referencer3 = Object
|
|
526
|
-
`);
|
|
527
|
-
|
|
528
|
-
const errorMessages = expectErrors(4, () => {
|
|
529
|
-
removeInaccessibleElements(schema);
|
|
530
|
-
});
|
|
531
|
-
|
|
532
|
-
expect(errorMessages).toMatchInlineSnapshot(`
|
|
533
|
-
Array [
|
|
534
|
-
"Type \\"Object\\" is @inaccessible but is referenced by \\"Referencer1.someField\\", which is in the API schema.",
|
|
535
|
-
"Type \\"Object\\" is @inaccessible but is referenced by \\"Referencer2.someField\\", which is in the API schema.",
|
|
536
|
-
"Type \\"Query\\" is @inaccessible but is the root query type, which must be in the API schema.",
|
|
537
|
-
"Type \\"Referencer3\\" is in the API schema but all of its members are @inaccessible.",
|
|
538
|
-
]
|
|
539
|
-
`);
|
|
540
|
-
});
|
|
541
|
-
|
|
542
|
-
it(`removes @inaccessible interface types`, () => {
|
|
543
|
-
const schema = buildSchema(`
|
|
544
|
-
${INACCESSIBLE_V02_HEADER}
|
|
545
|
-
|
|
546
|
-
type Query {
|
|
547
|
-
someField: String
|
|
548
|
-
}
|
|
549
|
-
|
|
550
|
-
# Non-inaccessible interface type
|
|
551
|
-
interface VisibleInterface {
|
|
552
|
-
someField: String
|
|
553
|
-
}
|
|
554
|
-
|
|
555
|
-
# Inaccessible interface type
|
|
556
|
-
interface Interface @inaccessible {
|
|
557
|
-
someField: String
|
|
558
|
-
}
|
|
559
|
-
|
|
560
|
-
# Inaccessible interface type referenced by inaccessible object field
|
|
561
|
-
type Referencer1 implements Referencer3 {
|
|
562
|
-
someField: String
|
|
563
|
-
privatefield: Interface! @inaccessible
|
|
564
|
-
}
|
|
565
|
-
|
|
566
|
-
# Inaccessible interface type referenced by non-inaccessible object field
|
|
567
|
-
# with inaccessible parent
|
|
568
|
-
type Referencer2 implements Referencer4 @inaccessible {
|
|
569
|
-
privateField: [Interface!]!
|
|
570
|
-
}
|
|
571
|
-
|
|
572
|
-
# Inaccessible interface type referenced by inaccessible interface field
|
|
573
|
-
interface Referencer3 {
|
|
574
|
-
someField: String
|
|
575
|
-
privatefield: Interface @inaccessible
|
|
576
|
-
}
|
|
577
|
-
|
|
578
|
-
# Inaccessible interface type referenced by non-inaccessible interface
|
|
579
|
-
# field with inaccessible parent
|
|
580
|
-
interface Referencer4 @inaccessible {
|
|
581
|
-
privateField: [Interface]
|
|
582
|
-
}
|
|
583
|
-
|
|
584
|
-
# Inaccessible interface type referenced by object type implements
|
|
585
|
-
type Referencer5 implements VisibleInterface & Interface {
|
|
586
|
-
someField: String
|
|
587
|
-
}
|
|
588
|
-
|
|
589
|
-
# Inaccessible interface type referenced by interface type implements
|
|
590
|
-
interface Referencer6 implements VisibleInterface & Interface {
|
|
591
|
-
someField: String
|
|
592
|
-
}
|
|
593
|
-
`);
|
|
594
|
-
|
|
595
|
-
removeInaccessibleElements(schema);
|
|
596
|
-
schema.validate();
|
|
597
|
-
expect(schema.elementByCoordinate("VisibleInterface")).toBeDefined();
|
|
598
|
-
expect(schema.elementByCoordinate("Interface")).toBeUndefined();
|
|
599
|
-
expect(schema.elementByCoordinate("Referencer1.someField")).toBeDefined();
|
|
600
|
-
expect(
|
|
601
|
-
schema.elementByCoordinate("Referencer1.privatefield")
|
|
602
|
-
).toBeUndefined();
|
|
603
|
-
expect(schema.elementByCoordinate("Referencer2")).toBeUndefined();
|
|
604
|
-
expect(schema.elementByCoordinate("Referencer3.someField")).toBeDefined();
|
|
605
|
-
expect(
|
|
606
|
-
schema.elementByCoordinate("Referencer3.privatefield")
|
|
607
|
-
).toBeUndefined();
|
|
608
|
-
expect(schema.elementByCoordinate("Referencer4")).toBeUndefined();
|
|
609
|
-
const objectType = schema.elementByCoordinate("Referencer5");
|
|
610
|
-
expect(objectType instanceof ObjectType).toBeTruthy();
|
|
611
|
-
expect(
|
|
612
|
-
(objectType as ObjectType).implementsInterface("VisibleInterface")
|
|
613
|
-
).toBeTruthy();
|
|
614
|
-
expect(
|
|
615
|
-
(objectType as ObjectType).implementsInterface("Interface")
|
|
616
|
-
).toBeFalsy();
|
|
617
|
-
const interfaceType = schema.elementByCoordinate("Referencer6");
|
|
618
|
-
expect(interfaceType instanceof InterfaceType).toBeTruthy();
|
|
619
|
-
expect(
|
|
620
|
-
(interfaceType as InterfaceType).implementsInterface("VisibleInterface")
|
|
621
|
-
).toBeTruthy();
|
|
622
|
-
expect(
|
|
623
|
-
(interfaceType as InterfaceType).implementsInterface("Interface")
|
|
624
|
-
).toBeFalsy();
|
|
625
|
-
});
|
|
626
|
-
|
|
627
|
-
it(`fails to remove @inaccessible interface types for breaking removals`, () => {
|
|
628
|
-
const schema = buildSchema(`
|
|
629
|
-
${INACCESSIBLE_V02_HEADER}
|
|
630
|
-
|
|
631
|
-
type Query {
|
|
632
|
-
someField: String
|
|
633
|
-
}
|
|
634
|
-
|
|
635
|
-
# Inaccessible interface type
|
|
636
|
-
interface Interface @inaccessible {
|
|
637
|
-
someField: String
|
|
638
|
-
}
|
|
639
|
-
|
|
640
|
-
# Inaccessible interface type can't be referenced by object field in the
|
|
641
|
-
# API schema
|
|
642
|
-
type Referencer1 implements Referencer2 {
|
|
643
|
-
someField: [Interface!]!
|
|
644
|
-
}
|
|
645
|
-
|
|
646
|
-
# Inaccessible interface type can't be referenced by interface field in
|
|
647
|
-
# the API schema
|
|
648
|
-
interface Referencer2 {
|
|
649
|
-
someField: [Interface]
|
|
650
|
-
}
|
|
651
|
-
`);
|
|
652
|
-
|
|
653
|
-
const errorMessages = expectErrors(2, () => {
|
|
654
|
-
removeInaccessibleElements(schema);
|
|
655
|
-
});
|
|
656
|
-
|
|
657
|
-
expect(errorMessages).toMatchInlineSnapshot(`
|
|
658
|
-
Array [
|
|
659
|
-
"Type \\"Interface\\" is @inaccessible but is referenced by \\"Referencer1.someField\\", which is in the API schema.",
|
|
660
|
-
"Type \\"Interface\\" is @inaccessible but is referenced by \\"Referencer2.someField\\", which is in the API schema.",
|
|
661
|
-
]
|
|
662
|
-
`);
|
|
663
|
-
});
|
|
664
|
-
|
|
665
|
-
it(`removes @inaccessible union types`, () => {
|
|
666
|
-
const schema = buildSchema(`
|
|
667
|
-
${INACCESSIBLE_V02_HEADER}
|
|
668
|
-
|
|
669
|
-
type Query {
|
|
670
|
-
someField: String
|
|
671
|
-
}
|
|
672
|
-
|
|
673
|
-
# Non-inaccessible union type
|
|
674
|
-
union VisibleUnion = Query
|
|
675
|
-
|
|
676
|
-
# Inaccessible union type
|
|
677
|
-
union Union @inaccessible = Query
|
|
678
|
-
|
|
679
|
-
# Inaccessible union type referenced by inaccessible object field
|
|
680
|
-
type Referencer1 implements Referencer3 {
|
|
681
|
-
someField: String
|
|
682
|
-
privatefield: Union! @inaccessible
|
|
683
|
-
}
|
|
684
|
-
|
|
685
|
-
# Inaccessible union type referenced by non-inaccessible object field with
|
|
686
|
-
# inaccessible parent
|
|
687
|
-
type Referencer2 implements Referencer4 @inaccessible {
|
|
688
|
-
privateField: [Union!]!
|
|
689
|
-
}
|
|
690
|
-
|
|
691
|
-
# Inaccessible union type referenced by inaccessible interface field
|
|
692
|
-
interface Referencer3 {
|
|
693
|
-
someField: String
|
|
694
|
-
privatefield: Union @inaccessible
|
|
695
|
-
}
|
|
696
|
-
|
|
697
|
-
# Inaccessible union type referenced by non-inaccessible interface field
|
|
698
|
-
# with inaccessible parent
|
|
699
|
-
interface Referencer4 @inaccessible {
|
|
700
|
-
privateField: [Union]
|
|
701
|
-
}
|
|
702
|
-
`);
|
|
703
|
-
|
|
704
|
-
removeInaccessibleElements(schema);
|
|
705
|
-
schema.validate();
|
|
706
|
-
expect(schema.elementByCoordinate("VisibleUnion")).toBeDefined();
|
|
707
|
-
expect(schema.elementByCoordinate("Union")).toBeUndefined();
|
|
708
|
-
expect(schema.elementByCoordinate("Referencer1.someField")).toBeDefined();
|
|
709
|
-
expect(
|
|
710
|
-
schema.elementByCoordinate("Referencer1.privatefield")
|
|
711
|
-
).toBeUndefined();
|
|
712
|
-
expect(schema.elementByCoordinate("Referencer2")).toBeUndefined();
|
|
713
|
-
expect(schema.elementByCoordinate("Referencer3.someField")).toBeDefined();
|
|
714
|
-
expect(
|
|
715
|
-
schema.elementByCoordinate("Referencer3.privatefield")
|
|
716
|
-
).toBeUndefined();
|
|
717
|
-
expect(schema.elementByCoordinate("Referencer4")).toBeUndefined();
|
|
718
|
-
});
|
|
719
|
-
|
|
720
|
-
it(`fails to remove @inaccessible union types for breaking removals`, () => {
|
|
721
|
-
const schema = buildSchema(`
|
|
722
|
-
${INACCESSIBLE_V02_HEADER}
|
|
723
|
-
|
|
724
|
-
type Query {
|
|
725
|
-
someField: String
|
|
726
|
-
}
|
|
727
|
-
|
|
728
|
-
# Inaccessible union type
|
|
729
|
-
union Union @inaccessible = Query
|
|
730
|
-
|
|
731
|
-
# Inaccessible union type can't be referenced by object field in the API
|
|
732
|
-
# schema
|
|
733
|
-
type Referencer1 implements Referencer2 {
|
|
734
|
-
someField: Union!
|
|
735
|
-
}
|
|
736
|
-
|
|
737
|
-
# Inaccessible union type can't be referenced by interface field in the
|
|
738
|
-
# API schema
|
|
739
|
-
interface Referencer2 {
|
|
740
|
-
someField: Union
|
|
741
|
-
}
|
|
742
|
-
`);
|
|
743
|
-
|
|
744
|
-
const errorMessages = expectErrors(2, () => {
|
|
745
|
-
removeInaccessibleElements(schema);
|
|
746
|
-
});
|
|
747
|
-
|
|
748
|
-
expect(errorMessages).toMatchInlineSnapshot(`
|
|
749
|
-
Array [
|
|
750
|
-
"Type \\"Union\\" is @inaccessible but is referenced by \\"Referencer1.someField\\", which is in the API schema.",
|
|
751
|
-
"Type \\"Union\\" is @inaccessible but is referenced by \\"Referencer2.someField\\", which is in the API schema.",
|
|
752
|
-
]
|
|
753
|
-
`);
|
|
754
|
-
});
|
|
755
|
-
|
|
756
|
-
it(`removes @inaccessible input object types`, () => {
|
|
757
|
-
const schema = buildSchema(`
|
|
758
|
-
${INACCESSIBLE_V02_HEADER}
|
|
759
|
-
|
|
760
|
-
type Query {
|
|
761
|
-
someField: String
|
|
762
|
-
}
|
|
763
|
-
|
|
764
|
-
# Non-inaccessible input object type
|
|
765
|
-
input VisibleInputObject {
|
|
766
|
-
someField: String
|
|
767
|
-
}
|
|
768
|
-
|
|
769
|
-
# Inaccessible input object type
|
|
770
|
-
input InputObject @inaccessible {
|
|
771
|
-
someField: String
|
|
772
|
-
}
|
|
773
|
-
|
|
774
|
-
# Inaccessible input object type referenced by inaccessible object field
|
|
775
|
-
# argument
|
|
776
|
-
type Referencer1 implements Referencer4 {
|
|
777
|
-
someField(privateArg: InputObject @inaccessible): String
|
|
778
|
-
}
|
|
779
|
-
|
|
780
|
-
# Inaccessible input object type referenced by non-inaccessible object
|
|
781
|
-
# field argument with inaccessible parent
|
|
782
|
-
type Referencer2 implements Referencer5 {
|
|
783
|
-
someField: String
|
|
784
|
-
privateField(privateArg: InputObject!): String @inaccessible
|
|
785
|
-
}
|
|
786
|
-
|
|
787
|
-
# Inaccessible input object type referenced by non-inaccessible object
|
|
788
|
-
# field argument with inaccessible grandparent
|
|
789
|
-
type Referencer3 implements Referencer6 @inaccessible {
|
|
790
|
-
privateField(privateArg: InputObject!): String
|
|
791
|
-
}
|
|
792
|
-
|
|
793
|
-
# Inaccessible input object type referenced by inaccessible interface
|
|
794
|
-
# field argument
|
|
795
|
-
interface Referencer4 {
|
|
796
|
-
someField(privateArg: InputObject @inaccessible): String
|
|
797
|
-
}
|
|
798
|
-
|
|
799
|
-
# Inaccessible input object type referenced by non-inaccessible interface
|
|
800
|
-
# field argument with inaccessible parent
|
|
801
|
-
interface Referencer5 {
|
|
802
|
-
someField: String
|
|
803
|
-
privateField(privateArg: InputObject!): String @inaccessible
|
|
804
|
-
}
|
|
805
|
-
|
|
806
|
-
# Inaccessible input object type referenced by non-inaccessible interface
|
|
807
|
-
# field argument with inaccessible grandparent
|
|
808
|
-
interface Referencer6 @inaccessible {
|
|
809
|
-
privateField(privateArg: InputObject!): String
|
|
810
|
-
}
|
|
811
|
-
|
|
812
|
-
# Inaccessible input object type referenced by inaccessible input object
|
|
813
|
-
# field
|
|
814
|
-
input Referencer7 {
|
|
815
|
-
someField: String
|
|
816
|
-
privateField: InputObject @inaccessible
|
|
817
|
-
}
|
|
818
|
-
|
|
819
|
-
# Inaccessible input object type referenced by non-inaccessible input
|
|
820
|
-
# object field with inaccessible parent
|
|
821
|
-
input Referencer8 @inaccessible {
|
|
822
|
-
privateField: InputObject!
|
|
823
|
-
}
|
|
824
|
-
|
|
825
|
-
# Inaccessible input object type referenced by inaccessible directive
|
|
826
|
-
# argument
|
|
827
|
-
directive @referencer9(privateArg: InputObject @inaccessible) on FIELD
|
|
828
|
-
`);
|
|
829
|
-
|
|
830
|
-
removeInaccessibleElements(schema);
|
|
831
|
-
schema.validate();
|
|
832
|
-
expect(schema.elementByCoordinate("VisibleInputObject")).toBeDefined();
|
|
833
|
-
expect(schema.elementByCoordinate("InputObject")).toBeUndefined();
|
|
834
|
-
expect(schema.elementByCoordinate("Referencer1.someField")).toBeDefined();
|
|
835
|
-
expect(
|
|
836
|
-
schema.elementByCoordinate("Referencer1.someField(privateArg:)")
|
|
837
|
-
).toBeUndefined();
|
|
838
|
-
expect(schema.elementByCoordinate("Referencer2.someField")).toBeDefined();
|
|
839
|
-
expect(
|
|
840
|
-
schema.elementByCoordinate("Referencer2.privateField")
|
|
841
|
-
).toBeUndefined();
|
|
842
|
-
expect(schema.elementByCoordinate("Referencer3")).toBeUndefined();
|
|
843
|
-
expect(schema.elementByCoordinate("Referencer4.someField")).toBeDefined();
|
|
844
|
-
expect(
|
|
845
|
-
schema.elementByCoordinate("Referencer4.someField(privateArg:)")
|
|
846
|
-
).toBeUndefined();
|
|
847
|
-
expect(schema.elementByCoordinate("Referencer5.someField")).toBeDefined();
|
|
848
|
-
expect(
|
|
849
|
-
schema.elementByCoordinate("Referencer5.privateField")
|
|
850
|
-
).toBeUndefined();
|
|
851
|
-
expect(schema.elementByCoordinate("Referencer6")).toBeUndefined();
|
|
852
|
-
expect(schema.elementByCoordinate("Referencer7.someField")).toBeDefined();
|
|
853
|
-
expect(
|
|
854
|
-
schema.elementByCoordinate("Referencer7.privatefield")
|
|
855
|
-
).toBeUndefined();
|
|
856
|
-
expect(schema.elementByCoordinate("Referencer8")).toBeUndefined();
|
|
857
|
-
expect(schema.elementByCoordinate("@referencer9")).toBeDefined();
|
|
858
|
-
expect(
|
|
859
|
-
schema.elementByCoordinate("@referencer9(privateArg:)")
|
|
860
|
-
).toBeUndefined();
|
|
861
|
-
});
|
|
862
|
-
|
|
863
|
-
it(`fails to remove @inaccessible input object types for breaking removals`, () => {
|
|
864
|
-
const schema = buildSchema(`
|
|
865
|
-
${INACCESSIBLE_V02_HEADER}
|
|
866
|
-
|
|
867
|
-
type Query {
|
|
868
|
-
someField: String
|
|
869
|
-
}
|
|
870
|
-
|
|
871
|
-
# Inaccessible input object type
|
|
872
|
-
input InputObject @inaccessible {
|
|
873
|
-
someField: String
|
|
874
|
-
}
|
|
875
|
-
|
|
876
|
-
# Inaccessible input object type can't be referenced by object field
|
|
877
|
-
# argument in the API schema
|
|
878
|
-
type Referencer1 implements Referencer2 {
|
|
879
|
-
someField(someArg: InputObject): String
|
|
880
|
-
}
|
|
881
|
-
|
|
882
|
-
# Inaccessible input object type can't be referenced by interface field
|
|
883
|
-
# argument in the API schema
|
|
884
|
-
interface Referencer2 {
|
|
885
|
-
someField(someArg: InputObject): String
|
|
886
|
-
}
|
|
887
|
-
|
|
888
|
-
# Inaccessible input object type can't be referenced by input object field
|
|
889
|
-
# in the API schema
|
|
890
|
-
input Referencer3 {
|
|
891
|
-
someField: InputObject
|
|
892
|
-
}
|
|
893
|
-
|
|
894
|
-
# Inaccessible input object type can't be referenced by directive argument
|
|
895
|
-
# in the API schema
|
|
896
|
-
directive @referencer4(someArg: InputObject) on QUERY
|
|
897
|
-
`);
|
|
898
|
-
|
|
899
|
-
const errorMessages = expectErrors(4, () => {
|
|
900
|
-
removeInaccessibleElements(schema);
|
|
901
|
-
});
|
|
902
|
-
|
|
903
|
-
expect(errorMessages).toMatchInlineSnapshot(`
|
|
904
|
-
Array [
|
|
905
|
-
"Type \\"InputObject\\" is @inaccessible but is referenced by \\"@referencer4(someArg:)\\", which is in the API schema.",
|
|
906
|
-
"Type \\"InputObject\\" is @inaccessible but is referenced by \\"Referencer1.someField(someArg:)\\", which is in the API schema.",
|
|
907
|
-
"Type \\"InputObject\\" is @inaccessible but is referenced by \\"Referencer2.someField(someArg:)\\", which is in the API schema.",
|
|
908
|
-
"Type \\"InputObject\\" is @inaccessible but is referenced by \\"Referencer3.someField\\", which is in the API schema.",
|
|
909
|
-
]
|
|
910
|
-
`);
|
|
911
|
-
});
|
|
912
|
-
|
|
913
|
-
it(`removes @inaccessible enum types`, () => {
|
|
914
|
-
const schema = buildSchema(`
|
|
915
|
-
${INACCESSIBLE_V02_HEADER}
|
|
916
|
-
|
|
917
|
-
type Query {
|
|
918
|
-
someField: String
|
|
919
|
-
}
|
|
920
|
-
|
|
921
|
-
# Non-inaccessible enum type
|
|
922
|
-
enum VisibleEnum {
|
|
923
|
-
SOME_VALUE
|
|
924
|
-
}
|
|
925
|
-
|
|
926
|
-
# Inaccessible enum type
|
|
927
|
-
enum Enum @inaccessible {
|
|
928
|
-
SOME_VALUE
|
|
929
|
-
}
|
|
930
|
-
|
|
931
|
-
# Inaccessible enum type referenced by inaccessible object field
|
|
932
|
-
type Referencer1 implements Referencer3 {
|
|
933
|
-
someField: String
|
|
934
|
-
privatefield: Enum! @inaccessible
|
|
935
|
-
}
|
|
936
|
-
|
|
937
|
-
# Inaccessible enum type referenced by non-inaccessible object field with
|
|
938
|
-
# inaccessible parent
|
|
939
|
-
type Referencer2 implements Referencer4 @inaccessible {
|
|
940
|
-
privateField: [Enum!]!
|
|
941
|
-
}
|
|
942
|
-
|
|
943
|
-
# Inaccessible enum type referenced by inaccessible interface field
|
|
944
|
-
interface Referencer3 {
|
|
945
|
-
someField: String
|
|
946
|
-
privatefield: Enum @inaccessible
|
|
947
|
-
}
|
|
948
|
-
|
|
949
|
-
# Inaccessible enum type referenced by non-inaccessible interface field
|
|
950
|
-
# with inaccessible parent
|
|
951
|
-
interface Referencer4 @inaccessible {
|
|
952
|
-
privateField: [Enum]
|
|
953
|
-
}
|
|
954
|
-
|
|
955
|
-
# Inaccessible enum type referenced by inaccessible object field argument
|
|
956
|
-
type Referencer5 implements Referencer8 {
|
|
957
|
-
someField(privateArg: Enum @inaccessible): String
|
|
958
|
-
}
|
|
959
|
-
|
|
960
|
-
# Inaccessible enum type referenced by non-inaccessible object field
|
|
961
|
-
# argument with inaccessible parent
|
|
962
|
-
type Referencer6 implements Referencer9 {
|
|
963
|
-
someField: String
|
|
964
|
-
privateField(privateArg: Enum!): String @inaccessible
|
|
965
|
-
}
|
|
966
|
-
|
|
967
|
-
# Inaccessible enum type referenced by non-inaccessible object field
|
|
968
|
-
# argument with inaccessible grandparent
|
|
969
|
-
type Referencer7 implements Referencer10 @inaccessible {
|
|
970
|
-
privateField(privateArg: Enum!): String
|
|
971
|
-
}
|
|
972
|
-
|
|
973
|
-
# Inaccessible enum type referenced by inaccessible interface field
|
|
974
|
-
# argument
|
|
975
|
-
interface Referencer8 {
|
|
976
|
-
someField(privateArg: Enum @inaccessible): String
|
|
977
|
-
}
|
|
978
|
-
|
|
979
|
-
# Inaccessible enum type referenced by non-inaccessible interface field
|
|
980
|
-
# argument with inaccessible parent
|
|
981
|
-
interface Referencer9 {
|
|
982
|
-
someField: String
|
|
983
|
-
privateField(privateArg: Enum!): String @inaccessible
|
|
984
|
-
}
|
|
985
|
-
|
|
986
|
-
# Inaccessible enum type referenced by non-inaccessible interface field
|
|
987
|
-
# argument with inaccessible grandparent
|
|
988
|
-
interface Referencer10 @inaccessible {
|
|
989
|
-
privateField(privateArg: Enum!): String
|
|
990
|
-
}
|
|
991
|
-
|
|
992
|
-
# Inaccessible enum type referenced by inaccessible input object field
|
|
993
|
-
input Referencer11 {
|
|
994
|
-
someField: String
|
|
995
|
-
privateField: Enum @inaccessible
|
|
996
|
-
}
|
|
997
|
-
|
|
998
|
-
# Inaccessible enum type referenced by non-inaccessible input object field
|
|
999
|
-
# with inaccessible parent
|
|
1000
|
-
input Referencer12 @inaccessible {
|
|
1001
|
-
privateField: Enum!
|
|
1002
|
-
}
|
|
1003
|
-
|
|
1004
|
-
# Inaccessible enum type referenced by inaccessible directive argument
|
|
1005
|
-
directive @referencer13(privateArg: Enum @inaccessible) on FRAGMENT_DEFINITION
|
|
1006
|
-
`);
|
|
1007
|
-
|
|
1008
|
-
removeInaccessibleElements(schema);
|
|
1009
|
-
schema.validate();
|
|
1010
|
-
expect(schema.elementByCoordinate("VisibleEnum")).toBeDefined();
|
|
1011
|
-
expect(schema.elementByCoordinate("Enum")).toBeUndefined();
|
|
1012
|
-
expect(schema.elementByCoordinate("Referencer1.someField")).toBeDefined();
|
|
1013
|
-
expect(
|
|
1014
|
-
schema.elementByCoordinate("Referencer1.privatefield")
|
|
1015
|
-
).toBeUndefined();
|
|
1016
|
-
expect(schema.elementByCoordinate("Referencer2")).toBeUndefined();
|
|
1017
|
-
expect(schema.elementByCoordinate("Referencer3.someField")).toBeDefined();
|
|
1018
|
-
expect(
|
|
1019
|
-
schema.elementByCoordinate("Referencer3.privatefield")
|
|
1020
|
-
).toBeUndefined();
|
|
1021
|
-
expect(schema.elementByCoordinate("Referencer4")).toBeUndefined();
|
|
1022
|
-
expect(schema.elementByCoordinate("Referencer5.someField")).toBeDefined();
|
|
1023
|
-
expect(
|
|
1024
|
-
schema.elementByCoordinate("Referencer5.someField(privateArg:)")
|
|
1025
|
-
).toBeUndefined();
|
|
1026
|
-
expect(schema.elementByCoordinate("Referencer6.someField")).toBeDefined();
|
|
1027
|
-
expect(
|
|
1028
|
-
schema.elementByCoordinate("Referencer6.privateField")
|
|
1029
|
-
).toBeUndefined();
|
|
1030
|
-
expect(schema.elementByCoordinate("Referencer7")).toBeUndefined();
|
|
1031
|
-
expect(schema.elementByCoordinate("Referencer8.someField")).toBeDefined();
|
|
1032
|
-
expect(
|
|
1033
|
-
schema.elementByCoordinate("Referencer8.someField(privateArg:)")
|
|
1034
|
-
).toBeUndefined();
|
|
1035
|
-
expect(schema.elementByCoordinate("Referencer9.someField")).toBeDefined();
|
|
1036
|
-
expect(
|
|
1037
|
-
schema.elementByCoordinate("Referencer9.privateField")
|
|
1038
|
-
).toBeUndefined();
|
|
1039
|
-
expect(schema.elementByCoordinate("Referencer10")).toBeUndefined();
|
|
1040
|
-
expect(schema.elementByCoordinate("Referencer11.someField")).toBeDefined();
|
|
1041
|
-
expect(
|
|
1042
|
-
schema.elementByCoordinate("Referencer11.privatefield")
|
|
1043
|
-
).toBeUndefined();
|
|
1044
|
-
expect(schema.elementByCoordinate("Referencer12")).toBeUndefined();
|
|
1045
|
-
expect(schema.elementByCoordinate("@referencer13")).toBeDefined();
|
|
1046
|
-
expect(
|
|
1047
|
-
schema.elementByCoordinate("@referencer13(privateArg:)")
|
|
1048
|
-
).toBeUndefined();
|
|
1049
|
-
});
|
|
1050
|
-
|
|
1051
|
-
it(`fails to remove @inaccessible enum types for breaking removals`, () => {
|
|
1052
|
-
const schema = buildSchema(`
|
|
1053
|
-
${INACCESSIBLE_V02_HEADER}
|
|
1054
|
-
|
|
1055
|
-
type Query {
|
|
1056
|
-
someField: String
|
|
1057
|
-
}
|
|
1058
|
-
|
|
1059
|
-
# Inaccessible enum type
|
|
1060
|
-
enum Enum @inaccessible {
|
|
1061
|
-
SOME_VALUE
|
|
1062
|
-
}
|
|
1063
|
-
|
|
1064
|
-
# Inaccessible enum type can't be referenced by object field in the API
|
|
1065
|
-
# schema
|
|
1066
|
-
type Referencer1 implements Referencer2 {
|
|
1067
|
-
somefield: [Enum!]!
|
|
1068
|
-
}
|
|
1069
|
-
|
|
1070
|
-
# Inaccessible enum type can't be referenced by interface field in the API
|
|
1071
|
-
# schema
|
|
1072
|
-
interface Referencer2 {
|
|
1073
|
-
somefield: [Enum]
|
|
1074
|
-
}
|
|
1075
|
-
|
|
1076
|
-
# Inaccessible enum type can't be referenced by object field argument in
|
|
1077
|
-
# the API schema
|
|
1078
|
-
type Referencer3 implements Referencer4 {
|
|
1079
|
-
someField(someArg: Enum): String
|
|
1080
|
-
}
|
|
1081
|
-
|
|
1082
|
-
# Inaccessible enum type can't be referenced by interface field argument
|
|
1083
|
-
# in the API schema
|
|
1084
|
-
interface Referencer4 {
|
|
1085
|
-
someField(someArg: Enum): String
|
|
1086
|
-
}
|
|
1087
|
-
|
|
1088
|
-
# Inaccessible enum type can't be referenced by input object field in the
|
|
1089
|
-
# API schema
|
|
1090
|
-
input Referencer5 {
|
|
1091
|
-
someField: Enum
|
|
1092
|
-
}
|
|
1093
|
-
|
|
1094
|
-
# Inaccessible enum type can't be referenced by directive argument in the
|
|
1095
|
-
# API schema
|
|
1096
|
-
directive @referencer6(someArg: Enum) on FRAGMENT_SPREAD
|
|
1097
|
-
`);
|
|
1098
|
-
|
|
1099
|
-
const errorMessages = expectErrors(6, () => {
|
|
1100
|
-
removeInaccessibleElements(schema);
|
|
1101
|
-
});
|
|
1102
|
-
|
|
1103
|
-
expect(errorMessages).toMatchInlineSnapshot(`
|
|
1104
|
-
Array [
|
|
1105
|
-
"Type \\"Enum\\" is @inaccessible but is referenced by \\"@referencer6(someArg:)\\", which is in the API schema.",
|
|
1106
|
-
"Type \\"Enum\\" is @inaccessible but is referenced by \\"Referencer1.somefield\\", which is in the API schema.",
|
|
1107
|
-
"Type \\"Enum\\" is @inaccessible but is referenced by \\"Referencer2.somefield\\", which is in the API schema.",
|
|
1108
|
-
"Type \\"Enum\\" is @inaccessible but is referenced by \\"Referencer3.someField(someArg:)\\", which is in the API schema.",
|
|
1109
|
-
"Type \\"Enum\\" is @inaccessible but is referenced by \\"Referencer4.someField(someArg:)\\", which is in the API schema.",
|
|
1110
|
-
"Type \\"Enum\\" is @inaccessible but is referenced by \\"Referencer5.someField\\", which is in the API schema.",
|
|
1111
|
-
]
|
|
1112
|
-
`);
|
|
1113
|
-
});
|
|
1114
|
-
|
|
1115
|
-
it(`removes @inaccessible scalar types`, () => {
|
|
1116
|
-
const schema = buildSchema(`
|
|
1117
|
-
${INACCESSIBLE_V02_HEADER}
|
|
1118
|
-
|
|
1119
|
-
type Query {
|
|
1120
|
-
someField: String
|
|
1121
|
-
}
|
|
1122
|
-
|
|
1123
|
-
# Non-inaccessible scalar type
|
|
1124
|
-
scalar VisibleScalar
|
|
1125
|
-
|
|
1126
|
-
# Inaccessible scalar type
|
|
1127
|
-
scalar Scalar @inaccessible
|
|
1128
|
-
|
|
1129
|
-
# Inaccessible scalar type referenced by inaccessible object field
|
|
1130
|
-
type Referencer1 implements Referencer3 {
|
|
1131
|
-
someField: String
|
|
1132
|
-
privatefield: Scalar! @inaccessible
|
|
1133
|
-
}
|
|
1134
|
-
|
|
1135
|
-
# Inaccessible scalar type referenced by non-inaccessible object field
|
|
1136
|
-
# with inaccessible parent
|
|
1137
|
-
type Referencer2 implements Referencer4 @inaccessible {
|
|
1138
|
-
privateField: [Scalar!]!
|
|
1139
|
-
}
|
|
1140
|
-
|
|
1141
|
-
# Inaccessible scalar type referenced by inaccessible interface field
|
|
1142
|
-
interface Referencer3 {
|
|
1143
|
-
someField: String
|
|
1144
|
-
privatefield: Scalar @inaccessible
|
|
1145
|
-
}
|
|
1146
|
-
|
|
1147
|
-
# Inaccessible scalar type referenced by non-inaccessible interface field
|
|
1148
|
-
# with inaccessible parent
|
|
1149
|
-
interface Referencer4 @inaccessible {
|
|
1150
|
-
privateField: [Scalar]
|
|
1151
|
-
}
|
|
1152
|
-
|
|
1153
|
-
# Inaccessible scalar type referenced by inaccessible object field
|
|
1154
|
-
# argument
|
|
1155
|
-
type Referencer5 implements Referencer8 {
|
|
1156
|
-
someField(privateArg: Scalar @inaccessible): String
|
|
1157
|
-
}
|
|
1158
|
-
|
|
1159
|
-
# Inaccessible scalar type referenced by non-inaccessible object field
|
|
1160
|
-
# argument with inaccessible parent
|
|
1161
|
-
type Referencer6 implements Referencer9 {
|
|
1162
|
-
someField: String
|
|
1163
|
-
privateField(privateArg: Scalar!): String @inaccessible
|
|
1164
|
-
}
|
|
1165
|
-
|
|
1166
|
-
# Inaccessible scalar type referenced by non-inaccessible object field
|
|
1167
|
-
# argument with inaccessible grandparent
|
|
1168
|
-
type Referencer7 implements Referencer10 @inaccessible {
|
|
1169
|
-
privateField(privateArg: Scalar!): String
|
|
1170
|
-
}
|
|
1171
|
-
|
|
1172
|
-
# Inaccessible scalar type referenced by inaccessible interface field
|
|
1173
|
-
# argument
|
|
1174
|
-
interface Referencer8 {
|
|
1175
|
-
someField(privateArg: Scalar @inaccessible): String
|
|
1176
|
-
}
|
|
1177
|
-
|
|
1178
|
-
# Inaccessible scalar type referenced by non-inaccessible interface field
|
|
1179
|
-
# argument with inaccessible parent
|
|
1180
|
-
interface Referencer9 {
|
|
1181
|
-
someField: String
|
|
1182
|
-
privateField(privateArg: Scalar!): String @inaccessible
|
|
1183
|
-
}
|
|
1184
|
-
|
|
1185
|
-
# Inaccessible scalar type referenced by non-inaccessible interface field
|
|
1186
|
-
# argument with inaccessible grandparent
|
|
1187
|
-
interface Referencer10 @inaccessible {
|
|
1188
|
-
privateField(privateArg: Scalar!): String
|
|
1189
|
-
}
|
|
1190
|
-
|
|
1191
|
-
# Inaccessible scalar type referenced by inaccessible input object field
|
|
1192
|
-
input Referencer11 {
|
|
1193
|
-
someField: String
|
|
1194
|
-
privateField: Scalar @inaccessible
|
|
1195
|
-
}
|
|
1196
|
-
|
|
1197
|
-
# Inaccessible scalar type referenced by non-inaccessible input object
|
|
1198
|
-
# field with inaccessible parent
|
|
1199
|
-
input Referencer12 @inaccessible {
|
|
1200
|
-
privateField: Scalar!
|
|
1201
|
-
}
|
|
1202
|
-
|
|
1203
|
-
# Inaccessible scalar type referenced by inaccessible directive argument
|
|
1204
|
-
directive @referencer13(privateArg: Scalar @inaccessible) on INLINE_FRAGMENT
|
|
1205
|
-
`);
|
|
1206
|
-
|
|
1207
|
-
removeInaccessibleElements(schema);
|
|
1208
|
-
schema.validate();
|
|
1209
|
-
expect(schema.elementByCoordinate("VisibleScalar")).toBeDefined();
|
|
1210
|
-
expect(schema.elementByCoordinate("Scalar")).toBeUndefined();
|
|
1211
|
-
expect(schema.elementByCoordinate("Referencer1.someField")).toBeDefined();
|
|
1212
|
-
expect(
|
|
1213
|
-
schema.elementByCoordinate("Referencer1.privatefield")
|
|
1214
|
-
).toBeUndefined();
|
|
1215
|
-
expect(schema.elementByCoordinate("Referencer2")).toBeUndefined();
|
|
1216
|
-
expect(schema.elementByCoordinate("Referencer3.someField")).toBeDefined();
|
|
1217
|
-
expect(
|
|
1218
|
-
schema.elementByCoordinate("Referencer3.privatefield")
|
|
1219
|
-
).toBeUndefined();
|
|
1220
|
-
expect(schema.elementByCoordinate("Referencer4")).toBeUndefined();
|
|
1221
|
-
expect(schema.elementByCoordinate("Referencer5.someField")).toBeDefined();
|
|
1222
|
-
expect(
|
|
1223
|
-
schema.elementByCoordinate("Referencer5.someField(privateArg:)")
|
|
1224
|
-
).toBeUndefined();
|
|
1225
|
-
expect(schema.elementByCoordinate("Referencer6.someField")).toBeDefined();
|
|
1226
|
-
expect(
|
|
1227
|
-
schema.elementByCoordinate("Referencer6.privateField")
|
|
1228
|
-
).toBeUndefined();
|
|
1229
|
-
expect(schema.elementByCoordinate("Referencer7")).toBeUndefined();
|
|
1230
|
-
expect(schema.elementByCoordinate("Referencer8.someField")).toBeDefined();
|
|
1231
|
-
expect(
|
|
1232
|
-
schema.elementByCoordinate("Referencer8.someField(privateArg:)")
|
|
1233
|
-
).toBeUndefined();
|
|
1234
|
-
expect(schema.elementByCoordinate("Referencer9.someField")).toBeDefined();
|
|
1235
|
-
expect(
|
|
1236
|
-
schema.elementByCoordinate("Referencer9.privateField")
|
|
1237
|
-
).toBeUndefined();
|
|
1238
|
-
expect(schema.elementByCoordinate("Referencer10")).toBeUndefined();
|
|
1239
|
-
expect(schema.elementByCoordinate("Referencer11.someField")).toBeDefined();
|
|
1240
|
-
expect(
|
|
1241
|
-
schema.elementByCoordinate("Referencer11.privatefield")
|
|
1242
|
-
).toBeUndefined();
|
|
1243
|
-
expect(schema.elementByCoordinate("Referencer12")).toBeUndefined();
|
|
1244
|
-
expect(schema.elementByCoordinate("@referencer13")).toBeDefined();
|
|
1245
|
-
expect(
|
|
1246
|
-
schema.elementByCoordinate("@referencer13(privateArg:)")
|
|
1247
|
-
).toBeUndefined();
|
|
1248
|
-
});
|
|
1249
|
-
|
|
1250
|
-
it(`fails to remove @inaccessible scalar types for breaking removals`, () => {
|
|
1251
|
-
const schema = buildSchema(`
|
|
1252
|
-
${INACCESSIBLE_V02_HEADER}
|
|
1253
|
-
|
|
1254
|
-
type Query {
|
|
1255
|
-
someField: String
|
|
1256
|
-
}
|
|
1257
|
-
|
|
1258
|
-
# Inaccessible scalar type
|
|
1259
|
-
scalar Scalar @inaccessible
|
|
1260
|
-
|
|
1261
|
-
# Inaccessible scalar type can't be referenced by object field in the API
|
|
1262
|
-
# schema
|
|
1263
|
-
type Referencer1 implements Referencer2 {
|
|
1264
|
-
somefield: [[Scalar!]!]!
|
|
1265
|
-
}
|
|
1266
|
-
|
|
1267
|
-
# Inaccessible scalar type can't be referenced by interface field in the
|
|
1268
|
-
# API schema
|
|
1269
|
-
interface Referencer2 {
|
|
1270
|
-
somefield: [[Scalar]]
|
|
1271
|
-
}
|
|
1272
|
-
|
|
1273
|
-
# Inaccessible scalar type can't be referenced by object field argument in
|
|
1274
|
-
# the API schema
|
|
1275
|
-
type Referencer3 implements Referencer4 {
|
|
1276
|
-
someField(someArg: Scalar): String
|
|
1277
|
-
}
|
|
1278
|
-
|
|
1279
|
-
# Inaccessible scalar type can't be referenced by interface field argument
|
|
1280
|
-
# in the API schema
|
|
1281
|
-
interface Referencer4 {
|
|
1282
|
-
someField(someArg: Scalar): String
|
|
1283
|
-
}
|
|
1284
|
-
|
|
1285
|
-
# Inaccessible scalar type can't be referenced by input object field in
|
|
1286
|
-
# the API schema
|
|
1287
|
-
input Referencer5 {
|
|
1288
|
-
someField: Scalar
|
|
1289
|
-
}
|
|
1290
|
-
|
|
1291
|
-
# Inaccessible scalar type can't be referenced by directive argument in
|
|
1292
|
-
# the API schema
|
|
1293
|
-
directive @referencer6(someArg: Scalar) on MUTATION
|
|
1294
|
-
`);
|
|
1295
|
-
|
|
1296
|
-
const errorMessages = expectErrors(6, () => {
|
|
1297
|
-
removeInaccessibleElements(schema);
|
|
1298
|
-
});
|
|
1299
|
-
|
|
1300
|
-
expect(errorMessages).toMatchInlineSnapshot(`
|
|
1301
|
-
Array [
|
|
1302
|
-
"Type \\"Scalar\\" is @inaccessible but is referenced by \\"@referencer6(someArg:)\\", which is in the API schema.",
|
|
1303
|
-
"Type \\"Scalar\\" is @inaccessible but is referenced by \\"Referencer1.somefield\\", which is in the API schema.",
|
|
1304
|
-
"Type \\"Scalar\\" is @inaccessible but is referenced by \\"Referencer2.somefield\\", which is in the API schema.",
|
|
1305
|
-
"Type \\"Scalar\\" is @inaccessible but is referenced by \\"Referencer3.someField(someArg:)\\", which is in the API schema.",
|
|
1306
|
-
"Type \\"Scalar\\" is @inaccessible but is referenced by \\"Referencer4.someField(someArg:)\\", which is in the API schema.",
|
|
1307
|
-
"Type \\"Scalar\\" is @inaccessible but is referenced by \\"Referencer5.someField\\", which is in the API schema.",
|
|
1308
|
-
]
|
|
1309
|
-
`);
|
|
1310
|
-
});
|
|
1311
|
-
|
|
1312
|
-
it(`removes @inaccessible object fields`, () => {
|
|
1313
|
-
const schema = buildSchema(`
|
|
1314
|
-
${INACCESSIBLE_V02_HEADER}
|
|
1315
|
-
|
|
1316
|
-
extend schema {
|
|
1317
|
-
mutation: Mutation
|
|
1318
|
-
subscription: Subscription
|
|
1319
|
-
}
|
|
1320
|
-
|
|
1321
|
-
# Inaccessible object field on query type
|
|
1322
|
-
type Query {
|
|
1323
|
-
someField: String
|
|
1324
|
-
privateField: String @inaccessible
|
|
1325
|
-
}
|
|
1326
|
-
|
|
1327
|
-
# Inaccessible object field on mutation type
|
|
1328
|
-
type Mutation {
|
|
1329
|
-
someField: String
|
|
1330
|
-
privateField: String @inaccessible
|
|
1331
|
-
}
|
|
1332
|
-
|
|
1333
|
-
# Inaccessible object field on subscription type
|
|
1334
|
-
type Subscription {
|
|
1335
|
-
someField: String
|
|
1336
|
-
privateField: String @inaccessible
|
|
1337
|
-
}
|
|
1338
|
-
|
|
1339
|
-
# Inaccessible (and non-inaccessible) object field
|
|
1340
|
-
type Object implements Referencer1 & Referencer2 {
|
|
1341
|
-
someField: String
|
|
1342
|
-
privateField: String @inaccessible
|
|
1343
|
-
}
|
|
1344
|
-
|
|
1345
|
-
# Inaccessible object field referenced by inaccessible interface field
|
|
1346
|
-
interface Referencer1 {
|
|
1347
|
-
someField: String
|
|
1348
|
-
privateField: String @inaccessible
|
|
1349
|
-
}
|
|
1350
|
-
|
|
1351
|
-
# Inaccessible object field referenced by non-inaccessible interface field
|
|
1352
|
-
# with inaccessible parent
|
|
1353
|
-
interface Referencer2 @inaccessible {
|
|
1354
|
-
privateField: String
|
|
1355
|
-
}
|
|
1356
|
-
|
|
1357
|
-
# Inaccessible object field with an inaccessible parent and no
|
|
1358
|
-
# non-inaccessible siblings
|
|
1359
|
-
type Referencer3 @inaccessible {
|
|
1360
|
-
privateField: String @inaccessible
|
|
1361
|
-
otherPrivateField: Float @inaccessible
|
|
1362
|
-
}
|
|
1363
|
-
`);
|
|
1364
|
-
|
|
1365
|
-
removeInaccessibleElements(schema);
|
|
1366
|
-
schema.validate();
|
|
1367
|
-
expect(schema.elementByCoordinate("Query.someField")).toBeDefined();
|
|
1368
|
-
expect(schema.elementByCoordinate("Query.privateField")).toBeUndefined();
|
|
1369
|
-
expect(schema.elementByCoordinate("Mutation.someField")).toBeDefined();
|
|
1370
|
-
expect(schema.elementByCoordinate("Mutation.privateField")).toBeUndefined();
|
|
1371
|
-
expect(schema.elementByCoordinate("Subscription.someField")).toBeDefined();
|
|
1372
|
-
expect(
|
|
1373
|
-
schema.elementByCoordinate("Subscription.privateField")
|
|
1374
|
-
).toBeUndefined();
|
|
1375
|
-
const objectType = schema.elementByCoordinate("Object");
|
|
1376
|
-
expect(objectType instanceof ObjectType).toBeTruthy();
|
|
1377
|
-
expect(
|
|
1378
|
-
(objectType as ObjectType).implementsInterface("Referencer1")
|
|
1379
|
-
).toBeTruthy();
|
|
1380
|
-
expect(
|
|
1381
|
-
(objectType as ObjectType).implementsInterface("Referencer2")
|
|
1382
|
-
).toBeFalsy();
|
|
1383
|
-
expect(schema.elementByCoordinate("Object.someField")).toBeDefined();
|
|
1384
|
-
expect(schema.elementByCoordinate("Object.privateField")).toBeUndefined();
|
|
1385
|
-
expect(schema.elementByCoordinate("Referencer1.someField")).toBeDefined();
|
|
1386
|
-
expect(
|
|
1387
|
-
schema.elementByCoordinate("Referencer1.privatefield")
|
|
1388
|
-
).toBeUndefined();
|
|
1389
|
-
expect(schema.elementByCoordinate("Referencer2")).toBeUndefined();
|
|
1390
|
-
expect(schema.elementByCoordinate("Referencer3")).toBeUndefined();
|
|
1391
|
-
});
|
|
1392
|
-
|
|
1393
|
-
it(`fails to remove @inaccessible object fields for breaking removals`, () => {
|
|
1394
|
-
const schema = buildSchema(`
|
|
1395
|
-
${INACCESSIBLE_V02_HEADER}
|
|
1396
|
-
|
|
1397
|
-
extend schema {
|
|
1398
|
-
mutation: Mutation
|
|
1399
|
-
subscription: Subscription
|
|
1400
|
-
}
|
|
1401
|
-
|
|
1402
|
-
# Inaccessible object field can't have a non-inaccessible parent query
|
|
1403
|
-
# type and no non-inaccessible siblings
|
|
1404
|
-
type Query {
|
|
1405
|
-
privateField: String @inaccessible
|
|
1406
|
-
otherPrivateField: Float @inaccessible
|
|
1407
|
-
}
|
|
1408
|
-
|
|
1409
|
-
# Inaccessible object field can't have a non-inaccessible parent mutation
|
|
1410
|
-
# type and no non-inaccessible siblings
|
|
1411
|
-
type Mutation {
|
|
1412
|
-
privateField: String @inaccessible
|
|
1413
|
-
otherPrivateField: Float @inaccessible
|
|
1414
|
-
}
|
|
1415
|
-
|
|
1416
|
-
# Inaccessible object field can't have a non-inaccessible parent
|
|
1417
|
-
# subscription type and no non-inaccessible siblings
|
|
1418
|
-
type Subscription {
|
|
1419
|
-
privateField: String @inaccessible
|
|
1420
|
-
otherPrivateField: Float @inaccessible
|
|
1421
|
-
}
|
|
1422
|
-
|
|
1423
|
-
# Inaccessible object field
|
|
1424
|
-
type Object implements Referencer1 {
|
|
1425
|
-
someField: String
|
|
1426
|
-
privateField: String @inaccessible
|
|
1427
|
-
}
|
|
1428
|
-
|
|
1429
|
-
# Inaccessible object field can't be referenced by interface field in the
|
|
1430
|
-
# API schema
|
|
1431
|
-
interface Referencer1 {
|
|
1432
|
-
privateField: String
|
|
1433
|
-
}
|
|
1434
|
-
|
|
1435
|
-
# Inaccessible object field can't have a non-inaccessible parent object
|
|
1436
|
-
# type and no non-inaccessible siblings
|
|
1437
|
-
type Referencer2 {
|
|
1438
|
-
privateField: String @inaccessible
|
|
1439
|
-
otherPrivateField: Float @inaccessible
|
|
1440
|
-
}
|
|
1441
|
-
`);
|
|
1442
|
-
|
|
1443
|
-
const errorMessages = expectErrors(5, () => {
|
|
1444
|
-
removeInaccessibleElements(schema);
|
|
1445
|
-
});
|
|
1446
|
-
|
|
1447
|
-
expect(errorMessages).toMatchInlineSnapshot(`
|
|
1448
|
-
Array [
|
|
1449
|
-
"Field \\"Object.privateField\\" is @inaccessible but implements the interface field \\"Referencer1.privateField\\", which is in the API schema.",
|
|
1450
|
-
"Type \\"Mutation\\" is in the API schema but all of its fields are @inaccessible.",
|
|
1451
|
-
"Type \\"Query\\" is in the API schema but all of its fields are @inaccessible.",
|
|
1452
|
-
"Type \\"Referencer2\\" is in the API schema but all of its fields are @inaccessible.",
|
|
1453
|
-
"Type \\"Subscription\\" is in the API schema but all of its fields are @inaccessible.",
|
|
1454
|
-
]
|
|
1455
|
-
`);
|
|
1456
|
-
});
|
|
1457
|
-
|
|
1458
|
-
it(`removes @inaccessible interface fields`, () => {
|
|
1459
|
-
const schema = buildSchema(`
|
|
1460
|
-
${INACCESSIBLE_V02_HEADER}
|
|
1461
|
-
|
|
1462
|
-
type Query {
|
|
1463
|
-
someField: String
|
|
1464
|
-
}
|
|
1465
|
-
|
|
1466
|
-
# Inaccessible (and non-inaccessible) interface field
|
|
1467
|
-
interface Interface implements Referencer1 & Referencer2 {
|
|
1468
|
-
someField: String
|
|
1469
|
-
privateField: String @inaccessible
|
|
1470
|
-
}
|
|
1471
|
-
|
|
1472
|
-
# Inaccessible interface field referenced by inaccessible interface field
|
|
1473
|
-
interface Referencer1 {
|
|
1474
|
-
someField: String
|
|
1475
|
-
privateField: String @inaccessible
|
|
1476
|
-
}
|
|
1477
|
-
|
|
1478
|
-
# Inaccessible interface field referenced by non-inaccessible interface
|
|
1479
|
-
# field with inaccessible parent
|
|
1480
|
-
interface Referencer2 @inaccessible {
|
|
1481
|
-
privateField: String
|
|
1482
|
-
}
|
|
1483
|
-
|
|
1484
|
-
# Inaccessible interface field with an inaccessible parent and no
|
|
1485
|
-
# non-inaccessible siblings
|
|
1486
|
-
interface Referencer3 @inaccessible {
|
|
1487
|
-
privateField: String @inaccessible
|
|
1488
|
-
otherPrivateField: Float @inaccessible
|
|
1489
|
-
}
|
|
1490
|
-
`);
|
|
1491
|
-
|
|
1492
|
-
removeInaccessibleElements(schema);
|
|
1493
|
-
schema.validate();
|
|
1494
|
-
const interfaceType = schema.elementByCoordinate("Interface");
|
|
1495
|
-
expect(interfaceType instanceof InterfaceType).toBeTruthy();
|
|
1496
|
-
expect(
|
|
1497
|
-
(interfaceType as InterfaceType).implementsInterface("Referencer1")
|
|
1498
|
-
).toBeTruthy();
|
|
1499
|
-
expect(
|
|
1500
|
-
(interfaceType as InterfaceType).implementsInterface("Referencer2")
|
|
1501
|
-
).toBeFalsy();
|
|
1502
|
-
expect(schema.elementByCoordinate("Interface.someField")).toBeDefined();
|
|
1503
|
-
expect(
|
|
1504
|
-
schema.elementByCoordinate("Interface.privateField")
|
|
1505
|
-
).toBeUndefined();
|
|
1506
|
-
expect(schema.elementByCoordinate("Referencer1.someField")).toBeDefined();
|
|
1507
|
-
expect(
|
|
1508
|
-
schema.elementByCoordinate("Referencer1.privatefield")
|
|
1509
|
-
).toBeUndefined();
|
|
1510
|
-
expect(schema.elementByCoordinate("Referencer2")).toBeUndefined();
|
|
1511
|
-
expect(schema.elementByCoordinate("Referencer3")).toBeUndefined();
|
|
1512
|
-
});
|
|
1513
|
-
|
|
1514
|
-
it(`fails to remove @inaccessible interface fields for breaking removals`, () => {
|
|
1515
|
-
const schema = buildSchema(`
|
|
1516
|
-
${INACCESSIBLE_V02_HEADER}
|
|
1517
|
-
|
|
1518
|
-
type Query {
|
|
1519
|
-
someField: String
|
|
1520
|
-
}
|
|
1521
|
-
|
|
1522
|
-
# Inaccessible interface field
|
|
1523
|
-
interface Interface implements Referencer1 {
|
|
1524
|
-
someField: String
|
|
1525
|
-
privateField: String @inaccessible
|
|
1526
|
-
}
|
|
1527
|
-
|
|
1528
|
-
# Inaccessible interface field can't be referenced by interface field in
|
|
1529
|
-
# the API schema
|
|
1530
|
-
interface Referencer1 {
|
|
1531
|
-
privateField: String
|
|
1532
|
-
}
|
|
1533
|
-
|
|
1534
|
-
# Inaccessible interface field can't have a non-inaccessible parent object
|
|
1535
|
-
# type and no non-inaccessible siblings
|
|
1536
|
-
interface Referencer2 {
|
|
1537
|
-
privateField: String @inaccessible
|
|
1538
|
-
otherPrivateField: Float @inaccessible
|
|
1539
|
-
}
|
|
1540
|
-
`);
|
|
1541
|
-
|
|
1542
|
-
const errorMessages = expectErrors(2, () => {
|
|
1543
|
-
removeInaccessibleElements(schema);
|
|
1544
|
-
});
|
|
1545
|
-
|
|
1546
|
-
expect(errorMessages).toMatchInlineSnapshot(`
|
|
1547
|
-
Array [
|
|
1548
|
-
"Field \\"Interface.privateField\\" is @inaccessible but implements the interface field \\"Referencer1.privateField\\", which is in the API schema.",
|
|
1549
|
-
"Type \\"Referencer2\\" is in the API schema but all of its fields are @inaccessible.",
|
|
1550
|
-
]
|
|
1551
|
-
`);
|
|
1552
|
-
});
|
|
1553
|
-
|
|
1554
|
-
it(`removes @inaccessible object field arguments`, () => {
|
|
1555
|
-
const schema = buildSchema(`
|
|
1556
|
-
${INACCESSIBLE_V02_HEADER}
|
|
1557
|
-
|
|
1558
|
-
# Inaccessible object field argument in query type
|
|
1559
|
-
type Query {
|
|
1560
|
-
someField(privateArg: String @inaccessible): String
|
|
1561
|
-
}
|
|
1562
|
-
|
|
1563
|
-
# Inaccessible object field argument in mutation type
|
|
1564
|
-
type Mutation {
|
|
1565
|
-
someField(privateArg: String @inaccessible): String
|
|
1566
|
-
}
|
|
1567
|
-
|
|
1568
|
-
# Inaccessible object field argument in subscription type
|
|
1569
|
-
type Subscription {
|
|
1570
|
-
someField(privateArg: String @inaccessible): String
|
|
1571
|
-
}
|
|
1572
|
-
|
|
1573
|
-
# Inaccessible (and non-inaccessible) object field argument
|
|
1574
|
-
type Object implements Referencer1 & Referencer2 & Referencer3 {
|
|
1575
|
-
someField(
|
|
1576
|
-
someArg: String,
|
|
1577
|
-
privateArg: String @inaccessible
|
|
1578
|
-
): String
|
|
1579
|
-
someOtherField: Float
|
|
1580
|
-
}
|
|
1581
|
-
|
|
1582
|
-
# Inaccessible object field argument referenced by inaccessible interface
|
|
1583
|
-
# field argument
|
|
1584
|
-
interface Referencer1 {
|
|
1585
|
-
someField(
|
|
1586
|
-
someArg: String,
|
|
1587
|
-
privateArg: String @inaccessible
|
|
1588
|
-
): String
|
|
1589
|
-
}
|
|
1590
|
-
|
|
1591
|
-
# Inaccessible object field argument referenced by non-inaccessible
|
|
1592
|
-
# interface field argument with inaccessible parent
|
|
1593
|
-
interface Referencer2 {
|
|
1594
|
-
someField(
|
|
1595
|
-
someArg: String,
|
|
1596
|
-
privateArg: String
|
|
1597
|
-
): String @inaccessible
|
|
1598
|
-
someOtherField: Float
|
|
1599
|
-
}
|
|
1600
|
-
|
|
1601
|
-
# Inaccessible object field argument referenced by non-inaccessible
|
|
1602
|
-
# interface field argument with inaccessible grandparent
|
|
1603
|
-
interface Referencer3 @inaccessible {
|
|
1604
|
-
someField(
|
|
1605
|
-
someArg: String,
|
|
1606
|
-
privateArg: String
|
|
1607
|
-
): String
|
|
1608
|
-
}
|
|
1609
|
-
|
|
1610
|
-
# Inaccessible non-nullable object field argument with default
|
|
1611
|
-
type ObjectDefault {
|
|
1612
|
-
someField(privateArg: String! = "default" @inaccessible): String
|
|
1613
|
-
}
|
|
1614
|
-
`);
|
|
1615
|
-
|
|
1616
|
-
removeInaccessibleElements(schema);
|
|
1617
|
-
schema.validate();
|
|
1618
|
-
expect(schema.elementByCoordinate("Query.someField")).toBeDefined();
|
|
1619
|
-
expect(
|
|
1620
|
-
schema.elementByCoordinate("Query.someField(privateArg:)")
|
|
1621
|
-
).toBeUndefined();
|
|
1622
|
-
expect(schema.elementByCoordinate("Mutation.someField")).toBeDefined();
|
|
1623
|
-
expect(
|
|
1624
|
-
schema.elementByCoordinate("Mutation.someField(privateArg:)")
|
|
1625
|
-
).toBeUndefined();
|
|
1626
|
-
expect(schema.elementByCoordinate("Subscription.someField")).toBeDefined();
|
|
1627
|
-
expect(
|
|
1628
|
-
schema.elementByCoordinate("Subscription.someField(privateArg:)")
|
|
1629
|
-
).toBeUndefined();
|
|
1630
|
-
const objectType = schema.elementByCoordinate("Object");
|
|
1631
|
-
expect(objectType instanceof ObjectType).toBeTruthy();
|
|
1632
|
-
expect(
|
|
1633
|
-
(objectType as ObjectType).implementsInterface("Referencer1")
|
|
1634
|
-
).toBeTruthy();
|
|
1635
|
-
expect(
|
|
1636
|
-
(objectType as ObjectType).implementsInterface("Referencer2")
|
|
1637
|
-
).toBeTruthy();
|
|
1638
|
-
expect(
|
|
1639
|
-
(objectType as ObjectType).implementsInterface("Referencer3")
|
|
1640
|
-
).toBeFalsy();
|
|
1641
|
-
expect(
|
|
1642
|
-
schema.elementByCoordinate("Object.someField(someArg:)")
|
|
1643
|
-
).toBeDefined();
|
|
1644
|
-
expect(
|
|
1645
|
-
schema.elementByCoordinate("Object.someField(privateArg:)")
|
|
1646
|
-
).toBeUndefined();
|
|
1647
|
-
expect(schema.elementByCoordinate("Referencer1.someField")).toBeDefined();
|
|
1648
|
-
expect(
|
|
1649
|
-
schema.elementByCoordinate("Referencer1.someField(privateArg:)")
|
|
1650
|
-
).toBeUndefined();
|
|
1651
|
-
expect(schema.elementByCoordinate("Referencer2")).toBeDefined();
|
|
1652
|
-
expect(schema.elementByCoordinate("Referencer2.someField")).toBeUndefined();
|
|
1653
|
-
expect(schema.elementByCoordinate("Referencer3")).toBeUndefined();
|
|
1654
|
-
expect(schema.elementByCoordinate("ObjectDefault.someField")).toBeDefined();
|
|
1655
|
-
expect(
|
|
1656
|
-
schema.elementByCoordinate("ObjectDefault.someField(privateArg:)")
|
|
1657
|
-
).toBeUndefined();
|
|
1658
|
-
});
|
|
1659
|
-
|
|
1660
|
-
it(`fails to remove @inaccessible object field arguments for breaking removals`, () => {
|
|
1661
|
-
const schema = buildSchema(`
|
|
1662
|
-
${INACCESSIBLE_V02_HEADER}
|
|
1663
|
-
|
|
1664
|
-
type Query {
|
|
1665
|
-
someField(someArg: String): String
|
|
1666
|
-
}
|
|
1667
|
-
|
|
1668
|
-
# Inaccessible object field argument
|
|
1669
|
-
type Object implements Referencer1 {
|
|
1670
|
-
someField(privateArg: String @inaccessible): String
|
|
1671
|
-
}
|
|
1672
|
-
|
|
1673
|
-
# Inaccessible object field argument can't be referenced by interface
|
|
1674
|
-
# field argument in the API schema
|
|
1675
|
-
interface Referencer1 {
|
|
1676
|
-
someField(privateArg: String): String
|
|
1677
|
-
}
|
|
1678
|
-
|
|
1679
|
-
# Inaccessible object field argument can't be a required argument
|
|
1680
|
-
type ObjectRequired {
|
|
1681
|
-
someField(privateArg: String! @inaccessible): String
|
|
1682
|
-
}
|
|
1683
|
-
`);
|
|
1684
|
-
|
|
1685
|
-
const errorMessages = expectErrors(2, () => {
|
|
1686
|
-
removeInaccessibleElements(schema);
|
|
1687
|
-
});
|
|
1688
|
-
|
|
1689
|
-
expect(errorMessages).toMatchInlineSnapshot(`
|
|
1690
|
-
Array [
|
|
1691
|
-
"Argument \\"Object.someField(privateArg:)\\" is @inaccessible but implements the interface argument \\"Referencer1.someField(privateArg:)\\", which is in the API schema.",
|
|
1692
|
-
"Argument \\"ObjectRequired.someField(privateArg:)\\" is @inaccessible but is a required argument of its field.",
|
|
1693
|
-
]
|
|
1694
|
-
`);
|
|
1695
|
-
});
|
|
1696
|
-
|
|
1697
|
-
it(`removes @inaccessible interface field arguments`, () => {
|
|
1698
|
-
const schema = buildSchema(`
|
|
1699
|
-
${INACCESSIBLE_V02_HEADER}
|
|
1700
|
-
|
|
1701
|
-
type Query {
|
|
1702
|
-
someField: String
|
|
1703
|
-
}
|
|
1704
|
-
|
|
1705
|
-
# Inaccessible (and non-inaccessible) interface field argument
|
|
1706
|
-
interface Interface implements Referencer1 & Referencer2 & Referencer3 {
|
|
1707
|
-
someField(
|
|
1708
|
-
someArg: String,
|
|
1709
|
-
privateArg: String @inaccessible
|
|
1710
|
-
): String
|
|
1711
|
-
someOtherField: Float
|
|
1712
|
-
}
|
|
1713
|
-
|
|
1714
|
-
# Inaccessible interface field argument referenced by inaccessible
|
|
1715
|
-
# interface field argument
|
|
1716
|
-
interface Referencer1 {
|
|
1717
|
-
someField(
|
|
1718
|
-
someArg: String,
|
|
1719
|
-
privateArg: String @inaccessible
|
|
1720
|
-
): String
|
|
1721
|
-
}
|
|
1722
|
-
|
|
1723
|
-
# Inaccessible interface field argument referenced by non-inaccessible
|
|
1724
|
-
# interface field argument with inaccessible parent
|
|
1725
|
-
interface Referencer2 {
|
|
1726
|
-
someField(
|
|
1727
|
-
someArg: String,
|
|
1728
|
-
privateArg: String
|
|
1729
|
-
): String @inaccessible
|
|
1730
|
-
someOtherField: Float
|
|
1731
|
-
}
|
|
1732
|
-
|
|
1733
|
-
# Inaccessible interface field argument referenced by non-inaccessible
|
|
1734
|
-
# interface field argument with inaccessible grandparent
|
|
1735
|
-
interface Referencer3 @inaccessible {
|
|
1736
|
-
someField(
|
|
1737
|
-
someArg: String,
|
|
1738
|
-
privateArg: String
|
|
1739
|
-
): String
|
|
1740
|
-
}
|
|
1741
|
-
|
|
1742
|
-
# Inaccessible non-nullable interface field argument with default
|
|
1743
|
-
interface InterfaceDefault {
|
|
1744
|
-
someField(privateArg: String! = "default" @inaccessible): String
|
|
1745
|
-
}
|
|
1746
|
-
|
|
1747
|
-
# Inaccessible interface field argument referenced by non-inaccessible
|
|
1748
|
-
# non-required object field argument
|
|
1749
|
-
type Referencer4 implements InterfaceDefault {
|
|
1750
|
-
someField(privateArg: String! = "default"): String
|
|
1751
|
-
}
|
|
1752
|
-
|
|
1753
|
-
# Inaccessible interface field argument referenced by non-inaccessible
|
|
1754
|
-
# required object field argument with inaccessible grandparent
|
|
1755
|
-
type Referencer5 implements InterfaceDefault @inaccessible {
|
|
1756
|
-
someField(privateArg: String!): String
|
|
1757
|
-
}
|
|
1758
|
-
|
|
1759
|
-
# Inaccessible interface field argument referenced by non-inaccessible
|
|
1760
|
-
# non-required interface field argument
|
|
1761
|
-
interface Referencer6 implements InterfaceDefault {
|
|
1762
|
-
someField(privateArg: String! = "default"): String
|
|
1763
|
-
}
|
|
1764
|
-
|
|
1765
|
-
# Inaccessible interface field argument referenced by non-inaccessible
|
|
1766
|
-
# required interface field argument with inaccessible grandparent
|
|
1767
|
-
interface Referencer7 implements InterfaceDefault @inaccessible {
|
|
1768
|
-
someField(privateArg: String!): String
|
|
1769
|
-
}
|
|
1770
|
-
`);
|
|
1771
|
-
|
|
1772
|
-
removeInaccessibleElements(schema);
|
|
1773
|
-
schema.validate();
|
|
1774
|
-
const interfaceType = schema.elementByCoordinate("Interface");
|
|
1775
|
-
expect(interfaceType instanceof InterfaceType).toBeTruthy();
|
|
1776
|
-
expect(
|
|
1777
|
-
(interfaceType as InterfaceType).implementsInterface("Referencer1")
|
|
1778
|
-
).toBeTruthy();
|
|
1779
|
-
expect(
|
|
1780
|
-
(interfaceType as InterfaceType).implementsInterface("Referencer2")
|
|
1781
|
-
).toBeTruthy();
|
|
1782
|
-
expect(
|
|
1783
|
-
(interfaceType as InterfaceType).implementsInterface("Referencer3")
|
|
1784
|
-
).toBeFalsy();
|
|
1785
|
-
expect(
|
|
1786
|
-
schema.elementByCoordinate("Interface.someField(someArg:)")
|
|
1787
|
-
).toBeDefined();
|
|
1788
|
-
expect(
|
|
1789
|
-
schema.elementByCoordinate("Interface.someField(privateArg:)")
|
|
1790
|
-
).toBeUndefined();
|
|
1791
|
-
expect(schema.elementByCoordinate("Referencer1.someField")).toBeDefined();
|
|
1792
|
-
expect(
|
|
1793
|
-
schema.elementByCoordinate("Referencer1.someField(privateArg:)")
|
|
1794
|
-
).toBeUndefined();
|
|
1795
|
-
expect(schema.elementByCoordinate("Referencer2")).toBeDefined();
|
|
1796
|
-
expect(schema.elementByCoordinate("Referencer2.someField")).toBeUndefined();
|
|
1797
|
-
expect(schema.elementByCoordinate("Referencer3")).toBeUndefined();
|
|
1798
|
-
expect(schema.elementByCoordinate("Interface.someField")).toBeDefined();
|
|
1799
|
-
expect(
|
|
1800
|
-
schema.elementByCoordinate("Interface.someField(privateArg:)")
|
|
1801
|
-
).toBeUndefined();
|
|
1802
|
-
const objectArg = schema.elementByCoordinate(
|
|
1803
|
-
"Referencer4.someField(privateArg:)"
|
|
1804
|
-
);
|
|
1805
|
-
expect(objectArg instanceof ArgumentDefinition).toBeTruthy();
|
|
1806
|
-
expect(
|
|
1807
|
-
(
|
|
1808
|
-
objectArg as ArgumentDefinition<FieldDefinition<ObjectType>>
|
|
1809
|
-
).isRequired()
|
|
1810
|
-
).toBeFalsy();
|
|
1811
|
-
expect(schema.elementByCoordinate("Referencer5")).toBeUndefined();
|
|
1812
|
-
const interfaceArg = schema.elementByCoordinate(
|
|
1813
|
-
"Referencer6.someField(privateArg:)"
|
|
1814
|
-
);
|
|
1815
|
-
expect(interfaceArg instanceof ArgumentDefinition).toBeTruthy();
|
|
1816
|
-
expect(
|
|
1817
|
-
(
|
|
1818
|
-
interfaceArg as ArgumentDefinition<FieldDefinition<InterfaceType>>
|
|
1819
|
-
).isRequired()
|
|
1820
|
-
).toBeFalsy();
|
|
1821
|
-
expect(schema.elementByCoordinate("Referencer7")).toBeUndefined();
|
|
1822
|
-
});
|
|
1823
|
-
|
|
1824
|
-
it(`fails to remove @inaccessible interface field arguments for breaking removals`, () => {
|
|
1825
|
-
const schema = buildSchema(`
|
|
1826
|
-
${INACCESSIBLE_V02_HEADER}
|
|
1827
|
-
|
|
1828
|
-
type Query {
|
|
1829
|
-
someField(someArg: String): String
|
|
1830
|
-
}
|
|
1831
|
-
|
|
1832
|
-
# Inaccessible interface field argument
|
|
1833
|
-
interface Interface implements Referencer1 {
|
|
1834
|
-
someField(privateArg: String! = "default" @inaccessible): String
|
|
1835
|
-
}
|
|
1836
|
-
|
|
1837
|
-
# Inaccessible interface field argument can't be referenced by interface
|
|
1838
|
-
# field argument in the API schema
|
|
1839
|
-
interface Referencer1 {
|
|
1840
|
-
someField(privateArg: String! = "default"): String
|
|
1841
|
-
}
|
|
1842
|
-
|
|
1843
|
-
# Inaccessible object field argument can't be a required argument
|
|
1844
|
-
type InterfaceRequired {
|
|
1845
|
-
someField(privateArg: String! @inaccessible): String
|
|
1846
|
-
}
|
|
1847
|
-
|
|
1848
|
-
# Inaccessible object field argument can't be implemented by a required
|
|
1849
|
-
# object field argument in the API schema
|
|
1850
|
-
type Referencer2 implements Interface & Referencer1 {
|
|
1851
|
-
someField(privateArg: String!): String
|
|
1852
|
-
}
|
|
1853
|
-
|
|
1854
|
-
# Inaccessible object field argument can't be implemented by a required
|
|
1855
|
-
# interface field argument in the API schema
|
|
1856
|
-
interface Referencer3 implements Interface & Referencer1 {
|
|
1857
|
-
someField(privateArg: String!): String
|
|
1858
|
-
}
|
|
1859
|
-
`);
|
|
1860
|
-
|
|
1861
|
-
const errorMessages = expectErrors(4, () => {
|
|
1862
|
-
removeInaccessibleElements(schema);
|
|
1863
|
-
});
|
|
1864
|
-
|
|
1865
|
-
expect(errorMessages).toMatchInlineSnapshot(`
|
|
1866
|
-
Array [
|
|
1867
|
-
"Argument \\"Interface.someField(privateArg:)\\" is @inaccessible but implements the interface argument \\"Referencer1.someField(privateArg:)\\", which is in the API schema.",
|
|
1868
|
-
"Argument \\"Interface.someField(privateArg:)\\" is @inaccessible but is implemented by the required argument \\"Referencer2.someField(privateArg:)\\", which is in the API schema.",
|
|
1869
|
-
"Argument \\"Interface.someField(privateArg:)\\" is @inaccessible but is implemented by the required argument \\"Referencer3.someField(privateArg:)\\", which is in the API schema.",
|
|
1870
|
-
"Argument \\"InterfaceRequired.someField(privateArg:)\\" is @inaccessible but is a required argument of its field.",
|
|
1871
|
-
]
|
|
1872
|
-
`);
|
|
1873
|
-
});
|
|
1874
|
-
|
|
1875
|
-
it(`removes @inaccessible input object fields`, () => {
|
|
1876
|
-
const schema = buildSchema(`
|
|
1877
|
-
${INACCESSIBLE_V02_HEADER}
|
|
1878
|
-
|
|
1879
|
-
type Query {
|
|
1880
|
-
someField: String
|
|
1881
|
-
}
|
|
1882
|
-
|
|
1883
|
-
# Inaccessible (and non-inaccessible) input object field
|
|
1884
|
-
input InputObject {
|
|
1885
|
-
someField: String
|
|
1886
|
-
privateField: String @inaccessible
|
|
1887
|
-
}
|
|
1888
|
-
|
|
1889
|
-
# Inaccessible input object field referenced by default value of
|
|
1890
|
-
# inaccessible object field argument
|
|
1891
|
-
type Referencer1 implements Referencer4 {
|
|
1892
|
-
someField(
|
|
1893
|
-
privateArg: InputObject = { privateField: "" } @inaccessible
|
|
1894
|
-
): String
|
|
1895
|
-
}
|
|
1896
|
-
|
|
1897
|
-
# Inaccessible input object field referenced by default value of
|
|
1898
|
-
# non-inaccessible object field argument with inaccessible parent
|
|
1899
|
-
type Referencer2 implements Referencer5 {
|
|
1900
|
-
someField: String
|
|
1901
|
-
privateField(
|
|
1902
|
-
privateArg: InputObject! = { privateField: "" }
|
|
1903
|
-
): String @inaccessible
|
|
1904
|
-
}
|
|
1905
|
-
|
|
1906
|
-
# Inaccessible input object field referenced by default value of
|
|
1907
|
-
# non-inaccessible object field argument with inaccessible grandparent
|
|
1908
|
-
type Referencer3 implements Referencer6 @inaccessible {
|
|
1909
|
-
privateField(privateArg: InputObject! = { privateField: "" }): String
|
|
1910
|
-
}
|
|
1911
|
-
|
|
1912
|
-
# Inaccessible input object field referenced by default value of
|
|
1913
|
-
# inaccessible interface field argument
|
|
1914
|
-
interface Referencer4 {
|
|
1915
|
-
someField(
|
|
1916
|
-
privateArg: InputObject = { privateField: "" } @inaccessible
|
|
1917
|
-
): String
|
|
1918
|
-
}
|
|
1919
|
-
|
|
1920
|
-
# Inaccessible input object field referenced by default value of
|
|
1921
|
-
# non-inaccessible interface field argument with inaccessible parent
|
|
1922
|
-
interface Referencer5 {
|
|
1923
|
-
someField: String
|
|
1924
|
-
privateField(
|
|
1925
|
-
privateArg: InputObject! = { privateField: "" }
|
|
1926
|
-
): String @inaccessible
|
|
1927
|
-
}
|
|
1928
|
-
|
|
1929
|
-
# Inaccessible input object field referenced by default value of
|
|
1930
|
-
# non-inaccessible interface field argument with inaccessible grandparent
|
|
1931
|
-
interface Referencer6 @inaccessible {
|
|
1932
|
-
privateField(privateArg: InputObject! = { privateField: "" }): String
|
|
1933
|
-
}
|
|
1934
|
-
|
|
1935
|
-
# Inaccessible input object field referenced by default value of
|
|
1936
|
-
# inaccessible input object field
|
|
1937
|
-
input Referencer7 {
|
|
1938
|
-
someField: String
|
|
1939
|
-
privateField: InputObject = { privateField: "" } @inaccessible
|
|
1940
|
-
}
|
|
1941
|
-
|
|
1942
|
-
# Inaccessible input object field referenced by default value of
|
|
1943
|
-
# non-inaccessible input object field with inaccessible parent
|
|
1944
|
-
input Referencer8 @inaccessible {
|
|
1945
|
-
privateField: InputObject! = { privateField: "" }
|
|
1946
|
-
}
|
|
1947
|
-
|
|
1948
|
-
# Inaccessible input object field referenced by default value of
|
|
1949
|
-
# inaccessible directive argument
|
|
1950
|
-
directive @referencer9(
|
|
1951
|
-
privateArg: InputObject = { privateField: "" } @inaccessible
|
|
1952
|
-
) on SUBSCRIPTION
|
|
1953
|
-
|
|
1954
|
-
# Inaccessible input object field not referenced (but type is referenced)
|
|
1955
|
-
# by default value of object field argument in the API schema
|
|
1956
|
-
type Referencer10 {
|
|
1957
|
-
someField(privateArg: InputObject = { someField: "" }): String
|
|
1958
|
-
}
|
|
1959
|
-
|
|
1960
|
-
# Inaccessible input object field with an inaccessible parent and no
|
|
1961
|
-
# non-inaccessible siblings
|
|
1962
|
-
input Referencer11 @inaccessible {
|
|
1963
|
-
privateField: String @inaccessible
|
|
1964
|
-
otherPrivateField: Float @inaccessible
|
|
1965
|
-
}
|
|
1966
|
-
|
|
1967
|
-
# Inaccessible non-nullable input object field with default
|
|
1968
|
-
input InputObjectDefault {
|
|
1969
|
-
someField: String
|
|
1970
|
-
privateField: String! = "default" @inaccessible
|
|
1971
|
-
}
|
|
1972
|
-
`);
|
|
1973
|
-
|
|
1974
|
-
removeInaccessibleElements(schema);
|
|
1975
|
-
schema.validate();
|
|
1976
|
-
expect(schema.elementByCoordinate("InputObject.someField")).toBeDefined();
|
|
1977
|
-
expect(
|
|
1978
|
-
schema.elementByCoordinate("InputObject.privateField")
|
|
1979
|
-
).toBeUndefined();
|
|
1980
|
-
expect(schema.elementByCoordinate("Referencer1.someField")).toBeDefined();
|
|
1981
|
-
expect(
|
|
1982
|
-
schema.elementByCoordinate("Referencer1.someField(privateArg:)")
|
|
1983
|
-
).toBeUndefined();
|
|
1984
|
-
expect(schema.elementByCoordinate("Referencer2.someField")).toBeDefined();
|
|
1985
|
-
expect(
|
|
1986
|
-
schema.elementByCoordinate("Referencer2.privateField")
|
|
1987
|
-
).toBeUndefined();
|
|
1988
|
-
expect(schema.elementByCoordinate("Referencer3")).toBeUndefined();
|
|
1989
|
-
expect(schema.elementByCoordinate("Referencer4.someField")).toBeDefined();
|
|
1990
|
-
expect(
|
|
1991
|
-
schema.elementByCoordinate("Referencer4.someField(privateArg:)")
|
|
1992
|
-
).toBeUndefined();
|
|
1993
|
-
expect(schema.elementByCoordinate("Referencer5.someField")).toBeDefined();
|
|
1994
|
-
expect(
|
|
1995
|
-
schema.elementByCoordinate("Referencer5.privateField")
|
|
1996
|
-
).toBeUndefined();
|
|
1997
|
-
expect(schema.elementByCoordinate("Referencer6")).toBeUndefined();
|
|
1998
|
-
expect(schema.elementByCoordinate("Referencer7.someField")).toBeDefined();
|
|
1999
|
-
expect(
|
|
2000
|
-
schema.elementByCoordinate("Referencer7.privatefield")
|
|
2001
|
-
).toBeUndefined();
|
|
2002
|
-
expect(schema.elementByCoordinate("Referencer8")).toBeUndefined();
|
|
2003
|
-
expect(schema.elementByCoordinate("@referencer9")).toBeDefined();
|
|
2004
|
-
expect(
|
|
2005
|
-
schema.elementByCoordinate("@referencer9(privateArg:)")
|
|
2006
|
-
).toBeUndefined();
|
|
2007
|
-
expect(
|
|
2008
|
-
schema.elementByCoordinate("Referencer10.someField(privateArg:)")
|
|
2009
|
-
).toBeDefined();
|
|
2010
|
-
expect(schema.elementByCoordinate("Referencer11")).toBeUndefined();
|
|
2011
|
-
expect(
|
|
2012
|
-
schema.elementByCoordinate("InputObjectDefault.someField")
|
|
2013
|
-
).toBeDefined();
|
|
2014
|
-
expect(
|
|
2015
|
-
schema.elementByCoordinate("InputObjectDefault.privatefield")
|
|
2016
|
-
).toBeUndefined();
|
|
2017
|
-
});
|
|
2018
|
-
|
|
2019
|
-
it(`fails to remove @inaccessible input object fields for breaking removals`, () => {
|
|
2020
|
-
const schema = buildSchema(`
|
|
2021
|
-
${INACCESSIBLE_V02_HEADER}
|
|
2022
|
-
|
|
2023
|
-
type Query {
|
|
2024
|
-
someField: String
|
|
2025
|
-
}
|
|
2026
|
-
|
|
2027
|
-
# Inaccessible input object field
|
|
2028
|
-
input InputObject {
|
|
2029
|
-
someField: String
|
|
2030
|
-
privateField: String @inaccessible
|
|
2031
|
-
}
|
|
2032
|
-
|
|
2033
|
-
# Inaccessible input object field can't be referenced by default value of
|
|
2034
|
-
# object field argument in the API schema
|
|
2035
|
-
type Referencer1 implements Referencer2 {
|
|
2036
|
-
someField(someArg: InputObject = { privateField: "" }): String
|
|
2037
|
-
}
|
|
2038
|
-
|
|
2039
|
-
# Inaccessible input object field can't be referenced by default value of
|
|
2040
|
-
# interface field argument in the API schema
|
|
2041
|
-
interface Referencer2 {
|
|
2042
|
-
someField(someArg: InputObject = { privateField: "" }): String
|
|
2043
|
-
}
|
|
2044
|
-
|
|
2045
|
-
# Inaccessible input object field can't be referenced by default value of
|
|
2046
|
-
# input object field in the API schema
|
|
2047
|
-
input Referencer3 {
|
|
2048
|
-
someField: InputObject = { privateField: "" }
|
|
2049
|
-
}
|
|
2050
|
-
|
|
2051
|
-
# Inaccessible input object field can't be referenced by default value of
|
|
2052
|
-
# directive argument in the API schema
|
|
2053
|
-
directive @referencer4(
|
|
2054
|
-
someArg: InputObject = { privateField: "" }
|
|
2055
|
-
) on FIELD
|
|
2056
|
-
|
|
2057
|
-
# Inaccessible input object field can't have a non-inaccessible parent
|
|
2058
|
-
# and no non-inaccessible siblings
|
|
2059
|
-
input Referencer5 {
|
|
2060
|
-
privateField: String @inaccessible
|
|
2061
|
-
otherPrivateField: Float @inaccessible
|
|
2062
|
-
}
|
|
2063
|
-
|
|
2064
|
-
# Inaccessible input object field can't be a required field
|
|
2065
|
-
input InputObjectRequired {
|
|
2066
|
-
someField: String
|
|
2067
|
-
privateField: String! @inaccessible
|
|
2068
|
-
}
|
|
2069
|
-
`);
|
|
2070
|
-
|
|
2071
|
-
const errorMessages = expectErrors(6, () => {
|
|
2072
|
-
removeInaccessibleElements(schema);
|
|
2073
|
-
});
|
|
2074
|
-
|
|
2075
|
-
expect(errorMessages).toMatchInlineSnapshot(`
|
|
2076
|
-
Array [
|
|
2077
|
-
"Input field \\"InputObject.privateField\\" is @inaccessible but is used in the default value of \\"@referencer4(someArg:)\\", which is in the API schema.",
|
|
2078
|
-
"Input field \\"InputObject.privateField\\" is @inaccessible but is used in the default value of \\"Referencer1.someField(someArg:)\\", which is in the API schema.",
|
|
2079
|
-
"Input field \\"InputObject.privateField\\" is @inaccessible but is used in the default value of \\"Referencer2.someField(someArg:)\\", which is in the API schema.",
|
|
2080
|
-
"Input field \\"InputObject.privateField\\" is @inaccessible but is used in the default value of \\"Referencer3.someField\\", which is in the API schema.",
|
|
2081
|
-
"Input field \\"InputObjectRequired.privateField\\" is @inaccessible but is a required input field of its type.",
|
|
2082
|
-
"Type \\"Referencer5\\" is in the API schema but all of its input fields are @inaccessible.",
|
|
2083
|
-
]
|
|
2084
|
-
`);
|
|
2085
|
-
});
|
|
2086
|
-
|
|
2087
|
-
it(`removes @inaccessible enum values`, () => {
|
|
2088
|
-
const schema = buildSchema(`
|
|
2089
|
-
${INACCESSIBLE_V02_HEADER}
|
|
2090
|
-
|
|
2091
|
-
type Query {
|
|
2092
|
-
someField: String
|
|
2093
|
-
}
|
|
2094
|
-
|
|
2095
|
-
# Inaccessible (and non-inaccessible) enum value
|
|
2096
|
-
enum Enum {
|
|
2097
|
-
SOME_VALUE
|
|
2098
|
-
PRIVATE_VALUE @inaccessible
|
|
2099
|
-
}
|
|
2100
|
-
|
|
2101
|
-
# Inaccessible enum value referenced by default value of inaccessible
|
|
2102
|
-
# object field argument
|
|
2103
|
-
type Referencer1 implements Referencer4 {
|
|
2104
|
-
someField(
|
|
2105
|
-
privateArg: Enum = PRIVATE_VALUE @inaccessible
|
|
2106
|
-
): String
|
|
2107
|
-
}
|
|
2108
|
-
|
|
2109
|
-
# Inaccessible enum value referenced by default value of non-inaccessible
|
|
2110
|
-
# object field argument with inaccessible parent
|
|
2111
|
-
type Referencer2 implements Referencer5 {
|
|
2112
|
-
someField: String
|
|
2113
|
-
privateField(
|
|
2114
|
-
privateArg: Enum! = PRIVATE_VALUE
|
|
2115
|
-
): String @inaccessible
|
|
2116
|
-
}
|
|
2117
|
-
|
|
2118
|
-
# Inaccessible enum value referenced by default value of non-inaccessible
|
|
2119
|
-
# object field argument with inaccessible grandparent
|
|
2120
|
-
type Referencer3 implements Referencer6 @inaccessible {
|
|
2121
|
-
privateField(privateArg: Enum! = PRIVATE_VALUE): String
|
|
2122
|
-
}
|
|
2123
|
-
|
|
2124
|
-
# Inaccessible enum value referenced by default value of inaccessible
|
|
2125
|
-
# interface field argument
|
|
2126
|
-
interface Referencer4 {
|
|
2127
|
-
someField(
|
|
2128
|
-
privateArg: Enum = PRIVATE_VALUE @inaccessible
|
|
2129
|
-
): String
|
|
2130
|
-
}
|
|
2131
|
-
|
|
2132
|
-
# Inaccessible enum value referenced by default value of non-inaccessible
|
|
2133
|
-
# interface field argument with inaccessible parent
|
|
2134
|
-
interface Referencer5 {
|
|
2135
|
-
someField: String
|
|
2136
|
-
privateField(
|
|
2137
|
-
privateArg: Enum! = PRIVATE_VALUE
|
|
2138
|
-
): String @inaccessible
|
|
2139
|
-
}
|
|
2140
|
-
|
|
2141
|
-
# Inaccessible enum value referenced by default value of non-inaccessible
|
|
2142
|
-
# interface field argument with inaccessible grandparent
|
|
2143
|
-
interface Referencer6 @inaccessible {
|
|
2144
|
-
privateField(privateArg: Enum! = PRIVATE_VALUE): String
|
|
2145
|
-
}
|
|
2146
|
-
|
|
2147
|
-
# Inaccessible enum value referenced by default value of inaccessible
|
|
2148
|
-
# input object field
|
|
2149
|
-
input Referencer7 {
|
|
2150
|
-
someField: String
|
|
2151
|
-
privateField: Enum = PRIVATE_VALUE @inaccessible
|
|
2152
|
-
}
|
|
2153
|
-
|
|
2154
|
-
# Inaccessible enum value referenced by default value of non-inaccessible
|
|
2155
|
-
# input object field with inaccessible parent
|
|
2156
|
-
input Referencer8 @inaccessible {
|
|
2157
|
-
privateField: Enum! = PRIVATE_VALUE
|
|
2158
|
-
}
|
|
2159
|
-
|
|
2160
|
-
# Inaccessible enum value referenced by default value of inaccessible
|
|
2161
|
-
# directive argument
|
|
2162
|
-
directive @referencer9(
|
|
2163
|
-
privateArg: Enum = PRIVATE_VALUE @inaccessible
|
|
2164
|
-
) on FRAGMENT_SPREAD
|
|
2165
|
-
|
|
2166
|
-
# Inaccessible enum value not referenced (but type is referenced) by
|
|
2167
|
-
# default value of object field argument in the API schema
|
|
2168
|
-
type Referencer10 {
|
|
2169
|
-
someField(privateArg: Enum = SOME_VALUE): String
|
|
2170
|
-
}
|
|
2171
|
-
|
|
2172
|
-
# Inaccessible enum value with an inaccessible parent and no
|
|
2173
|
-
# non-inaccessible siblings
|
|
2174
|
-
enum Referencer11 @inaccessible {
|
|
2175
|
-
PRIVATE_VALUE @inaccessible
|
|
2176
|
-
OTHER_PRIVATE_VALUE @inaccessible
|
|
2177
|
-
}
|
|
2178
|
-
`);
|
|
2179
|
-
|
|
2180
|
-
removeInaccessibleElements(schema);
|
|
2181
|
-
schema.validate();
|
|
2182
|
-
expect(schema.elementByCoordinate("Enum.SOME_VALUE")).toBeDefined();
|
|
2183
|
-
expect(schema.elementByCoordinate("Enum.PRIVATE_VALUE")).toBeUndefined();
|
|
2184
|
-
expect(schema.elementByCoordinate("Referencer1.someField")).toBeDefined();
|
|
2185
|
-
expect(
|
|
2186
|
-
schema.elementByCoordinate("Referencer1.someField(privateArg:)")
|
|
2187
|
-
).toBeUndefined();
|
|
2188
|
-
expect(schema.elementByCoordinate("Referencer2.someField")).toBeDefined();
|
|
2189
|
-
expect(
|
|
2190
|
-
schema.elementByCoordinate("Referencer2.privateField")
|
|
2191
|
-
).toBeUndefined();
|
|
2192
|
-
expect(schema.elementByCoordinate("Referencer3")).toBeUndefined();
|
|
2193
|
-
expect(schema.elementByCoordinate("Referencer4.someField")).toBeDefined();
|
|
2194
|
-
expect(
|
|
2195
|
-
schema.elementByCoordinate("Referencer4.someField(privateArg:)")
|
|
2196
|
-
).toBeUndefined();
|
|
2197
|
-
expect(schema.elementByCoordinate("Referencer5.someField")).toBeDefined();
|
|
2198
|
-
expect(
|
|
2199
|
-
schema.elementByCoordinate("Referencer5.privateField")
|
|
2200
|
-
).toBeUndefined();
|
|
2201
|
-
expect(schema.elementByCoordinate("Referencer6")).toBeUndefined();
|
|
2202
|
-
expect(schema.elementByCoordinate("Referencer7.someField")).toBeDefined();
|
|
2203
|
-
expect(
|
|
2204
|
-
schema.elementByCoordinate("Referencer7.privatefield")
|
|
2205
|
-
).toBeUndefined();
|
|
2206
|
-
expect(schema.elementByCoordinate("Referencer8")).toBeUndefined();
|
|
2207
|
-
expect(schema.elementByCoordinate("@referencer9")).toBeDefined();
|
|
2208
|
-
expect(
|
|
2209
|
-
schema.elementByCoordinate("@referencer9(privateArg:)")
|
|
2210
|
-
).toBeUndefined();
|
|
2211
|
-
expect(
|
|
2212
|
-
schema.elementByCoordinate("Referencer10.someField(privateArg:)")
|
|
2213
|
-
).toBeDefined();
|
|
2214
|
-
expect(schema.elementByCoordinate("Referencer11")).toBeUndefined();
|
|
2215
|
-
});
|
|
2216
|
-
|
|
2217
|
-
it(`fails to remove @inaccessible enum values for breaking removals`, () => {
|
|
2218
|
-
const schema = buildSchema(`
|
|
2219
|
-
${INACCESSIBLE_V02_HEADER}
|
|
2220
|
-
|
|
2221
|
-
type Query {
|
|
2222
|
-
someField: String
|
|
2223
|
-
}
|
|
2224
|
-
|
|
2225
|
-
# Inaccessible enum value
|
|
2226
|
-
enum Enum {
|
|
2227
|
-
SOME_VALUE
|
|
2228
|
-
PRIVATE_VALUE @inaccessible
|
|
2229
|
-
}
|
|
2230
|
-
|
|
2231
|
-
# Inaccessible enum value can't be referenced by default value of object
|
|
2232
|
-
# field argument in the API schema
|
|
2233
|
-
type Referencer1 implements Referencer2 {
|
|
2234
|
-
someField(someArg: Enum = PRIVATE_VALUE): String
|
|
2235
|
-
}
|
|
2236
|
-
|
|
2237
|
-
# Inaccessible enum value can't be referenced by default value of
|
|
2238
|
-
# interface field argument in the API schema
|
|
2239
|
-
interface Referencer2 {
|
|
2240
|
-
someField(someArg: Enum = PRIVATE_VALUE): String
|
|
2241
|
-
}
|
|
2242
|
-
|
|
2243
|
-
# Inaccessible enum value can't be referenced by default value of input
|
|
2244
|
-
# object field in the API schema
|
|
2245
|
-
input Referencer3 {
|
|
2246
|
-
someField: Enum = PRIVATE_VALUE
|
|
2247
|
-
}
|
|
2248
|
-
|
|
2249
|
-
# Inaccessible input enum value can't be referenced by default value of
|
|
2250
|
-
# directive argument in the API schema
|
|
2251
|
-
directive @referencer4(someArg: Enum = PRIVATE_VALUE) on INLINE_FRAGMENT
|
|
2252
|
-
|
|
2253
|
-
# Inaccessible enum value can't have a non-inaccessible parent and no
|
|
2254
|
-
# non-inaccessible siblings
|
|
2255
|
-
enum Referencer5 {
|
|
2256
|
-
PRIVATE_VALUE @inaccessible
|
|
2257
|
-
OTHER_PRIVATE_VALUE @inaccessible
|
|
2258
|
-
}
|
|
2259
|
-
`);
|
|
2260
|
-
|
|
2261
|
-
const errorMessages = expectErrors(5, () => {
|
|
2262
|
-
removeInaccessibleElements(schema);
|
|
2263
|
-
});
|
|
2264
|
-
|
|
2265
|
-
expect(errorMessages).toMatchInlineSnapshot(`
|
|
2266
|
-
Array [
|
|
2267
|
-
"Enum value \\"Enum.PRIVATE_VALUE\\" is @inaccessible but is used in the default value of \\"@referencer4(someArg:)\\", which is in the API schema.",
|
|
2268
|
-
"Enum value \\"Enum.PRIVATE_VALUE\\" is @inaccessible but is used in the default value of \\"Referencer1.someField(someArg:)\\", which is in the API schema.",
|
|
2269
|
-
"Enum value \\"Enum.PRIVATE_VALUE\\" is @inaccessible but is used in the default value of \\"Referencer2.someField(someArg:)\\", which is in the API schema.",
|
|
2270
|
-
"Enum value \\"Enum.PRIVATE_VALUE\\" is @inaccessible but is used in the default value of \\"Referencer3.someField\\", which is in the API schema.",
|
|
2271
|
-
"Type \\"Referencer5\\" is in the API schema but all of its values are @inaccessible.",
|
|
2272
|
-
]
|
|
2273
|
-
`);
|
|
2274
|
-
});
|
|
2275
|
-
|
|
2276
|
-
it(`removes @inaccessible directive arguments`, () => {
|
|
2277
|
-
const schema = buildSchema(`
|
|
2278
|
-
${INACCESSIBLE_V02_HEADER}
|
|
2279
|
-
|
|
2280
|
-
type Query {
|
|
2281
|
-
someField: String
|
|
2282
|
-
}
|
|
2283
|
-
|
|
2284
|
-
# Inaccessible (and non-inaccessible) directive argument
|
|
2285
|
-
directive @directive(
|
|
2286
|
-
someArg: String
|
|
2287
|
-
privateArg: String @inaccessible
|
|
2288
|
-
) on QUERY
|
|
2289
|
-
|
|
2290
|
-
# Inaccessible non-nullable directive argument with default
|
|
2291
|
-
directive @directiveDefault(
|
|
2292
|
-
someArg: String
|
|
2293
|
-
privateArg: String! = "default" @inaccessible
|
|
2294
|
-
) on MUTATION
|
|
2295
|
-
`);
|
|
2296
|
-
|
|
2297
|
-
removeInaccessibleElements(schema);
|
|
2298
|
-
schema.validate();
|
|
2299
|
-
expect(schema.elementByCoordinate("@directive(someArg:)")).toBeDefined();
|
|
2300
|
-
expect(
|
|
2301
|
-
schema.elementByCoordinate("@directive(privateArg:)")
|
|
2302
|
-
).toBeUndefined();
|
|
2303
|
-
expect(
|
|
2304
|
-
schema.elementByCoordinate("@directiveDefault(someArg:)")
|
|
2305
|
-
).toBeDefined();
|
|
2306
|
-
expect(
|
|
2307
|
-
schema.elementByCoordinate("@directiveDefault(privateArg:)")
|
|
2308
|
-
).toBeUndefined();
|
|
2309
|
-
});
|
|
2310
|
-
|
|
2311
|
-
it(`fails to remove @inaccessible directive arguments for breaking removals`, () => {
|
|
2312
|
-
const schema = buildSchema(`
|
|
2313
|
-
${INACCESSIBLE_V02_HEADER}
|
|
2314
|
-
|
|
2315
|
-
type Query {
|
|
2316
|
-
someField: String
|
|
2317
|
-
}
|
|
2318
|
-
|
|
2319
|
-
# Inaccessible directive argument
|
|
2320
|
-
directive @directive(privateArg: String @inaccessible) on SUBSCRIPTION
|
|
2321
|
-
|
|
2322
|
-
# Inaccessible directive argument can't be a required field
|
|
2323
|
-
directive @directiveRequired(
|
|
2324
|
-
someArg: String
|
|
2325
|
-
privateArg: String! @inaccessible
|
|
2326
|
-
) on FRAGMENT_DEFINITION
|
|
2327
|
-
`);
|
|
2328
|
-
|
|
2329
|
-
const errorMessages = expectErrors(1, () => {
|
|
2330
|
-
removeInaccessibleElements(schema);
|
|
2331
|
-
});
|
|
2332
|
-
|
|
2333
|
-
expect(errorMessages).toMatchInlineSnapshot(`
|
|
2334
|
-
Array [
|
|
2335
|
-
"Argument \\"@directiveRequired(privateArg:)\\" is @inaccessible but is a required argument of its directive.",
|
|
2336
|
-
]
|
|
2337
|
-
`);
|
|
2338
|
-
});
|
|
2339
|
-
|
|
2340
|
-
it(`handles complex default values`, () => {
|
|
2341
|
-
const schema = buildSchema(`
|
|
2342
|
-
${INACCESSIBLE_V02_HEADER}
|
|
2343
|
-
|
|
2344
|
-
type Query {
|
|
2345
|
-
someField(arg1: [[RootInputObject!]]! = [
|
|
2346
|
-
{
|
|
2347
|
-
foo: {
|
|
2348
|
-
# 2 references (with nesting)
|
|
2349
|
-
privateField: [PRIVATE_VALUE]
|
|
2350
|
-
}
|
|
2351
|
-
bar: SOME_VALUE
|
|
2352
|
-
# 0 references since scalar
|
|
2353
|
-
baz: { privateField: PRIVATE_VALUE }
|
|
2354
|
-
},
|
|
2355
|
-
[{
|
|
2356
|
-
foo: [{
|
|
2357
|
-
someField: "foo"
|
|
2358
|
-
}]
|
|
2359
|
-
# 1 reference
|
|
2360
|
-
bar: PRIVATE_VALUE
|
|
2361
|
-
}]
|
|
2362
|
-
]): String
|
|
2363
|
-
}
|
|
2364
|
-
|
|
2365
|
-
input RootInputObject {
|
|
2366
|
-
foo: [NestedInputObject]
|
|
2367
|
-
bar: Enum!
|
|
2368
|
-
baz: Scalar! = { default: 4 }
|
|
2369
|
-
}
|
|
2370
|
-
|
|
2371
|
-
input NestedInputObject {
|
|
2372
|
-
someField: String
|
|
2373
|
-
privateField: [Enum!] @inaccessible
|
|
2374
|
-
}
|
|
2375
|
-
|
|
2376
|
-
enum Enum {
|
|
2377
|
-
SOME_VALUE
|
|
2378
|
-
PRIVATE_VALUE @inaccessible
|
|
2379
|
-
}
|
|
2380
|
-
|
|
2381
|
-
scalar Scalar
|
|
2382
|
-
`);
|
|
2383
|
-
|
|
2384
|
-
const errorMessages = expectErrors(3, () => {
|
|
2385
|
-
removeInaccessibleElements(schema);
|
|
2386
|
-
});
|
|
2387
|
-
|
|
2388
|
-
expect(errorMessages).toMatchInlineSnapshot(`
|
|
2389
|
-
Array [
|
|
2390
|
-
"Enum value \\"Enum.PRIVATE_VALUE\\" is @inaccessible but is used in the default value of \\"Query.someField(arg1:)\\", which is in the API schema.",
|
|
2391
|
-
"Enum value \\"Enum.PRIVATE_VALUE\\" is @inaccessible but is used in the default value of \\"Query.someField(arg1:)\\", which is in the API schema.",
|
|
2392
|
-
"Input field \\"NestedInputObject.privateField\\" is @inaccessible but is used in the default value of \\"Query.someField(arg1:)\\", which is in the API schema.",
|
|
2393
|
-
]
|
|
2394
|
-
`);
|
|
2395
|
-
});
|
|
2396
|
-
|
|
2397
|
-
// It's not GraphQL-spec-compliant to allow a string for an enum value, but
|
|
2398
|
-
// since we're allowing it, we need to make sure this logic keeps working
|
|
2399
|
-
// until we're allowed to make breaking changes and remove it.
|
|
2400
|
-
it(`handles string enum value in default value`, () => {
|
|
2401
|
-
const schema = buildSchema(`
|
|
2402
|
-
${INACCESSIBLE_V02_HEADER}
|
|
2403
|
-
|
|
2404
|
-
type Query {
|
|
2405
|
-
someField(arg1: Enum! = "PRIVATE_VALUE"): String
|
|
2406
|
-
}
|
|
2407
|
-
|
|
2408
|
-
enum Enum {
|
|
2409
|
-
SOME_VALUE
|
|
2410
|
-
PRIVATE_VALUE @inaccessible
|
|
2411
|
-
}
|
|
2412
|
-
`);
|
|
2413
|
-
|
|
2414
|
-
const errorMessages = expectErrors(1, () => {
|
|
2415
|
-
removeInaccessibleElements(schema);
|
|
2416
|
-
});
|
|
2417
|
-
|
|
2418
|
-
expect(errorMessages).toMatchInlineSnapshot(`
|
|
2419
|
-
Array [
|
|
2420
|
-
"Enum value \\"Enum.PRIVATE_VALUE\\" is @inaccessible but is used in the default value of \\"Query.someField(arg1:)\\", which is in the API schema.",
|
|
2421
|
-
]
|
|
2422
|
-
`);
|
|
2423
|
-
});
|
|
2424
|
-
|
|
2425
|
-
it(`fails to remove @inaccessible non-core feature elements referenced by core feature elements`, () => {
|
|
2426
|
-
const schema = buildSchema(`
|
|
2427
|
-
directive @core(feature: String!, as: String, for: core__Purpose) repeatable on SCHEMA
|
|
2428
|
-
|
|
2429
|
-
enum core__Purpose {
|
|
2430
|
-
EXECUTION
|
|
2431
|
-
SECURITY
|
|
2432
|
-
}
|
|
2433
|
-
|
|
2434
|
-
directive @inaccessible on FIELD_DEFINITION | OBJECT | INTERFACE | UNION | ARGUMENT_DEFINITION | SCALAR | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION
|
|
2435
|
-
|
|
2436
|
-
schema
|
|
2437
|
-
@core(feature: "https://specs.apollo.dev/core/v0.2")
|
|
2438
|
-
@core(feature: "https://specs.apollo.dev/inaccessible/v0.2")
|
|
2439
|
-
@core(feature: "http://localhost/foo/v1.0")
|
|
2440
|
-
{
|
|
2441
|
-
query: Query
|
|
2442
|
-
}
|
|
2443
|
-
|
|
2444
|
-
type Query {
|
|
2445
|
-
someField: String
|
|
2446
|
-
}
|
|
2447
|
-
|
|
2448
|
-
# Inaccessible input object field
|
|
2449
|
-
input InputObject {
|
|
2450
|
-
someField: String
|
|
2451
|
-
privateField: String @inaccessible
|
|
2452
|
-
}
|
|
2453
|
-
|
|
2454
|
-
# Inaccessible input object field can't be referenced by default value of
|
|
2455
|
-
# directive argument of a core feature element
|
|
2456
|
-
directive @foo__referencer(
|
|
2457
|
-
someArg: InputObject = { privateField: "" }
|
|
2458
|
-
) on FIELD
|
|
2459
|
-
`);
|
|
2460
|
-
|
|
2461
|
-
const errorMessages = expectErrors(1, () => {
|
|
2462
|
-
removeInaccessibleElements(schema);
|
|
2463
|
-
});
|
|
2464
|
-
|
|
2465
|
-
expect(errorMessages).toMatchInlineSnapshot(`
|
|
2466
|
-
Array [
|
|
2467
|
-
"Input field \\"InputObject.privateField\\" is @inaccessible but is used in the default value of \\"@foo__referencer(someArg:)\\", which is in the API schema.",
|
|
2468
|
-
]
|
|
2469
|
-
`);
|
|
2470
|
-
});
|
|
2471
|
-
});
|