@theguild/federation-composition 0.6.0 → 0.6.1
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/cjs/subgraph/state.js +8 -1
- package/cjs/supergraph/composition/input-object-type.js +6 -3
- package/cjs/supergraph/composition/interface-type.js +1 -1
- package/cjs/supergraph/composition/object-type.js +51 -35
- package/cjs/supergraph/state.js +16 -7
- package/cjs/supergraph/validation/rules/satisfiablity-rule.js +1 -1
- package/esm/subgraph/state.js +9 -2
- package/esm/supergraph/composition/input-object-type.js +6 -3
- package/esm/supergraph/composition/interface-type.js +1 -1
- package/esm/supergraph/composition/object-type.js +51 -35
- package/esm/supergraph/state.js +16 -7
- package/esm/supergraph/validation/rules/satisfiablity-rule.js +1 -1
- package/package.json +1 -1
- package/typings/supergraph/composition/common.d.cts +3 -1
- package/typings/supergraph/composition/common.d.ts +3 -1
package/cjs/subgraph/state.js
CHANGED
|
@@ -21,6 +21,8 @@ function createSubgraphStateBuilder(graph, typeDefs, version, links) {
|
|
|
21
21
|
const isLinkSpecManuallyProvided = typeDefs.definitions.some(def => def.kind === graphql_1.Kind.DIRECTIVE_DEFINITION &&
|
|
22
22
|
def.name.value === 'link' &&
|
|
23
23
|
def.locations.every(loc => loc.value === 'SCHEMA'));
|
|
24
|
+
const specifiedScalars = graphql_1.specifiedScalarTypes.map(type => type.name);
|
|
25
|
+
const specifiedDirectives = graphql_1.specifiedDirectives.map(directive => directive.name);
|
|
24
26
|
const state = {
|
|
25
27
|
graph: {
|
|
26
28
|
...graph,
|
|
@@ -230,7 +232,9 @@ function createSubgraphStateBuilder(graph, typeDefs, version, links) {
|
|
|
230
232
|
inputObjectTypeBuilder.setDefinition(node.name.value);
|
|
231
233
|
},
|
|
232
234
|
ScalarTypeDefinition(node) {
|
|
233
|
-
|
|
235
|
+
if (!specifiedScalars.includes(node.name.value)) {
|
|
236
|
+
scalarTypeBuilder.setDefinition(node.name.value);
|
|
237
|
+
}
|
|
234
238
|
},
|
|
235
239
|
ScalarTypeExtension() {
|
|
236
240
|
},
|
|
@@ -351,6 +355,9 @@ function createSubgraphStateBuilder(graph, typeDefs, version, links) {
|
|
|
351
355
|
},
|
|
352
356
|
DirectiveDefinition(node) {
|
|
353
357
|
const directiveName = node.name.value;
|
|
358
|
+
if (specifiedDirectives.includes(directiveName)) {
|
|
359
|
+
return;
|
|
360
|
+
}
|
|
354
361
|
if (node.repeatable) {
|
|
355
362
|
directiveBuilder.setRepeatable(directiveName);
|
|
356
363
|
}
|
|
@@ -35,7 +35,7 @@ function inputObjectTypeBuilder() {
|
|
|
35
35
|
if (field.deprecated && !fieldState.deprecated) {
|
|
36
36
|
fieldState.deprecated = field.deprecated;
|
|
37
37
|
}
|
|
38
|
-
if (typeof field.defaultValue
|
|
38
|
+
if (typeof field.defaultValue !== 'undefined') {
|
|
39
39
|
fieldState.defaultValue = field.defaultValue;
|
|
40
40
|
}
|
|
41
41
|
fieldState.byGraph.set(graph.id, {
|
|
@@ -59,13 +59,16 @@ function inputObjectTypeBuilder() {
|
|
|
59
59
|
return true;
|
|
60
60
|
})
|
|
61
61
|
.map(field => {
|
|
62
|
-
const
|
|
62
|
+
const fieldStateInGraphs = Array.from(field.byGraph.values());
|
|
63
|
+
const hasDifferentType = fieldStateInGraphs.some(f => f.type !== field.type);
|
|
63
64
|
return {
|
|
64
65
|
name: field.name,
|
|
65
66
|
type: field.type,
|
|
66
67
|
tags: Array.from(field.tags),
|
|
67
68
|
inaccessible: field.inaccessible,
|
|
68
|
-
defaultValue:
|
|
69
|
+
defaultValue: fieldStateInGraphs.every(f => typeof f.defaultValue !== 'undefined')
|
|
70
|
+
? field.defaultValue
|
|
71
|
+
: undefined,
|
|
69
72
|
description: field.description,
|
|
70
73
|
deprecated: field.deprecated,
|
|
71
74
|
join: {
|
|
@@ -82,7 +82,7 @@ function interfaceTypeBuilder() {
|
|
|
82
82
|
if (arg.description && !argState.description) {
|
|
83
83
|
argState.description = arg.description;
|
|
84
84
|
}
|
|
85
|
-
if (typeof arg.defaultValue
|
|
85
|
+
if (typeof arg.defaultValue !== 'undefined') {
|
|
86
86
|
argState.defaultValue = arg.defaultValue;
|
|
87
87
|
}
|
|
88
88
|
arg.ast.directives.forEach(directive => {
|
|
@@ -137,7 +137,7 @@ function objectTypeBuilder() {
|
|
|
137
137
|
arg.ast.directives.forEach(directive => {
|
|
138
138
|
argState.ast.directives.push(directive);
|
|
139
139
|
});
|
|
140
|
-
if (typeof arg.defaultValue
|
|
140
|
+
if (typeof arg.defaultValue !== 'undefined') {
|
|
141
141
|
argState.defaultValue = arg.defaultValue;
|
|
142
142
|
}
|
|
143
143
|
argState.byGraph.set(graph.id, {
|
|
@@ -148,8 +148,31 @@ function objectTypeBuilder() {
|
|
|
148
148
|
}
|
|
149
149
|
}
|
|
150
150
|
},
|
|
151
|
-
composeSupergraphNode(objectType, graphs) {
|
|
151
|
+
composeSupergraphNode(objectType, graphs, { graphNameToId }) {
|
|
152
152
|
const isQuery = objectType.name === 'Query';
|
|
153
|
+
const joinTypes = isQuery
|
|
154
|
+
?
|
|
155
|
+
Array.from(graphs.values()).map(graph => ({
|
|
156
|
+
graph: graph.id,
|
|
157
|
+
}))
|
|
158
|
+
:
|
|
159
|
+
Array.from(objectType.byGraph.entries())
|
|
160
|
+
.map(([graphId, meta]) => {
|
|
161
|
+
if (meta.keys.length) {
|
|
162
|
+
return meta.keys.map(key => ({
|
|
163
|
+
graph: graphId,
|
|
164
|
+
key: key.fields,
|
|
165
|
+
extension: isRealExtension(meta, graphs.get(graphId).version),
|
|
166
|
+
resolvable: key.resolvable,
|
|
167
|
+
}));
|
|
168
|
+
}
|
|
169
|
+
return [
|
|
170
|
+
{
|
|
171
|
+
graph: graphId,
|
|
172
|
+
},
|
|
173
|
+
];
|
|
174
|
+
})
|
|
175
|
+
.flat(1);
|
|
153
176
|
return (0, ast_js_1.createObjectTypeNode)({
|
|
154
177
|
name: objectType.name,
|
|
155
178
|
ast: {
|
|
@@ -214,15 +237,22 @@ function objectTypeBuilder() {
|
|
|
214
237
|
else if (isDefinedEverywhere) {
|
|
215
238
|
const hasDifferencesBetweenGraphs = Object.values(differencesBetweenGraphs).some(value => value === true);
|
|
216
239
|
if (differencesBetweenGraphs.override) {
|
|
217
|
-
const
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
240
|
+
const mutedGraphs = fieldInGraphs
|
|
241
|
+
.map(([_, meta]) => (meta.override ? graphNameToId(meta.override) : null))
|
|
242
|
+
.filter((graphId) => typeof graphId === 'string');
|
|
243
|
+
const graphsToEmit = fieldInGraphs.filter(([graphId, f]) => f.external || !mutedGraphs.includes(graphId));
|
|
244
|
+
if (!(graphsToEmit.length === 1 &&
|
|
245
|
+
joinTypes.length === 1 &&
|
|
246
|
+
joinTypes[0].graph === graphsToEmit[0][0])) {
|
|
247
|
+
joinFields = graphsToEmit.map(([graphId, meta]) => ({
|
|
248
|
+
graph: graphId,
|
|
249
|
+
override: meta.override ?? undefined,
|
|
250
|
+
type: differencesBetweenGraphs.type ? meta.type : undefined,
|
|
251
|
+
external: meta.external ?? undefined,
|
|
252
|
+
provides: meta.provides ?? undefined,
|
|
253
|
+
requires: meta.requires ?? undefined,
|
|
254
|
+
}));
|
|
255
|
+
}
|
|
226
256
|
}
|
|
227
257
|
else if (hasDifferencesBetweenGraphs) {
|
|
228
258
|
joinFields = fieldInGraphs.map(([graphId, meta]) => ({
|
|
@@ -277,7 +307,15 @@ function objectTypeBuilder() {
|
|
|
277
307
|
directives: (0, common_js_1.convertToConst)(field.ast.directives),
|
|
278
308
|
},
|
|
279
309
|
join: {
|
|
280
|
-
field: joinFields
|
|
310
|
+
field: joinFields.length === 1 &&
|
|
311
|
+
joinTypes.length === 1 &&
|
|
312
|
+
!joinFields[0].external &&
|
|
313
|
+
!joinFields[0].override &&
|
|
314
|
+
!joinFields[0].provides &&
|
|
315
|
+
!joinFields[0].requires &&
|
|
316
|
+
!joinFields[0].type
|
|
317
|
+
? []
|
|
318
|
+
: joinFields,
|
|
281
319
|
},
|
|
282
320
|
arguments: Array.from(field.args.values())
|
|
283
321
|
.filter(arg => {
|
|
@@ -309,29 +347,7 @@ function objectTypeBuilder() {
|
|
|
309
347
|
policies: objectType.policies,
|
|
310
348
|
scopes: objectType.scopes,
|
|
311
349
|
join: {
|
|
312
|
-
type:
|
|
313
|
-
?
|
|
314
|
-
Array.from(graphs.values()).map(graph => ({
|
|
315
|
-
graph: graph.id,
|
|
316
|
-
}))
|
|
317
|
-
:
|
|
318
|
-
Array.from(objectType.byGraph.entries())
|
|
319
|
-
.map(([graphId, meta]) => {
|
|
320
|
-
if (meta.keys.length) {
|
|
321
|
-
return meta.keys.map(key => ({
|
|
322
|
-
graph: graphId,
|
|
323
|
-
key: key.fields,
|
|
324
|
-
extension: isRealExtension(meta, graphs.get(graphId).version),
|
|
325
|
-
resolvable: key.resolvable,
|
|
326
|
-
}));
|
|
327
|
-
}
|
|
328
|
-
return [
|
|
329
|
-
{
|
|
330
|
-
graph: graphId,
|
|
331
|
-
},
|
|
332
|
-
];
|
|
333
|
-
})
|
|
334
|
-
.flat(1),
|
|
350
|
+
type: joinTypes,
|
|
335
351
|
implements: objectType.interfaces.size > 0
|
|
336
352
|
? Array.from(objectType.byGraph.entries())
|
|
337
353
|
.map(([graph, meta]) => {
|
package/cjs/supergraph/state.js
CHANGED
|
@@ -114,6 +114,15 @@ function createSupergraphStateBuilder() {
|
|
|
114
114
|
},
|
|
115
115
|
build() {
|
|
116
116
|
const transformFields = createFieldsTransformer(state);
|
|
117
|
+
const graphNameToIdMap = {};
|
|
118
|
+
for (const [id, graph] of state.graphs) {
|
|
119
|
+
graphNameToIdMap[graph.name] = id;
|
|
120
|
+
}
|
|
121
|
+
const helpers = {
|
|
122
|
+
graphNameToId(graphName) {
|
|
123
|
+
return graphNameToIdMap[graphName] ?? null;
|
|
124
|
+
},
|
|
125
|
+
};
|
|
117
126
|
const numberOfExpectedNodes = state.directives.size +
|
|
118
127
|
state.scalarTypes.size +
|
|
119
128
|
state.objectTypes.size +
|
|
@@ -130,25 +139,25 @@ function createSupergraphStateBuilder() {
|
|
|
130
139
|
url: graph.url ?? '',
|
|
131
140
|
})));
|
|
132
141
|
for (const directiveState of state.directives.values()) {
|
|
133
|
-
nodes[i++] = directive.composeSupergraphNode(directiveState, state.graphs);
|
|
142
|
+
nodes[i++] = directive.composeSupergraphNode(directiveState, state.graphs, helpers);
|
|
134
143
|
}
|
|
135
144
|
for (const scalarTypeState of state.scalarTypes.values()) {
|
|
136
|
-
nodes[i++] = scalarType.composeSupergraphNode(scalarTypeState, state.graphs);
|
|
145
|
+
nodes[i++] = scalarType.composeSupergraphNode(scalarTypeState, state.graphs, helpers);
|
|
137
146
|
}
|
|
138
147
|
for (const objectTypeState of state.objectTypes.values()) {
|
|
139
|
-
nodes[i++] = objectType.composeSupergraphNode(transformFields(objectTypeState), state.graphs);
|
|
148
|
+
nodes[i++] = objectType.composeSupergraphNode(transformFields(objectTypeState), state.graphs, helpers);
|
|
140
149
|
}
|
|
141
150
|
for (const interfaceTypeState of state.interfaceTypes.values()) {
|
|
142
|
-
nodes[i++] = interfaceType.composeSupergraphNode(interfaceTypeState, state.graphs);
|
|
151
|
+
nodes[i++] = interfaceType.composeSupergraphNode(interfaceTypeState, state.graphs, helpers);
|
|
143
152
|
}
|
|
144
153
|
for (const unionTypeState of state.unionTypes.values()) {
|
|
145
|
-
nodes[i++] = unionType.composeSupergraphNode(unionTypeState, state.graphs);
|
|
154
|
+
nodes[i++] = unionType.composeSupergraphNode(unionTypeState, state.graphs, helpers);
|
|
146
155
|
}
|
|
147
156
|
for (const enumTypeState of state.enumTypes.values()) {
|
|
148
|
-
nodes[i++] = enumType.composeSupergraphNode(enumTypeState, state.graphs);
|
|
157
|
+
nodes[i++] = enumType.composeSupergraphNode(enumTypeState, state.graphs, helpers);
|
|
149
158
|
}
|
|
150
159
|
for (const inputObjectTypeState of state.inputObjectTypes.values()) {
|
|
151
|
-
nodes[i++] = inputObjectType.composeSupergraphNode(inputObjectTypeState, state.graphs);
|
|
160
|
+
nodes[i++] = inputObjectType.composeSupergraphNode(inputObjectTypeState, state.graphs, helpers);
|
|
152
161
|
}
|
|
153
162
|
return nodes;
|
|
154
163
|
},
|
|
@@ -536,7 +536,7 @@ function SatisfiabilityRule(context, supergraphState) {
|
|
|
536
536
|
? localSchemaDefinition.subscriptionType
|
|
537
537
|
: undefined;
|
|
538
538
|
if (!localRootTypeName) {
|
|
539
|
-
return
|
|
539
|
+
return false;
|
|
540
540
|
}
|
|
541
541
|
const localRootType = localSubgraph.types.get(localRootTypeName);
|
|
542
542
|
const localRootFields = Array.from(localRootType.fields.keys());
|
package/esm/subgraph/state.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Kind, OperationTypeNode, } from 'graphql';
|
|
1
|
+
import { Kind, OperationTypeNode, specifiedDirectives as specifiedDirectiveTypes, specifiedScalarTypes, } from 'graphql';
|
|
2
2
|
import { print } from '../graphql/printer.js';
|
|
3
3
|
import { isFederationLink } from '../specifications/federation.js';
|
|
4
4
|
import { printOutputType } from './helpers.js';
|
|
@@ -18,6 +18,8 @@ export function createSubgraphStateBuilder(graph, typeDefs, version, links) {
|
|
|
18
18
|
const isLinkSpecManuallyProvided = typeDefs.definitions.some(def => def.kind === Kind.DIRECTIVE_DEFINITION &&
|
|
19
19
|
def.name.value === 'link' &&
|
|
20
20
|
def.locations.every(loc => loc.value === 'SCHEMA'));
|
|
21
|
+
const specifiedScalars = specifiedScalarTypes.map(type => type.name);
|
|
22
|
+
const specifiedDirectives = specifiedDirectiveTypes.map(directive => directive.name);
|
|
21
23
|
const state = {
|
|
22
24
|
graph: {
|
|
23
25
|
...graph,
|
|
@@ -227,7 +229,9 @@ export function createSubgraphStateBuilder(graph, typeDefs, version, links) {
|
|
|
227
229
|
inputObjectTypeBuilder.setDefinition(node.name.value);
|
|
228
230
|
},
|
|
229
231
|
ScalarTypeDefinition(node) {
|
|
230
|
-
|
|
232
|
+
if (!specifiedScalars.includes(node.name.value)) {
|
|
233
|
+
scalarTypeBuilder.setDefinition(node.name.value);
|
|
234
|
+
}
|
|
231
235
|
},
|
|
232
236
|
ScalarTypeExtension() {
|
|
233
237
|
},
|
|
@@ -348,6 +352,9 @@ export function createSubgraphStateBuilder(graph, typeDefs, version, links) {
|
|
|
348
352
|
},
|
|
349
353
|
DirectiveDefinition(node) {
|
|
350
354
|
const directiveName = node.name.value;
|
|
355
|
+
if (specifiedDirectives.includes(directiveName)) {
|
|
356
|
+
return;
|
|
357
|
+
}
|
|
351
358
|
if (node.repeatable) {
|
|
352
359
|
directiveBuilder.setRepeatable(directiveName);
|
|
353
360
|
}
|
|
@@ -32,7 +32,7 @@ export function inputObjectTypeBuilder() {
|
|
|
32
32
|
if (field.deprecated && !fieldState.deprecated) {
|
|
33
33
|
fieldState.deprecated = field.deprecated;
|
|
34
34
|
}
|
|
35
|
-
if (typeof field.defaultValue
|
|
35
|
+
if (typeof field.defaultValue !== 'undefined') {
|
|
36
36
|
fieldState.defaultValue = field.defaultValue;
|
|
37
37
|
}
|
|
38
38
|
fieldState.byGraph.set(graph.id, {
|
|
@@ -56,13 +56,16 @@ export function inputObjectTypeBuilder() {
|
|
|
56
56
|
return true;
|
|
57
57
|
})
|
|
58
58
|
.map(field => {
|
|
59
|
-
const
|
|
59
|
+
const fieldStateInGraphs = Array.from(field.byGraph.values());
|
|
60
|
+
const hasDifferentType = fieldStateInGraphs.some(f => f.type !== field.type);
|
|
60
61
|
return {
|
|
61
62
|
name: field.name,
|
|
62
63
|
type: field.type,
|
|
63
64
|
tags: Array.from(field.tags),
|
|
64
65
|
inaccessible: field.inaccessible,
|
|
65
|
-
defaultValue:
|
|
66
|
+
defaultValue: fieldStateInGraphs.every(f => typeof f.defaultValue !== 'undefined')
|
|
67
|
+
? field.defaultValue
|
|
68
|
+
: undefined,
|
|
66
69
|
description: field.description,
|
|
67
70
|
deprecated: field.deprecated,
|
|
68
71
|
join: {
|
|
@@ -79,7 +79,7 @@ export function interfaceTypeBuilder() {
|
|
|
79
79
|
if (arg.description && !argState.description) {
|
|
80
80
|
argState.description = arg.description;
|
|
81
81
|
}
|
|
82
|
-
if (typeof arg.defaultValue
|
|
82
|
+
if (typeof arg.defaultValue !== 'undefined') {
|
|
83
83
|
argState.defaultValue = arg.defaultValue;
|
|
84
84
|
}
|
|
85
85
|
arg.ast.directives.forEach(directive => {
|
|
@@ -133,7 +133,7 @@ export function objectTypeBuilder() {
|
|
|
133
133
|
arg.ast.directives.forEach(directive => {
|
|
134
134
|
argState.ast.directives.push(directive);
|
|
135
135
|
});
|
|
136
|
-
if (typeof arg.defaultValue
|
|
136
|
+
if (typeof arg.defaultValue !== 'undefined') {
|
|
137
137
|
argState.defaultValue = arg.defaultValue;
|
|
138
138
|
}
|
|
139
139
|
argState.byGraph.set(graph.id, {
|
|
@@ -144,8 +144,31 @@ export function objectTypeBuilder() {
|
|
|
144
144
|
}
|
|
145
145
|
}
|
|
146
146
|
},
|
|
147
|
-
composeSupergraphNode(objectType, graphs) {
|
|
147
|
+
composeSupergraphNode(objectType, graphs, { graphNameToId }) {
|
|
148
148
|
const isQuery = objectType.name === 'Query';
|
|
149
|
+
const joinTypes = isQuery
|
|
150
|
+
?
|
|
151
|
+
Array.from(graphs.values()).map(graph => ({
|
|
152
|
+
graph: graph.id,
|
|
153
|
+
}))
|
|
154
|
+
:
|
|
155
|
+
Array.from(objectType.byGraph.entries())
|
|
156
|
+
.map(([graphId, meta]) => {
|
|
157
|
+
if (meta.keys.length) {
|
|
158
|
+
return meta.keys.map(key => ({
|
|
159
|
+
graph: graphId,
|
|
160
|
+
key: key.fields,
|
|
161
|
+
extension: isRealExtension(meta, graphs.get(graphId).version),
|
|
162
|
+
resolvable: key.resolvable,
|
|
163
|
+
}));
|
|
164
|
+
}
|
|
165
|
+
return [
|
|
166
|
+
{
|
|
167
|
+
graph: graphId,
|
|
168
|
+
},
|
|
169
|
+
];
|
|
170
|
+
})
|
|
171
|
+
.flat(1);
|
|
149
172
|
return createObjectTypeNode({
|
|
150
173
|
name: objectType.name,
|
|
151
174
|
ast: {
|
|
@@ -210,15 +233,22 @@ export function objectTypeBuilder() {
|
|
|
210
233
|
else if (isDefinedEverywhere) {
|
|
211
234
|
const hasDifferencesBetweenGraphs = Object.values(differencesBetweenGraphs).some(value => value === true);
|
|
212
235
|
if (differencesBetweenGraphs.override) {
|
|
213
|
-
const
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
236
|
+
const mutedGraphs = fieldInGraphs
|
|
237
|
+
.map(([_, meta]) => (meta.override ? graphNameToId(meta.override) : null))
|
|
238
|
+
.filter((graphId) => typeof graphId === 'string');
|
|
239
|
+
const graphsToEmit = fieldInGraphs.filter(([graphId, f]) => f.external || !mutedGraphs.includes(graphId));
|
|
240
|
+
if (!(graphsToEmit.length === 1 &&
|
|
241
|
+
joinTypes.length === 1 &&
|
|
242
|
+
joinTypes[0].graph === graphsToEmit[0][0])) {
|
|
243
|
+
joinFields = graphsToEmit.map(([graphId, meta]) => ({
|
|
244
|
+
graph: graphId,
|
|
245
|
+
override: meta.override ?? undefined,
|
|
246
|
+
type: differencesBetweenGraphs.type ? meta.type : undefined,
|
|
247
|
+
external: meta.external ?? undefined,
|
|
248
|
+
provides: meta.provides ?? undefined,
|
|
249
|
+
requires: meta.requires ?? undefined,
|
|
250
|
+
}));
|
|
251
|
+
}
|
|
222
252
|
}
|
|
223
253
|
else if (hasDifferencesBetweenGraphs) {
|
|
224
254
|
joinFields = fieldInGraphs.map(([graphId, meta]) => ({
|
|
@@ -273,7 +303,15 @@ export function objectTypeBuilder() {
|
|
|
273
303
|
directives: convertToConst(field.ast.directives),
|
|
274
304
|
},
|
|
275
305
|
join: {
|
|
276
|
-
field: joinFields
|
|
306
|
+
field: joinFields.length === 1 &&
|
|
307
|
+
joinTypes.length === 1 &&
|
|
308
|
+
!joinFields[0].external &&
|
|
309
|
+
!joinFields[0].override &&
|
|
310
|
+
!joinFields[0].provides &&
|
|
311
|
+
!joinFields[0].requires &&
|
|
312
|
+
!joinFields[0].type
|
|
313
|
+
? []
|
|
314
|
+
: joinFields,
|
|
277
315
|
},
|
|
278
316
|
arguments: Array.from(field.args.values())
|
|
279
317
|
.filter(arg => {
|
|
@@ -305,29 +343,7 @@ export function objectTypeBuilder() {
|
|
|
305
343
|
policies: objectType.policies,
|
|
306
344
|
scopes: objectType.scopes,
|
|
307
345
|
join: {
|
|
308
|
-
type:
|
|
309
|
-
?
|
|
310
|
-
Array.from(graphs.values()).map(graph => ({
|
|
311
|
-
graph: graph.id,
|
|
312
|
-
}))
|
|
313
|
-
:
|
|
314
|
-
Array.from(objectType.byGraph.entries())
|
|
315
|
-
.map(([graphId, meta]) => {
|
|
316
|
-
if (meta.keys.length) {
|
|
317
|
-
return meta.keys.map(key => ({
|
|
318
|
-
graph: graphId,
|
|
319
|
-
key: key.fields,
|
|
320
|
-
extension: isRealExtension(meta, graphs.get(graphId).version),
|
|
321
|
-
resolvable: key.resolvable,
|
|
322
|
-
}));
|
|
323
|
-
}
|
|
324
|
-
return [
|
|
325
|
-
{
|
|
326
|
-
graph: graphId,
|
|
327
|
-
},
|
|
328
|
-
];
|
|
329
|
-
})
|
|
330
|
-
.flat(1),
|
|
346
|
+
type: joinTypes,
|
|
331
347
|
implements: objectType.interfaces.size > 0
|
|
332
348
|
? Array.from(objectType.byGraph.entries())
|
|
333
349
|
.map(([graph, meta]) => {
|
package/esm/supergraph/state.js
CHANGED
|
@@ -111,6 +111,15 @@ export function createSupergraphStateBuilder() {
|
|
|
111
111
|
},
|
|
112
112
|
build() {
|
|
113
113
|
const transformFields = createFieldsTransformer(state);
|
|
114
|
+
const graphNameToIdMap = {};
|
|
115
|
+
for (const [id, graph] of state.graphs) {
|
|
116
|
+
graphNameToIdMap[graph.name] = id;
|
|
117
|
+
}
|
|
118
|
+
const helpers = {
|
|
119
|
+
graphNameToId(graphName) {
|
|
120
|
+
return graphNameToIdMap[graphName] ?? null;
|
|
121
|
+
},
|
|
122
|
+
};
|
|
114
123
|
const numberOfExpectedNodes = state.directives.size +
|
|
115
124
|
state.scalarTypes.size +
|
|
116
125
|
state.objectTypes.size +
|
|
@@ -127,25 +136,25 @@ export function createSupergraphStateBuilder() {
|
|
|
127
136
|
url: graph.url ?? '',
|
|
128
137
|
})));
|
|
129
138
|
for (const directiveState of state.directives.values()) {
|
|
130
|
-
nodes[i++] = directive.composeSupergraphNode(directiveState, state.graphs);
|
|
139
|
+
nodes[i++] = directive.composeSupergraphNode(directiveState, state.graphs, helpers);
|
|
131
140
|
}
|
|
132
141
|
for (const scalarTypeState of state.scalarTypes.values()) {
|
|
133
|
-
nodes[i++] = scalarType.composeSupergraphNode(scalarTypeState, state.graphs);
|
|
142
|
+
nodes[i++] = scalarType.composeSupergraphNode(scalarTypeState, state.graphs, helpers);
|
|
134
143
|
}
|
|
135
144
|
for (const objectTypeState of state.objectTypes.values()) {
|
|
136
|
-
nodes[i++] = objectType.composeSupergraphNode(transformFields(objectTypeState), state.graphs);
|
|
145
|
+
nodes[i++] = objectType.composeSupergraphNode(transformFields(objectTypeState), state.graphs, helpers);
|
|
137
146
|
}
|
|
138
147
|
for (const interfaceTypeState of state.interfaceTypes.values()) {
|
|
139
|
-
nodes[i++] = interfaceType.composeSupergraphNode(interfaceTypeState, state.graphs);
|
|
148
|
+
nodes[i++] = interfaceType.composeSupergraphNode(interfaceTypeState, state.graphs, helpers);
|
|
140
149
|
}
|
|
141
150
|
for (const unionTypeState of state.unionTypes.values()) {
|
|
142
|
-
nodes[i++] = unionType.composeSupergraphNode(unionTypeState, state.graphs);
|
|
151
|
+
nodes[i++] = unionType.composeSupergraphNode(unionTypeState, state.graphs, helpers);
|
|
143
152
|
}
|
|
144
153
|
for (const enumTypeState of state.enumTypes.values()) {
|
|
145
|
-
nodes[i++] = enumType.composeSupergraphNode(enumTypeState, state.graphs);
|
|
154
|
+
nodes[i++] = enumType.composeSupergraphNode(enumTypeState, state.graphs, helpers);
|
|
146
155
|
}
|
|
147
156
|
for (const inputObjectTypeState of state.inputObjectTypes.values()) {
|
|
148
|
-
nodes[i++] = inputObjectType.composeSupergraphNode(inputObjectTypeState, state.graphs);
|
|
157
|
+
nodes[i++] = inputObjectType.composeSupergraphNode(inputObjectTypeState, state.graphs, helpers);
|
|
149
158
|
}
|
|
150
159
|
return nodes;
|
|
151
160
|
},
|
|
@@ -533,7 +533,7 @@ export function SatisfiabilityRule(context, supergraphState) {
|
|
|
533
533
|
? localSchemaDefinition.subscriptionType
|
|
534
534
|
: undefined;
|
|
535
535
|
if (!localRootTypeName) {
|
|
536
|
-
return
|
|
536
|
+
return false;
|
|
537
537
|
}
|
|
538
538
|
const localRootType = localSubgraph.types.get(localRootTypeName);
|
|
539
539
|
const localRootFields = Array.from(localRootType.fields.keys());
|
package/package.json
CHANGED
|
@@ -13,7 +13,9 @@ export interface Graph {
|
|
|
13
13
|
}
|
|
14
14
|
export interface TypeBuilder<T, S> {
|
|
15
15
|
visitSubgraphState(graph: Graph, state: Map<string, S>, typeName: string, type: T): void;
|
|
16
|
-
composeSupergraphNode(type: S, graphMap: Map<string, Graph
|
|
16
|
+
composeSupergraphNode(type: S, graphMap: Map<string, Graph>, helpers: {
|
|
17
|
+
graphNameToId(graphName: string): string | null;
|
|
18
|
+
}): TypeDefinitionNode | DirectiveDefinitionNode;
|
|
17
19
|
}
|
|
18
20
|
export declare function convertToConst(nodes: DirectiveNode[]): ConstDirectiveNode[];
|
|
19
21
|
//# sourceMappingURL=common.d.ts.map
|
|
@@ -13,7 +13,9 @@ export interface Graph {
|
|
|
13
13
|
}
|
|
14
14
|
export interface TypeBuilder<T, S> {
|
|
15
15
|
visitSubgraphState(graph: Graph, state: Map<string, S>, typeName: string, type: T): void;
|
|
16
|
-
composeSupergraphNode(type: S, graphMap: Map<string, Graph
|
|
16
|
+
composeSupergraphNode(type: S, graphMap: Map<string, Graph>, helpers: {
|
|
17
|
+
graphNameToId(graphName: string): string | null;
|
|
18
|
+
}): TypeDefinitionNode | DirectiveDefinitionNode;
|
|
17
19
|
}
|
|
18
20
|
export declare function convertToConst(nodes: DirectiveNode[]): ConstDirectiveNode[];
|
|
19
21
|
//# sourceMappingURL=common.d.ts.map
|