@graphql-mesh/compose-cli 1.4.1 → 1.4.2-alpha-20250317141626-bbdf676e6a254787f49ca8b8ee9c35afa21e293c
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.
|
@@ -163,12 +163,49 @@ async function getComposedSchemaFromConfig(config, logger) {
|
|
|
163
163
|
assumeValidSDL: true,
|
|
164
164
|
});
|
|
165
165
|
if (additionalTypeDefs?.length) {
|
|
166
|
+
const originalComposedSchema = composedSchema;
|
|
166
167
|
composedSchema = (0, schema_1.mergeSchemas)({
|
|
167
168
|
schemas: [composedSchema],
|
|
168
169
|
typeDefs: additionalTypeDefs,
|
|
169
170
|
assumeValid: true,
|
|
170
171
|
assumeValidSDL: true,
|
|
171
172
|
});
|
|
173
|
+
// Fix extra additionalField annotations
|
|
174
|
+
if (composedSchema.getDirective('additionalField')) {
|
|
175
|
+
let composedSchemaAST = (0, utils_2.getDocumentNodeFromSchema)(composedSchema);
|
|
176
|
+
composedSchemaAST = (0, graphql_1.visit)(composedSchemaAST, {
|
|
177
|
+
[graphql_1.Kind.FIELD_DEFINITION](node, __key, __parent, __path, ancestors) {
|
|
178
|
+
const directiveNames = node.directives?.map(directive => directive.name.value);
|
|
179
|
+
if (directiveNames.includes('additionalField')) {
|
|
180
|
+
if (directiveNames.includes('join__field') || directiveNames.includes('source')) {
|
|
181
|
+
return {
|
|
182
|
+
...node,
|
|
183
|
+
directives: node.directives?.filter(directive => directive.name.value !== 'additionalField'),
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
const typeInAncestor = ancestors
|
|
187
|
+
.toReversed()
|
|
188
|
+
.find(ancestor => !Array.isArray(ancestor) &&
|
|
189
|
+
ancestor != null &&
|
|
190
|
+
typeof ancestor === 'object' &&
|
|
191
|
+
'kind' in ancestor);
|
|
192
|
+
if (typeInAncestor) {
|
|
193
|
+
const typeInOriginalSchema = originalComposedSchema.getType(typeInAncestor.name.value);
|
|
194
|
+
if (typeInOriginalSchema && 'getFields' in typeInOriginalSchema) {
|
|
195
|
+
const field = typeInOriginalSchema.getFields()[node.name.value];
|
|
196
|
+
if (field) {
|
|
197
|
+
return {
|
|
198
|
+
...node,
|
|
199
|
+
directives: node.directives?.filter(directive => directive.name.value !== 'additionalField'),
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
},
|
|
206
|
+
});
|
|
207
|
+
return (0, graphql_1.print)(composedSchemaAST);
|
|
208
|
+
}
|
|
172
209
|
}
|
|
173
210
|
/* TODO
|
|
174
211
|
if (config.transforms?.length) {
|
|
@@ -5,7 +5,7 @@ import { CodeFileLoader } from '@graphql-tools/code-file-loader';
|
|
|
5
5
|
import { GraphQLFileLoader } from '@graphql-tools/graphql-file-loader';
|
|
6
6
|
import { loadTypedefs } from '@graphql-tools/load';
|
|
7
7
|
import { mergeSchemas } from '@graphql-tools/schema';
|
|
8
|
-
import { astFromValueUntyped, printSchemaWithDirectives } from '@graphql-tools/utils';
|
|
8
|
+
import { astFromValueUntyped, getDocumentNodeFromSchema, printSchemaWithDirectives, } from '@graphql-tools/utils';
|
|
9
9
|
import { fetch as defaultFetch } from '@whatwg-node/fetch';
|
|
10
10
|
const isDebug = ['1', 'y', 'yes', 't', 'true'].includes(String(process.env.DEBUG));
|
|
11
11
|
export async function getComposedSchemaFromConfig(config, logger) {
|
|
@@ -160,12 +160,49 @@ export async function getComposedSchemaFromConfig(config, logger) {
|
|
|
160
160
|
assumeValidSDL: true,
|
|
161
161
|
});
|
|
162
162
|
if (additionalTypeDefs?.length) {
|
|
163
|
+
const originalComposedSchema = composedSchema;
|
|
163
164
|
composedSchema = mergeSchemas({
|
|
164
165
|
schemas: [composedSchema],
|
|
165
166
|
typeDefs: additionalTypeDefs,
|
|
166
167
|
assumeValid: true,
|
|
167
168
|
assumeValidSDL: true,
|
|
168
169
|
});
|
|
170
|
+
// Fix extra additionalField annotations
|
|
171
|
+
if (composedSchema.getDirective('additionalField')) {
|
|
172
|
+
let composedSchemaAST = getDocumentNodeFromSchema(composedSchema);
|
|
173
|
+
composedSchemaAST = visit(composedSchemaAST, {
|
|
174
|
+
[Kind.FIELD_DEFINITION](node, __key, __parent, __path, ancestors) {
|
|
175
|
+
const directiveNames = node.directives?.map(directive => directive.name.value);
|
|
176
|
+
if (directiveNames.includes('additionalField')) {
|
|
177
|
+
if (directiveNames.includes('join__field') || directiveNames.includes('source')) {
|
|
178
|
+
return {
|
|
179
|
+
...node,
|
|
180
|
+
directives: node.directives?.filter(directive => directive.name.value !== 'additionalField'),
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
const typeInAncestor = ancestors
|
|
184
|
+
.toReversed()
|
|
185
|
+
.find(ancestor => !Array.isArray(ancestor) &&
|
|
186
|
+
ancestor != null &&
|
|
187
|
+
typeof ancestor === 'object' &&
|
|
188
|
+
'kind' in ancestor);
|
|
189
|
+
if (typeInAncestor) {
|
|
190
|
+
const typeInOriginalSchema = originalComposedSchema.getType(typeInAncestor.name.value);
|
|
191
|
+
if (typeInOriginalSchema && 'getFields' in typeInOriginalSchema) {
|
|
192
|
+
const field = typeInOriginalSchema.getFields()[node.name.value];
|
|
193
|
+
if (field) {
|
|
194
|
+
return {
|
|
195
|
+
...node,
|
|
196
|
+
directives: node.directives?.filter(directive => directive.name.value !== 'additionalField'),
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
},
|
|
203
|
+
});
|
|
204
|
+
return print(composedSchemaAST);
|
|
205
|
+
}
|
|
169
206
|
}
|
|
170
207
|
/* TODO
|
|
171
208
|
if (config.transforms?.length) {
|