@apollo/federation-internals 2.4.3 → 2.4.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -0
- package/package.json +1 -1
- package/dist/Subgraph.d.ts +0 -1
- package/dist/Subgraph.d.ts.map +0 -1
- package/dist/Subgraph.js +0 -2
- package/dist/Subgraph.js.map +0 -1
- package/dist/argumentCompositionStrategies.d.ts +0 -34
- package/dist/argumentCompositionStrategies.d.ts.map +0 -1
- package/dist/argumentCompositionStrategies.js +0 -35
- package/dist/argumentCompositionStrategies.js.map +0 -1
- package/dist/buildSchema.d.ts +0 -10
- package/dist/buildSchema.d.ts.map +0 -1
- package/dist/buildSchema.js +0 -362
- package/dist/buildSchema.js.map +0 -1
- package/dist/coreSpec.d.ts +0 -127
- package/dist/coreSpec.d.ts.map +0 -1
- package/dist/coreSpec.js +0 -590
- package/dist/coreSpec.js.map +0 -1
- package/dist/debug.d.ts +0 -15
- package/dist/debug.d.ts.map +0 -1
- package/dist/debug.js +0 -122
- package/dist/debug.js.map +0 -1
- package/dist/definitions.d.ts +0 -663
- package/dist/definitions.d.ts.map +0 -1
- package/dist/definitions.js +0 -2841
- package/dist/definitions.js.map +0 -1
- package/dist/directiveAndTypeSpecification.d.ts +0 -67
- package/dist/directiveAndTypeSpecification.d.ts.map +0 -1
- package/dist/directiveAndTypeSpecification.js +0 -271
- package/dist/directiveAndTypeSpecification.js.map +0 -1
- package/dist/error.d.ts +0 -128
- package/dist/error.d.ts.map +0 -1
- package/dist/error.js +0 -315
- package/dist/error.js.map +0 -1
- package/dist/extractSubgraphsFromSupergraph.d.ts +0 -8
- package/dist/extractSubgraphsFromSupergraph.d.ts.map +0 -1
- package/dist/extractSubgraphsFromSupergraph.js +0 -576
- package/dist/extractSubgraphsFromSupergraph.js.map +0 -1
- package/dist/federation.d.ts +0 -175
- package/dist/federation.d.ts.map +0 -1
- package/dist/federation.js +0 -1414
- package/dist/federation.js.map +0 -1
- package/dist/federationSpec.d.ts +0 -25
- package/dist/federationSpec.d.ts.map +0 -1
- package/dist/federationSpec.js +0 -125
- package/dist/federationSpec.js.map +0 -1
- package/dist/genErrorCodeDoc.d.ts +0 -2
- package/dist/genErrorCodeDoc.d.ts.map +0 -1
- package/dist/genErrorCodeDoc.js +0 -61
- package/dist/genErrorCodeDoc.js.map +0 -1
- package/dist/graphQLJSSchemaToAST.d.ts +0 -8
- package/dist/graphQLJSSchemaToAST.d.ts.map +0 -1
- package/dist/graphQLJSSchemaToAST.js +0 -96
- package/dist/graphQLJSSchemaToAST.js.map +0 -1
- package/dist/inaccessibleSpec.d.ts +0 -18
- package/dist/inaccessibleSpec.d.ts.map +0 -1
- package/dist/inaccessibleSpec.js +0 -655
- package/dist/inaccessibleSpec.js.map +0 -1
- package/dist/index.d.ts +0 -24
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -42
- package/dist/index.js.map +0 -1
- package/dist/introspection.d.ts +0 -6
- package/dist/introspection.d.ts.map +0 -1
- package/dist/introspection.js +0 -96
- package/dist/introspection.js.map +0 -1
- package/dist/joinSpec.d.ts +0 -51
- package/dist/joinSpec.d.ts.map +0 -1
- package/dist/joinSpec.js +0 -160
- package/dist/joinSpec.js.map +0 -1
- package/dist/knownCoreFeatures.d.ts +0 -5
- package/dist/knownCoreFeatures.d.ts.map +0 -1
- package/dist/knownCoreFeatures.js +0 -20
- package/dist/knownCoreFeatures.js.map +0 -1
- package/dist/operations.d.ts +0 -415
- package/dist/operations.d.ts.map +0 -1
- package/dist/operations.js +0 -2040
- package/dist/operations.js.map +0 -1
- package/dist/precompute.d.ts +0 -3
- package/dist/precompute.d.ts.map +0 -1
- package/dist/precompute.js +0 -54
- package/dist/precompute.js.map +0 -1
- package/dist/print.d.ts +0 -28
- package/dist/print.d.ts.map +0 -1
- package/dist/print.js +0 -299
- package/dist/print.js.map +0 -1
- package/dist/schemaUpgrader.d.ts +0 -121
- package/dist/schemaUpgrader.d.ts.map +0 -1
- package/dist/schemaUpgrader.js +0 -570
- package/dist/schemaUpgrader.js.map +0 -1
- package/dist/suggestions.d.ts +0 -3
- package/dist/suggestions.d.ts.map +0 -1
- package/dist/suggestions.js +0 -44
- package/dist/suggestions.js.map +0 -1
- package/dist/supergraphs.d.ts +0 -10
- package/dist/supergraphs.d.ts.map +0 -1
- package/dist/supergraphs.js +0 -76
- package/dist/supergraphs.js.map +0 -1
- package/dist/tagSpec.d.ts +0 -19
- package/dist/tagSpec.d.ts.map +0 -1
- package/dist/tagSpec.js +0 -66
- package/dist/tagSpec.js.map +0 -1
- package/dist/types.d.ts +0 -9
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -64
- package/dist/types.js.map +0 -1
- package/dist/utils.d.ts +0 -64
- package/dist/utils.d.ts.map +0 -1
- package/dist/utils.js +0 -326
- package/dist/utils.js.map +0 -1
- package/dist/validate.d.ts +0 -4
- package/dist/validate.d.ts.map +0 -1
- package/dist/validate.js +0 -239
- package/dist/validate.js.map +0 -1
- package/dist/validation/KnownTypeNamesInFederationRule.d.ts +0 -4
- package/dist/validation/KnownTypeNamesInFederationRule.d.ts.map +0 -1
- package/dist/validation/KnownTypeNamesInFederationRule.js +0 -41
- package/dist/validation/KnownTypeNamesInFederationRule.js.map +0 -1
- package/dist/values.d.ts +0 -23
- package/dist/values.d.ts.map +0 -1
- package/dist/values.js +0 -580
- package/dist/values.js.map +0 -1
- package/tsconfig.tsbuildinfo +0 -1
package/dist/inaccessibleSpec.js
DELETED
|
@@ -1,655 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.removeInaccessibleElements = exports.INACCESSIBLE_VERSIONS = exports.InaccessibleSpecDefinition = exports.inaccessibleIdentity = void 0;
|
|
4
|
-
const coreSpec_1 = require("./coreSpec");
|
|
5
|
-
const definitions_1 = require("./definitions");
|
|
6
|
-
const graphql_1 = require("graphql");
|
|
7
|
-
const knownCoreFeatures_1 = require("./knownCoreFeatures");
|
|
8
|
-
const error_1 = require("./error");
|
|
9
|
-
const directiveAndTypeSpecification_1 = require("./directiveAndTypeSpecification");
|
|
10
|
-
const utils_1 = require("./utils");
|
|
11
|
-
exports.inaccessibleIdentity = 'https://specs.apollo.dev/inaccessible';
|
|
12
|
-
class InaccessibleSpecDefinition extends coreSpec_1.FeatureDefinition {
|
|
13
|
-
constructor(version) {
|
|
14
|
-
super(new coreSpec_1.FeatureUrl(exports.inaccessibleIdentity, 'inaccessible', version));
|
|
15
|
-
this.inaccessibleLocations = [
|
|
16
|
-
graphql_1.DirectiveLocation.FIELD_DEFINITION,
|
|
17
|
-
graphql_1.DirectiveLocation.OBJECT,
|
|
18
|
-
graphql_1.DirectiveLocation.INTERFACE,
|
|
19
|
-
graphql_1.DirectiveLocation.UNION,
|
|
20
|
-
];
|
|
21
|
-
this.printedInaccessibleDefinition = 'directive @inaccessible on FIELD_DEFINITION | INTERFACE | OBJECT | UNION';
|
|
22
|
-
if (!this.isV01()) {
|
|
23
|
-
this.inaccessibleLocations.push(graphql_1.DirectiveLocation.ARGUMENT_DEFINITION, graphql_1.DirectiveLocation.SCALAR, graphql_1.DirectiveLocation.ENUM, graphql_1.DirectiveLocation.ENUM_VALUE, graphql_1.DirectiveLocation.INPUT_OBJECT, graphql_1.DirectiveLocation.INPUT_FIELD_DEFINITION);
|
|
24
|
-
this.printedInaccessibleDefinition = 'directive @inaccessible on FIELD_DEFINITION | INTERFACE | OBJECT | UNION | ARGUMENT_DEFINITION | SCALAR | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION';
|
|
25
|
-
}
|
|
26
|
-
this.inaccessibleDirectiveSpec = (0, directiveAndTypeSpecification_1.createDirectiveSpecification)({
|
|
27
|
-
name: 'inaccessible',
|
|
28
|
-
locations: this.inaccessibleLocations,
|
|
29
|
-
composes: true,
|
|
30
|
-
supergraphSpecification: () => exports.INACCESSIBLE_VERSIONS.latest(),
|
|
31
|
-
});
|
|
32
|
-
this.registerDirective(this.inaccessibleDirectiveSpec);
|
|
33
|
-
}
|
|
34
|
-
isV01() {
|
|
35
|
-
return this.version.equals(new coreSpec_1.FeatureVersion(0, 1));
|
|
36
|
-
}
|
|
37
|
-
inaccessibleDirective(schema) {
|
|
38
|
-
return this.directive(schema, 'inaccessible');
|
|
39
|
-
}
|
|
40
|
-
checkCompatibleDirective(definition) {
|
|
41
|
-
const hasUnknownArguments = Object.keys(definition.arguments()).length > 0;
|
|
42
|
-
const hasRepeatable = definition.repeatable;
|
|
43
|
-
const hasValidLocations = definition.locations.every(loc => this.inaccessibleLocations.includes(loc));
|
|
44
|
-
if (hasUnknownArguments || hasRepeatable || !hasValidLocations) {
|
|
45
|
-
return error_1.ERRORS.DIRECTIVE_DEFINITION_INVALID.err(`Found invalid @inaccessible directive definition. Please ensure the directive definition in your schema's definitions matches the following:\n\t${this.printedInaccessibleDefinition}`);
|
|
46
|
-
}
|
|
47
|
-
return undefined;
|
|
48
|
-
}
|
|
49
|
-
get defaultCorePurpose() {
|
|
50
|
-
return 'SECURITY';
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
exports.InaccessibleSpecDefinition = InaccessibleSpecDefinition;
|
|
54
|
-
exports.INACCESSIBLE_VERSIONS = new coreSpec_1.FeatureDefinitions(exports.inaccessibleIdentity)
|
|
55
|
-
.add(new InaccessibleSpecDefinition(new coreSpec_1.FeatureVersion(0, 1)))
|
|
56
|
-
.add(new InaccessibleSpecDefinition(new coreSpec_1.FeatureVersion(0, 2)));
|
|
57
|
-
(0, knownCoreFeatures_1.registerKnownFeature)(exports.INACCESSIBLE_VERSIONS);
|
|
58
|
-
function removeInaccessibleElements(schema) {
|
|
59
|
-
schema.validate();
|
|
60
|
-
const coreFeatures = schema.coreFeatures;
|
|
61
|
-
if (!coreFeatures) {
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
const inaccessibleFeature = coreFeatures.getByIdentity(exports.inaccessibleIdentity);
|
|
65
|
-
if (!inaccessibleFeature) {
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
const inaccessibleSpec = exports.INACCESSIBLE_VERSIONS.find(inaccessibleFeature.url.version);
|
|
69
|
-
if (!inaccessibleSpec) {
|
|
70
|
-
throw (0, definitions_1.ErrGraphQLAPISchemaValidationFailed)([new graphql_1.GraphQLError(`Cannot remove inaccessible elements: the schema uses unsupported` +
|
|
71
|
-
` inaccessible spec version ${inaccessibleFeature.url.version}` +
|
|
72
|
-
` (supported versions: ${exports.INACCESSIBLE_VERSIONS.versions().join(', ')})`)]);
|
|
73
|
-
}
|
|
74
|
-
const inaccessibleDirective = inaccessibleSpec.inaccessibleDirective(schema);
|
|
75
|
-
if (!inaccessibleDirective) {
|
|
76
|
-
throw (0, definitions_1.ErrGraphQLAPISchemaValidationFailed)([new graphql_1.GraphQLError(`Invalid schema: declares ${inaccessibleSpec.url} spec but does not` +
|
|
77
|
-
` define a @inaccessible directive.`)]);
|
|
78
|
-
}
|
|
79
|
-
const incompatibleError = inaccessibleSpec.checkCompatibleDirective(inaccessibleDirective);
|
|
80
|
-
if (incompatibleError) {
|
|
81
|
-
throw (0, definitions_1.ErrGraphQLAPISchemaValidationFailed)([incompatibleError]);
|
|
82
|
-
}
|
|
83
|
-
validateInaccessibleElements(schema, coreFeatures, inaccessibleSpec, inaccessibleDirective);
|
|
84
|
-
removeInaccessibleElementsAssumingValid(schema, inaccessibleDirective);
|
|
85
|
-
}
|
|
86
|
-
exports.removeInaccessibleElements = removeInaccessibleElements;
|
|
87
|
-
function validateInaccessibleElements(schema, coreFeatures, inaccessibleSpec, inaccessibleDirective) {
|
|
88
|
-
var _a, _b, _c;
|
|
89
|
-
function isInaccessible(element) {
|
|
90
|
-
return element.hasAppliedDirective(inaccessibleDirective);
|
|
91
|
-
}
|
|
92
|
-
const featureList = [...coreFeatures.allFeatures()];
|
|
93
|
-
function isFeatureDefinition(element) {
|
|
94
|
-
return featureList.some((feature) => feature.isFeatureDefinition(element));
|
|
95
|
-
}
|
|
96
|
-
function isInAPISchema(element) {
|
|
97
|
-
if (!(element instanceof definitions_1.DirectiveDefinition) &&
|
|
98
|
-
isInaccessible(element))
|
|
99
|
-
return false;
|
|
100
|
-
if ((element instanceof definitions_1.ObjectType) ||
|
|
101
|
-
(element instanceof definitions_1.InterfaceType) ||
|
|
102
|
-
(element instanceof definitions_1.UnionType) ||
|
|
103
|
-
(element instanceof definitions_1.ScalarType) ||
|
|
104
|
-
(element instanceof definitions_1.EnumType) ||
|
|
105
|
-
(element instanceof definitions_1.InputObjectType) ||
|
|
106
|
-
(element instanceof definitions_1.DirectiveDefinition)) {
|
|
107
|
-
return true;
|
|
108
|
-
}
|
|
109
|
-
else if ((element instanceof definitions_1.FieldDefinition) ||
|
|
110
|
-
(element instanceof definitions_1.ArgumentDefinition) ||
|
|
111
|
-
(element instanceof definitions_1.InputFieldDefinition) ||
|
|
112
|
-
(element instanceof definitions_1.EnumValue)) {
|
|
113
|
-
return isInAPISchema(element.parent);
|
|
114
|
-
}
|
|
115
|
-
(0, utils_1.assert)(false, "Unreachable code, element is of unknown type.");
|
|
116
|
-
}
|
|
117
|
-
function fetchInaccessibleElementsDeep(element) {
|
|
118
|
-
const inaccessibleElements = [];
|
|
119
|
-
if (isInaccessible(element)) {
|
|
120
|
-
inaccessibleElements.push(element);
|
|
121
|
-
}
|
|
122
|
-
if ((element instanceof definitions_1.ObjectType) ||
|
|
123
|
-
(element instanceof definitions_1.InterfaceType) ||
|
|
124
|
-
(element instanceof definitions_1.InputObjectType)) {
|
|
125
|
-
for (const field of element.fields()) {
|
|
126
|
-
inaccessibleElements.push(...fetchInaccessibleElementsDeep(field));
|
|
127
|
-
}
|
|
128
|
-
return inaccessibleElements;
|
|
129
|
-
}
|
|
130
|
-
else if (element instanceof definitions_1.EnumType) {
|
|
131
|
-
for (const enumValue of element.values) {
|
|
132
|
-
inaccessibleElements.push(...fetchInaccessibleElementsDeep(enumValue));
|
|
133
|
-
}
|
|
134
|
-
return inaccessibleElements;
|
|
135
|
-
}
|
|
136
|
-
else if ((element instanceof definitions_1.DirectiveDefinition) ||
|
|
137
|
-
(element instanceof definitions_1.FieldDefinition)) {
|
|
138
|
-
for (const argument of element.arguments()) {
|
|
139
|
-
inaccessibleElements.push(...fetchInaccessibleElementsDeep(argument));
|
|
140
|
-
}
|
|
141
|
-
return inaccessibleElements;
|
|
142
|
-
}
|
|
143
|
-
else if ((element instanceof definitions_1.UnionType) ||
|
|
144
|
-
(element instanceof definitions_1.ScalarType) ||
|
|
145
|
-
(element instanceof definitions_1.ArgumentDefinition) ||
|
|
146
|
-
(element instanceof definitions_1.InputFieldDefinition) ||
|
|
147
|
-
(element instanceof definitions_1.EnumValue)) {
|
|
148
|
-
return inaccessibleElements;
|
|
149
|
-
}
|
|
150
|
-
(0, utils_1.assert)(false, "Unreachable code, element is of unknown type.");
|
|
151
|
-
}
|
|
152
|
-
const errors = [];
|
|
153
|
-
let defaultValueReferencers = undefined;
|
|
154
|
-
if (!inaccessibleSpec.isV01()) {
|
|
155
|
-
defaultValueReferencers = computeDefaultValueReferencers(schema);
|
|
156
|
-
}
|
|
157
|
-
for (const type of schema.allTypes()) {
|
|
158
|
-
if (hasBuiltInName(type)) {
|
|
159
|
-
const inaccessibleElements = fetchInaccessibleElementsDeep(type);
|
|
160
|
-
if (inaccessibleElements.length > 0) {
|
|
161
|
-
errors.push(error_1.ERRORS.DISALLOWED_INACCESSIBLE.err(`Built-in type "${type.coordinate}" cannot use @inaccessible.`, {
|
|
162
|
-
nodes: type.sourceAST,
|
|
163
|
-
extensions: {
|
|
164
|
-
inaccessible_elements: inaccessibleElements
|
|
165
|
-
.map((element) => element.coordinate),
|
|
166
|
-
inaccessible_referencers: [type.coordinate],
|
|
167
|
-
}
|
|
168
|
-
}));
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
else if (isFeatureDefinition(type)) {
|
|
172
|
-
const inaccessibleElements = fetchInaccessibleElementsDeep(type);
|
|
173
|
-
if (inaccessibleElements.length > 0) {
|
|
174
|
-
errors.push(error_1.ERRORS.DISALLOWED_INACCESSIBLE.err(`Core feature type "${type.coordinate}" cannot use @inaccessible.`, {
|
|
175
|
-
nodes: type.sourceAST,
|
|
176
|
-
extensions: {
|
|
177
|
-
inaccessible_elements: inaccessibleElements
|
|
178
|
-
.map((element) => element.coordinate),
|
|
179
|
-
inaccessible_referencers: [type.coordinate],
|
|
180
|
-
}
|
|
181
|
-
}));
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
else if (isInaccessible(type)) {
|
|
185
|
-
const referencers = type.referencers();
|
|
186
|
-
for (const referencer of referencers) {
|
|
187
|
-
if (referencer instanceof definitions_1.FieldDefinition ||
|
|
188
|
-
referencer instanceof definitions_1.ArgumentDefinition ||
|
|
189
|
-
referencer instanceof definitions_1.InputFieldDefinition) {
|
|
190
|
-
if (isInAPISchema(referencer)) {
|
|
191
|
-
errors.push(error_1.ERRORS.REFERENCED_INACCESSIBLE.err(`Type "${type.coordinate}" is @inaccessible but is referenced` +
|
|
192
|
-
` by "${referencer.coordinate}", which is in the API schema.`, {
|
|
193
|
-
nodes: type.sourceAST,
|
|
194
|
-
extensions: {
|
|
195
|
-
inaccessible_elements: [type.coordinate],
|
|
196
|
-
inaccessible_referencers: [referencer.coordinate],
|
|
197
|
-
}
|
|
198
|
-
}));
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
else if (referencer instanceof definitions_1.SchemaDefinition) {
|
|
202
|
-
if (type === referencer.rootType('query')) {
|
|
203
|
-
errors.push(error_1.ERRORS.QUERY_ROOT_TYPE_INACCESSIBLE.err(`Type "${type.coordinate}" is @inaccessible but is the root` +
|
|
204
|
-
` query type, which must be in the API schema.`, {
|
|
205
|
-
nodes: type.sourceAST,
|
|
206
|
-
extensions: {
|
|
207
|
-
inaccessible_elements: [type.coordinate],
|
|
208
|
-
}
|
|
209
|
-
}));
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
else {
|
|
215
|
-
if ((type instanceof definitions_1.ObjectType) ||
|
|
216
|
-
(type instanceof definitions_1.InterfaceType) ||
|
|
217
|
-
(type instanceof definitions_1.InputObjectType)) {
|
|
218
|
-
let isEmpty = true;
|
|
219
|
-
for (const field of type.fields()) {
|
|
220
|
-
if (!isInaccessible(field))
|
|
221
|
-
isEmpty = false;
|
|
222
|
-
}
|
|
223
|
-
if (isEmpty) {
|
|
224
|
-
errors.push(error_1.ERRORS.ONLY_INACCESSIBLE_CHILDREN.err(`Type "${type.coordinate}" is in the API schema but all of its` +
|
|
225
|
-
` ${(type instanceof definitions_1.InputObjectType) ? 'input ' : ''}fields` +
|
|
226
|
-
` are @inaccessible.`, {
|
|
227
|
-
nodes: type.sourceAST,
|
|
228
|
-
extensions: {
|
|
229
|
-
inaccessible_elements: type.fields()
|
|
230
|
-
.map((field) => field.coordinate),
|
|
231
|
-
inaccessible_referencers: [type.coordinate],
|
|
232
|
-
}
|
|
233
|
-
}));
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
else if (type instanceof definitions_1.UnionType) {
|
|
237
|
-
let isEmpty = true;
|
|
238
|
-
for (const member of type.types()) {
|
|
239
|
-
if (!isInaccessible(member))
|
|
240
|
-
isEmpty = false;
|
|
241
|
-
}
|
|
242
|
-
if (isEmpty) {
|
|
243
|
-
errors.push(error_1.ERRORS.ONLY_INACCESSIBLE_CHILDREN.err(`Type "${type.coordinate}" is in the API schema but all of its` +
|
|
244
|
-
` members are @inaccessible.`, {
|
|
245
|
-
nodes: type.sourceAST,
|
|
246
|
-
extensions: {
|
|
247
|
-
inaccessible_elements: type.types()
|
|
248
|
-
.map((type) => type.coordinate),
|
|
249
|
-
inaccessible_referencers: [type.coordinate],
|
|
250
|
-
}
|
|
251
|
-
}));
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
else if (type instanceof definitions_1.EnumType) {
|
|
255
|
-
let isEmpty = true;
|
|
256
|
-
for (const enumValue of type.values) {
|
|
257
|
-
if (!isInaccessible(enumValue))
|
|
258
|
-
isEmpty = false;
|
|
259
|
-
}
|
|
260
|
-
if (isEmpty) {
|
|
261
|
-
errors.push(error_1.ERRORS.ONLY_INACCESSIBLE_CHILDREN.err(`Type "${type.coordinate}" is in the API schema but all of its` +
|
|
262
|
-
` values are @inaccessible.`, {
|
|
263
|
-
nodes: type.sourceAST,
|
|
264
|
-
extensions: {
|
|
265
|
-
inaccessible_elements: type.values
|
|
266
|
-
.map((enumValue) => enumValue.coordinate),
|
|
267
|
-
inaccessible_referencers: [type.coordinate],
|
|
268
|
-
}
|
|
269
|
-
}));
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
if ((type instanceof definitions_1.ObjectType) ||
|
|
273
|
-
(type instanceof definitions_1.InterfaceType)) {
|
|
274
|
-
const implementedInterfaces = type.interfaces();
|
|
275
|
-
const implementingTypes = [];
|
|
276
|
-
if (type instanceof definitions_1.InterfaceType) {
|
|
277
|
-
for (const referencer of type.referencers()) {
|
|
278
|
-
if ((referencer instanceof definitions_1.ObjectType) ||
|
|
279
|
-
(referencer instanceof definitions_1.InterfaceType)) {
|
|
280
|
-
implementingTypes.push(referencer);
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
for (const field of type.fields()) {
|
|
285
|
-
if (isInaccessible(field)) {
|
|
286
|
-
for (const implementedInterface of implementedInterfaces) {
|
|
287
|
-
const implementedField = implementedInterface.field(field.name);
|
|
288
|
-
if (implementedField && isInAPISchema(implementedField)) {
|
|
289
|
-
errors.push(error_1.ERRORS.IMPLEMENTED_BY_INACCESSIBLE.err(`Field "${field.coordinate}" is @inaccessible but` +
|
|
290
|
-
` implements the interface field` +
|
|
291
|
-
` "${implementedField.coordinate}", which is in the API` +
|
|
292
|
-
` schema.`, {
|
|
293
|
-
nodes: field.sourceAST,
|
|
294
|
-
extensions: {
|
|
295
|
-
inaccessible_elements: [field.coordinate],
|
|
296
|
-
inaccessible_referencers: [implementedField.coordinate],
|
|
297
|
-
}
|
|
298
|
-
}));
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
else {
|
|
303
|
-
for (const argument of field.arguments()) {
|
|
304
|
-
if (isInaccessible(argument)) {
|
|
305
|
-
if (argument.isRequired()) {
|
|
306
|
-
errors.push(error_1.ERRORS.REQUIRED_INACCESSIBLE.err(`Argument "${argument.coordinate}" is @inaccessible but` +
|
|
307
|
-
` is a required argument of its field.`, {
|
|
308
|
-
nodes: argument.sourceAST,
|
|
309
|
-
extensions: {
|
|
310
|
-
inaccessible_elements: [argument.coordinate],
|
|
311
|
-
inaccessible_referencers: [argument.coordinate],
|
|
312
|
-
}
|
|
313
|
-
}));
|
|
314
|
-
}
|
|
315
|
-
for (const implementingType of implementingTypes) {
|
|
316
|
-
const implementingField = implementingType.field(field.name);
|
|
317
|
-
(0, utils_1.assert)(implementingField, "Schema should have been valid, but an implementing type" +
|
|
318
|
-
" did not implement one of this type's fields.");
|
|
319
|
-
const implementingArgument = implementingField
|
|
320
|
-
.argument(argument.name);
|
|
321
|
-
(0, utils_1.assert)(implementingArgument, "Schema should have been valid, but an implementing type" +
|
|
322
|
-
" did not implement one of this type's field's arguments.");
|
|
323
|
-
if (isInAPISchema(implementingArgument) &&
|
|
324
|
-
implementingArgument.isRequired()) {
|
|
325
|
-
errors.push(error_1.ERRORS.REQUIRED_INACCESSIBLE.err(`Argument "${argument.coordinate}" is @inaccessible` +
|
|
326
|
-
` but is implemented by the required argument` +
|
|
327
|
-
` "${implementingArgument.coordinate}", which is` +
|
|
328
|
-
` in the API schema.`, {
|
|
329
|
-
nodes: argument.sourceAST,
|
|
330
|
-
extensions: {
|
|
331
|
-
inaccessible_elements: [argument.coordinate],
|
|
332
|
-
inaccessible_referencers: [
|
|
333
|
-
implementingArgument.coordinate,
|
|
334
|
-
],
|
|
335
|
-
}
|
|
336
|
-
}));
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
for (const implementedInterface of implementedInterfaces) {
|
|
340
|
-
const implementedArgument = (_a = implementedInterface
|
|
341
|
-
.field(field.name)) === null || _a === void 0 ? void 0 : _a.argument(argument.name);
|
|
342
|
-
if (implementedArgument &&
|
|
343
|
-
isInAPISchema(implementedArgument)) {
|
|
344
|
-
errors.push(error_1.ERRORS.IMPLEMENTED_BY_INACCESSIBLE.err(`Argument "${argument.coordinate}" is @inaccessible` +
|
|
345
|
-
` but implements the interface argument` +
|
|
346
|
-
` "${implementedArgument.coordinate}", which is in` +
|
|
347
|
-
` the API schema.`, {
|
|
348
|
-
nodes: argument.sourceAST,
|
|
349
|
-
extensions: {
|
|
350
|
-
inaccessible_elements: [argument.coordinate],
|
|
351
|
-
inaccessible_referencers: [
|
|
352
|
-
implementedArgument.coordinate,
|
|
353
|
-
],
|
|
354
|
-
}
|
|
355
|
-
}));
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
else if (type instanceof definitions_1.InputObjectType) {
|
|
364
|
-
for (const inputField of type.fields()) {
|
|
365
|
-
if (isInaccessible(inputField)) {
|
|
366
|
-
if (inputField.isRequired()) {
|
|
367
|
-
errors.push(error_1.ERRORS.REQUIRED_INACCESSIBLE.err(`Input field "${inputField.coordinate}" is @inaccessible` +
|
|
368
|
-
` but is a required input field of its type.`, {
|
|
369
|
-
nodes: inputField.sourceAST,
|
|
370
|
-
extensions: {
|
|
371
|
-
inaccessible_elements: [inputField.coordinate],
|
|
372
|
-
inaccessible_referencers: [inputField.coordinate],
|
|
373
|
-
}
|
|
374
|
-
}));
|
|
375
|
-
}
|
|
376
|
-
(0, utils_1.assert)(defaultValueReferencers, "Input fields can't be @inaccessible in v0.1, but default value" +
|
|
377
|
-
" referencers weren't computed (which is only skipped for v0.1).");
|
|
378
|
-
const referencers = (_b = defaultValueReferencers.get(inputField)) !== null && _b !== void 0 ? _b : [];
|
|
379
|
-
for (const referencer of referencers) {
|
|
380
|
-
if (isInAPISchema(referencer)) {
|
|
381
|
-
errors.push(error_1.ERRORS.DEFAULT_VALUE_USES_INACCESSIBLE.err(`Input field "${inputField.coordinate}" is @inaccessible` +
|
|
382
|
-
` but is used in the default value of` +
|
|
383
|
-
` "${referencer.coordinate}", which is in the API schema.`, {
|
|
384
|
-
nodes: type.sourceAST,
|
|
385
|
-
extensions: {
|
|
386
|
-
inaccessible_elements: [type.coordinate],
|
|
387
|
-
inaccessible_referencers: [referencer.coordinate],
|
|
388
|
-
}
|
|
389
|
-
}));
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
else if (type instanceof definitions_1.EnumType) {
|
|
396
|
-
for (const enumValue of type.values) {
|
|
397
|
-
if (isInaccessible(enumValue)) {
|
|
398
|
-
(0, utils_1.assert)(defaultValueReferencers, "Enum values can't be @inaccessible in v0.1, but default value" +
|
|
399
|
-
" referencers weren't computed (which is only skipped for v0.1).");
|
|
400
|
-
const referencers = (_c = defaultValueReferencers.get(enumValue)) !== null && _c !== void 0 ? _c : [];
|
|
401
|
-
for (const referencer of referencers) {
|
|
402
|
-
if (isInAPISchema(referencer)) {
|
|
403
|
-
errors.push(error_1.ERRORS.DEFAULT_VALUE_USES_INACCESSIBLE.err(`Enum value "${enumValue.coordinate}" is @inaccessible` +
|
|
404
|
-
` but is used in the default value of` +
|
|
405
|
-
` "${referencer.coordinate}", which is in the API schema.`, {
|
|
406
|
-
nodes: type.sourceAST,
|
|
407
|
-
extensions: {
|
|
408
|
-
inaccessible_elements: [type.coordinate],
|
|
409
|
-
inaccessible_referencers: [referencer.coordinate],
|
|
410
|
-
}
|
|
411
|
-
}));
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
}
|
|
415
|
-
}
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
for (const directive of schema.allDirectives()) {
|
|
420
|
-
const typeSystemLocations = directive.locations.filter((loc) => (0, definitions_1.isTypeSystemDirectiveLocation)(loc));
|
|
421
|
-
if (hasBuiltInName(directive)) {
|
|
422
|
-
const inaccessibleElements = fetchInaccessibleElementsDeep(directive);
|
|
423
|
-
if (inaccessibleElements.length > 0) {
|
|
424
|
-
errors.push(error_1.ERRORS.DISALLOWED_INACCESSIBLE.err(`Built-in directive "${directive.coordinate}" cannot use @inaccessible.`, {
|
|
425
|
-
nodes: directive.sourceAST,
|
|
426
|
-
extensions: {
|
|
427
|
-
inaccessible_elements: inaccessibleElements
|
|
428
|
-
.map((element) => element.coordinate),
|
|
429
|
-
inaccessible_referencers: [directive.coordinate],
|
|
430
|
-
}
|
|
431
|
-
}));
|
|
432
|
-
}
|
|
433
|
-
}
|
|
434
|
-
else if (isFeatureDefinition(directive)) {
|
|
435
|
-
const inaccessibleElements = fetchInaccessibleElementsDeep(directive);
|
|
436
|
-
if (inaccessibleElements.length > 0) {
|
|
437
|
-
errors.push(error_1.ERRORS.DISALLOWED_INACCESSIBLE.err(`Core feature directive "${directive.coordinate}" cannot use @inaccessible.`, {
|
|
438
|
-
nodes: directive.sourceAST,
|
|
439
|
-
extensions: {
|
|
440
|
-
inaccessible_elements: inaccessibleElements
|
|
441
|
-
.map((element) => element.coordinate),
|
|
442
|
-
inaccessible_referencers: [directive.coordinate],
|
|
443
|
-
}
|
|
444
|
-
}));
|
|
445
|
-
}
|
|
446
|
-
}
|
|
447
|
-
else if (typeSystemLocations.length > 0) {
|
|
448
|
-
const inaccessibleElements = fetchInaccessibleElementsDeep(directive);
|
|
449
|
-
if (inaccessibleElements.length > 0) {
|
|
450
|
-
errors.push(error_1.ERRORS.DISALLOWED_INACCESSIBLE.err(`Directive "${directive.coordinate}" cannot use @inaccessible` +
|
|
451
|
-
` because it may be applied to these type-system locations:` +
|
|
452
|
-
` ${typeSystemLocations.join(', ')}.`, {
|
|
453
|
-
nodes: directive.sourceAST,
|
|
454
|
-
extensions: {
|
|
455
|
-
inaccessible_elements: inaccessibleElements
|
|
456
|
-
.map((element) => element.coordinate),
|
|
457
|
-
inaccessible_referencers: [directive.coordinate],
|
|
458
|
-
}
|
|
459
|
-
}));
|
|
460
|
-
}
|
|
461
|
-
}
|
|
462
|
-
else {
|
|
463
|
-
for (const argument of directive.arguments()) {
|
|
464
|
-
if (argument.isRequired()) {
|
|
465
|
-
if (isInaccessible(argument)) {
|
|
466
|
-
errors.push(error_1.ERRORS.REQUIRED_INACCESSIBLE.err(`Argument "${argument.coordinate}" is @inaccessible but is a` +
|
|
467
|
-
` required argument of its directive.`, {
|
|
468
|
-
nodes: argument.sourceAST,
|
|
469
|
-
extensions: {
|
|
470
|
-
inaccessible_elements: [argument.coordinate],
|
|
471
|
-
inaccessible_referencers: [argument.coordinate],
|
|
472
|
-
}
|
|
473
|
-
}));
|
|
474
|
-
}
|
|
475
|
-
}
|
|
476
|
-
}
|
|
477
|
-
}
|
|
478
|
-
}
|
|
479
|
-
if (errors.length > 0) {
|
|
480
|
-
throw (0, definitions_1.ErrGraphQLAPISchemaValidationFailed)(errors);
|
|
481
|
-
}
|
|
482
|
-
}
|
|
483
|
-
function computeDefaultValueReferencers(schema) {
|
|
484
|
-
const referencers = new Map();
|
|
485
|
-
function addReference(reference, referencer) {
|
|
486
|
-
var _a;
|
|
487
|
-
const referencerList = (_a = referencers.get(reference)) !== null && _a !== void 0 ? _a : [];
|
|
488
|
-
if (referencerList.length === 0) {
|
|
489
|
-
referencers.set(reference, referencerList);
|
|
490
|
-
}
|
|
491
|
-
referencerList.push(referencer);
|
|
492
|
-
}
|
|
493
|
-
for (const type of schema.allTypes()) {
|
|
494
|
-
if (hasBuiltInName(type))
|
|
495
|
-
continue;
|
|
496
|
-
if ((type instanceof definitions_1.ObjectType) ||
|
|
497
|
-
(type instanceof definitions_1.InterfaceType)) {
|
|
498
|
-
for (const field of type.fields()) {
|
|
499
|
-
for (const argument of field.arguments()) {
|
|
500
|
-
for (const reference of computeDefaultValueReferences(argument)) {
|
|
501
|
-
addReference(reference, argument);
|
|
502
|
-
}
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
if (type instanceof definitions_1.InputObjectType) {
|
|
507
|
-
for (const inputField of type.fields()) {
|
|
508
|
-
for (const reference of computeDefaultValueReferences(inputField)) {
|
|
509
|
-
addReference(reference, inputField);
|
|
510
|
-
}
|
|
511
|
-
}
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
for (const directive of schema.allDirectives()) {
|
|
515
|
-
if (hasBuiltInName(directive))
|
|
516
|
-
continue;
|
|
517
|
-
for (const argument of directive.arguments()) {
|
|
518
|
-
for (const reference of computeDefaultValueReferences(argument)) {
|
|
519
|
-
addReference(reference, argument);
|
|
520
|
-
}
|
|
521
|
-
}
|
|
522
|
-
}
|
|
523
|
-
return referencers;
|
|
524
|
-
}
|
|
525
|
-
function computeDefaultValueReferences(element) {
|
|
526
|
-
const references = [];
|
|
527
|
-
addValueReferences(element.defaultValue, getInputType(element), references);
|
|
528
|
-
return references;
|
|
529
|
-
}
|
|
530
|
-
function getInputType(element) {
|
|
531
|
-
const type = element.type;
|
|
532
|
-
(0, utils_1.assert)(type, "Schema should have been valid, but argument/input field did not have type.");
|
|
533
|
-
return type;
|
|
534
|
-
}
|
|
535
|
-
function addValueReferences(value, type, references) {
|
|
536
|
-
if (value === undefined || value === null) {
|
|
537
|
-
return;
|
|
538
|
-
}
|
|
539
|
-
if ((0, definitions_1.isNonNullType)(type)) {
|
|
540
|
-
return addValueReferences(value, type.ofType, references);
|
|
541
|
-
}
|
|
542
|
-
if ((0, definitions_1.isScalarType)(type)) {
|
|
543
|
-
return;
|
|
544
|
-
}
|
|
545
|
-
if ((0, definitions_1.isVariable)(value)) {
|
|
546
|
-
return;
|
|
547
|
-
}
|
|
548
|
-
if (Array.isArray(value)) {
|
|
549
|
-
if ((0, definitions_1.isListType)(type)) {
|
|
550
|
-
const itemType = type.ofType;
|
|
551
|
-
for (const item of value) {
|
|
552
|
-
addValueReferences(item, itemType, references);
|
|
553
|
-
}
|
|
554
|
-
}
|
|
555
|
-
else {
|
|
556
|
-
}
|
|
557
|
-
return;
|
|
558
|
-
}
|
|
559
|
-
if ((0, definitions_1.isListType)(type)) {
|
|
560
|
-
return addValueReferences(value, type.ofType, references);
|
|
561
|
-
}
|
|
562
|
-
if (typeof value === 'object') {
|
|
563
|
-
if ((0, definitions_1.isInputObjectType)(type)) {
|
|
564
|
-
for (const field of type.fields()) {
|
|
565
|
-
const fieldValue = value[field.name];
|
|
566
|
-
if (fieldValue !== undefined) {
|
|
567
|
-
references.push(field);
|
|
568
|
-
addValueReferences(fieldValue, field.type, references);
|
|
569
|
-
}
|
|
570
|
-
else {
|
|
571
|
-
}
|
|
572
|
-
}
|
|
573
|
-
}
|
|
574
|
-
else {
|
|
575
|
-
}
|
|
576
|
-
return;
|
|
577
|
-
}
|
|
578
|
-
if (typeof value === 'string') {
|
|
579
|
-
if ((0, definitions_1.isEnumType)(type)) {
|
|
580
|
-
const enumValue = type.value(value);
|
|
581
|
-
if (enumValue !== undefined) {
|
|
582
|
-
references.push(enumValue);
|
|
583
|
-
}
|
|
584
|
-
else {
|
|
585
|
-
}
|
|
586
|
-
}
|
|
587
|
-
else {
|
|
588
|
-
}
|
|
589
|
-
return;
|
|
590
|
-
}
|
|
591
|
-
return;
|
|
592
|
-
}
|
|
593
|
-
function hasBuiltInName(element) {
|
|
594
|
-
const schema = element.schema();
|
|
595
|
-
if ((element instanceof definitions_1.ObjectType) ||
|
|
596
|
-
(element instanceof definitions_1.InterfaceType) ||
|
|
597
|
-
(element instanceof definitions_1.UnionType) ||
|
|
598
|
-
(element instanceof definitions_1.ScalarType) ||
|
|
599
|
-
(element instanceof definitions_1.EnumType) ||
|
|
600
|
-
(element instanceof definitions_1.InputObjectType)) {
|
|
601
|
-
return schema.builtInTypes(true).some((type) => type.name === element.name);
|
|
602
|
-
}
|
|
603
|
-
else if (element instanceof definitions_1.DirectiveDefinition) {
|
|
604
|
-
return schema.builtInDirectives(true).some((directive) => directive.name === element.name);
|
|
605
|
-
}
|
|
606
|
-
(0, utils_1.assert)(false, "Unreachable code, element is of unknown type.");
|
|
607
|
-
}
|
|
608
|
-
function removeInaccessibleElementsAssumingValid(schema, inaccessibleDirective) {
|
|
609
|
-
function isInaccessible(element) {
|
|
610
|
-
return element.hasAppliedDirective(inaccessibleDirective);
|
|
611
|
-
}
|
|
612
|
-
for (const type of schema.types()) {
|
|
613
|
-
if (isInaccessible(type)) {
|
|
614
|
-
type.remove();
|
|
615
|
-
}
|
|
616
|
-
else {
|
|
617
|
-
if ((type instanceof definitions_1.ObjectType) || (type instanceof definitions_1.InterfaceType)) {
|
|
618
|
-
for (const field of type.fields()) {
|
|
619
|
-
if (isInaccessible(field)) {
|
|
620
|
-
field.remove();
|
|
621
|
-
}
|
|
622
|
-
else {
|
|
623
|
-
for (const argument of field.arguments()) {
|
|
624
|
-
if (isInaccessible(argument)) {
|
|
625
|
-
argument.remove();
|
|
626
|
-
}
|
|
627
|
-
}
|
|
628
|
-
}
|
|
629
|
-
}
|
|
630
|
-
}
|
|
631
|
-
else if (type instanceof definitions_1.InputObjectType) {
|
|
632
|
-
for (const inputField of type.fields()) {
|
|
633
|
-
if (isInaccessible(inputField)) {
|
|
634
|
-
inputField.remove();
|
|
635
|
-
}
|
|
636
|
-
}
|
|
637
|
-
}
|
|
638
|
-
else if (type instanceof definitions_1.EnumType) {
|
|
639
|
-
for (const enumValue of type.values) {
|
|
640
|
-
if (isInaccessible(enumValue)) {
|
|
641
|
-
enumValue.remove();
|
|
642
|
-
}
|
|
643
|
-
}
|
|
644
|
-
}
|
|
645
|
-
}
|
|
646
|
-
}
|
|
647
|
-
for (const directive of schema.directives()) {
|
|
648
|
-
for (const argument of directive.arguments()) {
|
|
649
|
-
if (isInaccessible(argument)) {
|
|
650
|
-
argument.remove();
|
|
651
|
-
}
|
|
652
|
-
}
|
|
653
|
-
}
|
|
654
|
-
}
|
|
655
|
-
//# sourceMappingURL=inaccessibleSpec.js.map
|