@omnigraph/json-schema 1.0.0-alpha-20230523154231-8c60b52d9 → 1.0.0-alpha-20230523155104-df277a22b
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/addExecutionLogicToComposer.js +4 -4
- package/cjs/addRootFieldResolver.js +10 -13
- package/cjs/directives.js +4 -4
- package/cjs/getComposerFromJSONSchema.js +22 -26
- package/cjs/getTypeResolverFromOutputTCs.js +2 -2
- package/cjs/getUnionTypeComposers.js +1 -2
- package/cjs/resolveDataByUnionInputType.js +2 -3
- package/esm/addExecutionLogicToComposer.js +4 -4
- package/esm/addRootFieldResolver.js +10 -13
- package/esm/directives.js +4 -4
- package/esm/getComposerFromJSONSchema.js +22 -26
- package/esm/getTypeResolverFromOutputTCs.js +2 -2
- package/esm/getUnionTypeComposers.js +1 -2
- package/esm/resolveDataByUnionInputType.js +2 -3
- package/package.json +11 -8
|
@@ -18,7 +18,6 @@ const responseMetadataType = new graphql_1.GraphQLObjectType({
|
|
|
18
18
|
},
|
|
19
19
|
});
|
|
20
20
|
async function addExecutionDirectivesToComposer(name, { schemaComposer, logger, operations, operationHeaders, endpoint, queryParams, queryStringOptions, }) {
|
|
21
|
-
var _a, _b;
|
|
22
21
|
schemaComposer.addDirective(directives_js_1.GlobalOptionsDirective);
|
|
23
22
|
schemaComposer.Query.setDirectiveByName('globalOptions', JSON.parse(JSON.stringify({
|
|
24
23
|
sourceName: name,
|
|
@@ -94,12 +93,12 @@ ${operationConfig.description || ''}
|
|
|
94
93
|
targetField = schemaComposer.Query.getField(linkObj.fieldName);
|
|
95
94
|
fieldTypeName = 'Query';
|
|
96
95
|
}
|
|
97
|
-
catch
|
|
96
|
+
catch {
|
|
98
97
|
try {
|
|
99
98
|
targetField = schemaComposer.Mutation.getField(linkObj.fieldName);
|
|
100
99
|
fieldTypeName = 'Mutation';
|
|
101
100
|
}
|
|
102
|
-
catch
|
|
101
|
+
catch { }
|
|
103
102
|
}
|
|
104
103
|
if (!targetField) {
|
|
105
104
|
logger.debug(`Field ${linkObj.fieldName} not found in ${name} for link ${linkName}`);
|
|
@@ -153,7 +152,8 @@ ${operationConfig.description || ''}
|
|
|
153
152
|
const directives = unionOrSingleTC.getDirectives();
|
|
154
153
|
for (const directive of directives) {
|
|
155
154
|
if (directive.name === 'statusCodeOneOfIndex') {
|
|
156
|
-
statusCodeOneOfIndexMap[
|
|
155
|
+
statusCodeOneOfIndexMap[directive.args?.statusCode] = directive.args
|
|
156
|
+
?.oneOfIndex;
|
|
157
157
|
}
|
|
158
158
|
}
|
|
159
159
|
for (const statusCode in operationConfig.responseByStatusCode) {
|
|
@@ -29,7 +29,6 @@ function addHTTPRootFieldResolver(schema, field, logger, globalFetch, { path, op
|
|
|
29
29
|
};
|
|
30
30
|
const returnNamedGraphQLType = (0, graphql_1.getNamedType)(field.type);
|
|
31
31
|
field.resolve = async (root, args, context, info) => {
|
|
32
|
-
var _a, _b;
|
|
33
32
|
const operationLogger = logger.child(`${info.parentType.name}.${info.fieldName}`);
|
|
34
33
|
operationLogger.debug(`=> Resolving`);
|
|
35
34
|
const interpolationData = { root, args, context, env: cross_helpers_1.process.env };
|
|
@@ -94,13 +93,13 @@ function addHTTPRootFieldResolver(schema, field, logger, globalFetch, { path, op
|
|
|
94
93
|
}
|
|
95
94
|
}
|
|
96
95
|
// Resolve union input
|
|
97
|
-
const input = (args.input = (0, resolveDataByUnionInputType_js_1.resolveDataByUnionInputType)(args.input,
|
|
96
|
+
const input = (args.input = (0, resolveDataByUnionInputType_js_1.resolveDataByUnionInputType)(args.input, field.args?.find(arg => arg.name === 'input')?.type, schema));
|
|
98
97
|
if (input != null) {
|
|
99
98
|
const [, contentType] = Object.entries(headers).find(([key]) => key.toLowerCase() === 'content-type') || [];
|
|
100
|
-
if (contentType
|
|
99
|
+
if (contentType?.startsWith('application/x-www-form-urlencoded')) {
|
|
101
100
|
requestInit.body = (0, qs_1.stringify)(input, globalQueryStringOptions);
|
|
102
101
|
}
|
|
103
|
-
else if (contentType
|
|
102
|
+
else if (contentType?.startsWith('multipart/form-data')) {
|
|
104
103
|
delete headers['content-type'];
|
|
105
104
|
delete headers['Content-Type'];
|
|
106
105
|
const formData = new fetch_1.FormData();
|
|
@@ -158,7 +157,7 @@ function addHTTPRootFieldResolver(schema, field, logger, globalFetch, { path, op
|
|
|
158
157
|
[queryParamName]: interpolatedQueryParam,
|
|
159
158
|
}, {
|
|
160
159
|
...globalQueryStringOptions,
|
|
161
|
-
...queryStringOptionsByParam
|
|
160
|
+
...queryStringOptionsByParam?.[queryParamName],
|
|
162
161
|
});
|
|
163
162
|
fullPath += fullPath.includes('?') ? '&' : '?';
|
|
164
163
|
fullPath += queryParamsString;
|
|
@@ -175,7 +174,7 @@ function addHTTPRootFieldResolver(schema, field, logger, globalFetch, { path, op
|
|
|
175
174
|
}
|
|
176
175
|
const opts = {
|
|
177
176
|
...globalQueryStringOptions,
|
|
178
|
-
...queryStringOptionsByParam
|
|
177
|
+
...queryStringOptionsByParam?.[queryParamName],
|
|
179
178
|
};
|
|
180
179
|
let queryParamObj = argValue;
|
|
181
180
|
if (Array.isArray(argValue) || !(typeof argValue === 'object' && opts.destructObject)) {
|
|
@@ -190,7 +189,7 @@ function addHTTPRootFieldResolver(schema, field, logger, globalFetch, { path, op
|
|
|
190
189
|
}
|
|
191
190
|
}
|
|
192
191
|
operationLogger.debug(`=> Fetching `, fullPath, `=>`, requestInit);
|
|
193
|
-
const fetch =
|
|
192
|
+
const fetch = context?.fetch || globalFetch;
|
|
194
193
|
if (!fetch) {
|
|
195
194
|
return (0, utils_2.createGraphQLError)(`You should have fetch defined in either the config or the context!`, {
|
|
196
195
|
extensions: {
|
|
@@ -341,11 +340,10 @@ function addHTTPRootFieldResolver(schema, field, logger, globalFetch, { path, op
|
|
|
341
340
|
case 'path':
|
|
342
341
|
return new Proxy(args, {
|
|
343
342
|
get(_, prop) {
|
|
344
|
-
|
|
345
|
-
return args[prop] || ((_a = args.input) === null || _a === void 0 ? void 0 : _a[prop]) || (obj === null || obj === void 0 ? void 0 : obj[prop]);
|
|
343
|
+
return args[prop] || args.input?.[prop] || obj?.[prop];
|
|
346
344
|
},
|
|
347
345
|
has(_, prop) {
|
|
348
|
-
return prop in args || (args.input && prop in args.input) ||
|
|
346
|
+
return prop in args || (args.input && prop in args.input) || obj?.[prop];
|
|
349
347
|
},
|
|
350
348
|
});
|
|
351
349
|
case 'header':
|
|
@@ -371,11 +369,10 @@ function addHTTPRootFieldResolver(schema, field, logger, globalFetch, { path, op
|
|
|
371
369
|
case 'path':
|
|
372
370
|
return new Proxy(args, {
|
|
373
371
|
get(_, prop) {
|
|
374
|
-
|
|
375
|
-
return args[prop] || ((_a = args.input) === null || _a === void 0 ? void 0 : _a[prop]) || (obj === null || obj === void 0 ? void 0 : obj[prop]);
|
|
372
|
+
return args[prop] || args.input?.[prop] || obj?.[prop];
|
|
376
373
|
},
|
|
377
374
|
has(_, prop) {
|
|
378
|
-
return prop in args || (args.input && prop in args.input) ||
|
|
375
|
+
return prop in args || (args.input && prop in args.input) || obj?.[prop];
|
|
379
376
|
},
|
|
380
377
|
});
|
|
381
378
|
}
|
package/cjs/directives.js
CHANGED
|
@@ -151,7 +151,7 @@ exports.PubSubOperationDirective = new graphql_1.GraphQLDirective({
|
|
|
151
151
|
function processPubSubOperationAnnotations({ field, globalPubsub, pubsubTopic, logger, }) {
|
|
152
152
|
field.subscribe = (root, args, context, info) => {
|
|
153
153
|
const operationLogger = logger.child(`${info.parentType.name}.${field.name}`);
|
|
154
|
-
const pubsub =
|
|
154
|
+
const pubsub = context?.pubsub || globalPubsub;
|
|
155
155
|
if (!pubsub) {
|
|
156
156
|
return (0, utils_1.createGraphQLError)(`You should have PubSub defined in either the config or the context!`);
|
|
157
157
|
}
|
|
@@ -348,7 +348,7 @@ function linkResolver({ linkObjArgs, targetTypeName, targetFieldName }, { root,
|
|
|
348
348
|
}
|
|
349
349
|
function getLinkResolverMap(schema, field) {
|
|
350
350
|
const parentFieldLinkResolverDirectives = (0, utils_1.getDirective)(schema, field, 'linkResolver');
|
|
351
|
-
if (parentFieldLinkResolverDirectives
|
|
351
|
+
if (parentFieldLinkResolverDirectives?.length) {
|
|
352
352
|
const linkResolverMap = parentFieldLinkResolverDirectives[0].linkResolverMap;
|
|
353
353
|
if (linkResolverMap) {
|
|
354
354
|
return linkResolverMap;
|
|
@@ -424,10 +424,10 @@ function processDirectives({ schema, globalFetch, logger, pubsub, ...extraGlobal
|
|
|
424
424
|
for (const typeName in typeMap) {
|
|
425
425
|
const type = typeMap[typeName];
|
|
426
426
|
const exampleAnnotations = (0, utils_1.getDirective)(schema, type, 'example');
|
|
427
|
-
if (exampleAnnotations
|
|
427
|
+
if (exampleAnnotations?.length) {
|
|
428
428
|
const examples = [];
|
|
429
429
|
for (const exampleAnnotation of exampleAnnotations) {
|
|
430
|
-
if (exampleAnnotation
|
|
430
|
+
if (exampleAnnotation?.value) {
|
|
431
431
|
examples.push(exampleAnnotation.value);
|
|
432
432
|
}
|
|
433
433
|
}
|
|
@@ -22,7 +22,6 @@ function getComposerFromJSONSchema(schema, logger) {
|
|
|
22
22
|
};
|
|
23
23
|
return (0, json_machete_1.visitJSONSchema)(schema, {
|
|
24
24
|
enter(subSchema, { path, visitedSubschemaResultMap }) {
|
|
25
|
-
var _a, _b, _c, _d, _e, _f;
|
|
26
25
|
if (typeof subSchema === 'boolean' || subSchema.title === 'Any') {
|
|
27
26
|
const typeComposer = schemaComposer.getAnyTC(graphql_scalars_1.GraphQLJSON);
|
|
28
27
|
return subSchema
|
|
@@ -195,7 +194,7 @@ function getComposerFromJSONSchema(schema, logger) {
|
|
|
195
194
|
schemaComposer.addDirective(directives_js_1.EnumDirective);
|
|
196
195
|
// Falsy values are ignored by GraphQL
|
|
197
196
|
// eslint-disable-next-line no-unneeded-ternary
|
|
198
|
-
const enumValue = value ? value : value
|
|
197
|
+
const enumValue = value ? value : value?.toString();
|
|
199
198
|
const directives = [];
|
|
200
199
|
if (enumValue !== enumKey) {
|
|
201
200
|
directives.push({
|
|
@@ -211,7 +210,7 @@ function getComposerFromJSONSchema(schema, logger) {
|
|
|
211
210
|
};
|
|
212
211
|
}
|
|
213
212
|
const directives = [];
|
|
214
|
-
if (
|
|
213
|
+
if (subSchema.examples?.length) {
|
|
215
214
|
schemaComposer.addDirective(directives_js_1.ExampleDirective);
|
|
216
215
|
for (const example of subSchema.examples) {
|
|
217
216
|
directives.push({
|
|
@@ -644,14 +643,14 @@ function getComposerFromJSONSchema(schema, logger) {
|
|
|
644
643
|
});
|
|
645
644
|
const extensions = {};
|
|
646
645
|
const directives = [];
|
|
647
|
-
if (
|
|
646
|
+
if (subSchema.$comment?.startsWith('statusCodeOneOfIndexMap:')) {
|
|
648
647
|
const statusCodeOneOfIndexMapStr = subSchema.$comment.replace('statusCodeOneOfIndexMap:', '');
|
|
649
648
|
const statusCodeOneOfIndexMap = JSON.parse(statusCodeOneOfIndexMapStr);
|
|
650
649
|
if (statusCodeOneOfIndexMap) {
|
|
651
650
|
extensions.statusCodeOneOfIndexMap = statusCodeOneOfIndexMap;
|
|
652
651
|
}
|
|
653
652
|
}
|
|
654
|
-
if (
|
|
653
|
+
if (subSchema.discriminator?.propertyName) {
|
|
655
654
|
schemaComposer.addDirective(directives_js_1.DiscriminatorDirective);
|
|
656
655
|
const mappingByName = {};
|
|
657
656
|
for (const discriminatorValue in subSchema.discriminator.mapping) {
|
|
@@ -713,7 +712,7 @@ function getComposerFromJSONSchema(schema, logger) {
|
|
|
713
712
|
default: subSchema.default,
|
|
714
713
|
},
|
|
715
714
|
};
|
|
716
|
-
if (
|
|
715
|
+
if (subSchema.examples?.length) {
|
|
717
716
|
schemaComposer.addDirective(directives_js_1.ExampleDirective);
|
|
718
717
|
for (const example of subSchema.examples) {
|
|
719
718
|
config.directives.push({
|
|
@@ -724,11 +723,11 @@ function getComposerFromJSONSchema(schema, logger) {
|
|
|
724
723
|
});
|
|
725
724
|
}
|
|
726
725
|
}
|
|
727
|
-
if (
|
|
726
|
+
if (subSchema.discriminator?.propertyName) {
|
|
728
727
|
schemaComposer.addDirective(directives_js_1.DiscriminatorDirective);
|
|
729
728
|
}
|
|
730
729
|
const directives = [];
|
|
731
|
-
if (
|
|
730
|
+
if (subSchema.examples?.length) {
|
|
732
731
|
schemaComposer.addDirective(directives_js_1.ExampleDirective);
|
|
733
732
|
for (const example of subSchema.examples) {
|
|
734
733
|
directives.push({
|
|
@@ -784,7 +783,6 @@ function getComposerFromJSONSchema(schema, logger) {
|
|
|
784
783
|
return subSchema;
|
|
785
784
|
},
|
|
786
785
|
leave(subSchemaAndTypeComposers, { path }) {
|
|
787
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
|
|
788
786
|
// const validateWithJSONSchema = getValidateFnForSchemaPath(ajv, path, schema);
|
|
789
787
|
const subSchemaOnly = {
|
|
790
788
|
...subSchemaAndTypeComposers,
|
|
@@ -877,7 +875,7 @@ function getComposerFromJSONSchema(schema, logger) {
|
|
|
877
875
|
}
|
|
878
876
|
}
|
|
879
877
|
}
|
|
880
|
-
if (
|
|
878
|
+
if (subSchemaAndTypeComposers.examples?.length) {
|
|
881
879
|
schemaComposer.addDirective(directives_js_1.ExampleDirective);
|
|
882
880
|
const directives = subSchemaAndTypeComposers.output.getDirectives() || [];
|
|
883
881
|
for (const example of subSchemaAndTypeComposers.examples) {
|
|
@@ -897,7 +895,7 @@ function getComposerFromJSONSchema(schema, logger) {
|
|
|
897
895
|
});
|
|
898
896
|
if (ableToUseGraphQLInputObjectType) {
|
|
899
897
|
subSchemaAndTypeComposers.input.addFields(inputFieldMap);
|
|
900
|
-
if (
|
|
898
|
+
if (subSchemaAndTypeComposers.examples?.length) {
|
|
901
899
|
schemaComposer.addDirective(directives_js_1.ExampleDirective);
|
|
902
900
|
const directives = subSchemaAndTypeComposers.input.getDirectives() || [];
|
|
903
901
|
for (const example of subSchemaAndTypeComposers.examples) {
|
|
@@ -982,7 +980,7 @@ function getComposerFromJSONSchema(schema, logger) {
|
|
|
982
980
|
// In case of conflict set it to JSON
|
|
983
981
|
// TODO: But instead we can convert that field into a union of all possible types
|
|
984
982
|
if (fieldMap[typeName]) {
|
|
985
|
-
const existingTypeName =
|
|
983
|
+
const existingTypeName = fieldMap[typeName]?.type?.getTypeName();
|
|
986
984
|
if (existingTypeName === 'JSON') {
|
|
987
985
|
schemaComposer.addDirective(directives_js_1.ResolveRootDirective);
|
|
988
986
|
fieldMap[typeName] = {
|
|
@@ -1047,7 +1045,7 @@ function getComposerFromJSONSchema(schema, logger) {
|
|
|
1047
1045
|
outputTypeComposer = outputTypeComposer.ofType;
|
|
1048
1046
|
}
|
|
1049
1047
|
outputTypeComposer.addFields(fieldMap);
|
|
1050
|
-
if (
|
|
1048
|
+
if (subSchemaAndTypeComposers.examples?.length) {
|
|
1051
1049
|
schemaComposer.addDirective(directives_js_1.ExampleDirective);
|
|
1052
1050
|
const directives = outputTypeComposer.getDirectives() || [];
|
|
1053
1051
|
for (const example of subSchemaAndTypeComposers.examples) {
|
|
@@ -1070,7 +1068,7 @@ function getComposerFromJSONSchema(schema, logger) {
|
|
|
1070
1068
|
}
|
|
1071
1069
|
if (ableToUseGraphQLInputObjectType) {
|
|
1072
1070
|
inputTypeComposer.addFields(inputFieldMap);
|
|
1073
|
-
if (
|
|
1071
|
+
if (subSchemaAndTypeComposers.examples?.length) {
|
|
1074
1072
|
schemaComposer.addDirective(directives_js_1.ExampleDirective);
|
|
1075
1073
|
const directives = inputTypeComposer.getDirectives() || [];
|
|
1076
1074
|
for (const example of subSchemaAndTypeComposers.examples) {
|
|
@@ -1112,10 +1110,9 @@ function getComposerFromJSONSchema(schema, logger) {
|
|
|
1112
1110
|
}
|
|
1113
1111
|
fieldMap[fieldName] = {
|
|
1114
1112
|
type: () => {
|
|
1115
|
-
var _a;
|
|
1116
1113
|
const typeComposers = subSchemaAndTypeComposers.properties[propertyName];
|
|
1117
1114
|
let nullable = true;
|
|
1118
|
-
if (
|
|
1115
|
+
if (subSchemaAndTypeComposers.required?.includes(propertyName)) {
|
|
1119
1116
|
nullable = false;
|
|
1120
1117
|
}
|
|
1121
1118
|
// Nullable has more priority
|
|
@@ -1133,7 +1130,7 @@ function getComposerFromJSONSchema(schema, logger) {
|
|
|
1133
1130
|
// Make sure you get the right property
|
|
1134
1131
|
directives: fieldDirectives,
|
|
1135
1132
|
description: subSchemaAndTypeComposers.properties[propertyName].description ||
|
|
1136
|
-
|
|
1133
|
+
subSchemaAndTypeComposers.properties[propertyName].output?.description,
|
|
1137
1134
|
};
|
|
1138
1135
|
const directives = [];
|
|
1139
1136
|
if (fieldName !== propertyName) {
|
|
@@ -1147,10 +1144,9 @@ function getComposerFromJSONSchema(schema, logger) {
|
|
|
1147
1144
|
}
|
|
1148
1145
|
inputFieldMap[fieldName] = {
|
|
1149
1146
|
type: () => {
|
|
1150
|
-
var _a, _b;
|
|
1151
1147
|
const typeComposers = subSchemaAndTypeComposers.properties[propertyName];
|
|
1152
1148
|
let nullable = true;
|
|
1153
|
-
if (
|
|
1149
|
+
if (subSchemaAndTypeComposers.required?.includes(propertyName)) {
|
|
1154
1150
|
nullable = false;
|
|
1155
1151
|
}
|
|
1156
1152
|
// Nullable has more priority
|
|
@@ -1163,14 +1159,14 @@ function getComposerFromJSONSchema(schema, logger) {
|
|
|
1163
1159
|
if (subSchemaAndTypeComposers.properties[propertyName].readOnly) {
|
|
1164
1160
|
nullable = true;
|
|
1165
1161
|
}
|
|
1166
|
-
return !nullable ?
|
|
1162
|
+
return !nullable ? typeComposers.input?.getTypeNonNull() : typeComposers.input;
|
|
1167
1163
|
},
|
|
1168
1164
|
directives,
|
|
1169
1165
|
description: subSchemaAndTypeComposers.properties[propertyName].description ||
|
|
1170
|
-
|
|
1171
|
-
defaultValue:
|
|
1172
|
-
|
|
1173
|
-
|
|
1166
|
+
subSchemaAndTypeComposers.properties[propertyName].input?.description,
|
|
1167
|
+
defaultValue: subSchemaAndTypeComposers.properties[propertyName]?.default ||
|
|
1168
|
+
subSchemaAndTypeComposers.properties[propertyName]?.extensions?.default ||
|
|
1169
|
+
subSchemaAndTypeComposers.properties[propertyName]?.input?.default,
|
|
1174
1170
|
};
|
|
1175
1171
|
}
|
|
1176
1172
|
}
|
|
@@ -1212,8 +1208,8 @@ function getComposerFromJSONSchema(schema, logger) {
|
|
|
1212
1208
|
}
|
|
1213
1209
|
else {
|
|
1214
1210
|
const typeComposer = schemaComposer.getAnyTC(graphql_scalars_1.GraphQLJSON);
|
|
1215
|
-
schemaComposer.delete(
|
|
1216
|
-
schemaComposer.delete(
|
|
1211
|
+
schemaComposer.delete(subSchemaAndTypeComposers.input?.getTypeName?.());
|
|
1212
|
+
schemaComposer.delete(subSchemaAndTypeComposers.output?.getTypeName?.());
|
|
1217
1213
|
return {
|
|
1218
1214
|
input: typeComposer,
|
|
1219
1215
|
output: typeComposer,
|
|
@@ -9,7 +9,7 @@ function getTypeResolverFromOutputTCs({ possibleTypes, discriminatorField, discr
|
|
|
9
9
|
}
|
|
10
10
|
else if (discriminatorField != null && data[discriminatorField]) {
|
|
11
11
|
const discriminatorValue = data[discriminatorField];
|
|
12
|
-
return
|
|
12
|
+
return discriminatorMapping?.[discriminatorValue] || discriminatorValue;
|
|
13
13
|
}
|
|
14
14
|
if (data.$statusCode && statusCodeTypeNameMap) {
|
|
15
15
|
const typeName = statusCodeTypeNameMap[data.$statusCode.toString()] || statusCodeTypeNameMap.default;
|
|
@@ -25,7 +25,7 @@ function getTypeResolverFromOutputTCs({ possibleTypes, discriminatorField, discr
|
|
|
25
25
|
if (fields.length === 1) {
|
|
26
26
|
const field = fields[0];
|
|
27
27
|
const directiveObjs = (0, utils_1.getDirective)(info.schema, field, 'resolveRoot');
|
|
28
|
-
if (directiveObjs
|
|
28
|
+
if (directiveObjs?.length) {
|
|
29
29
|
const fieldType = field.type;
|
|
30
30
|
if ('parseValue' in fieldType) {
|
|
31
31
|
try {
|
|
@@ -19,7 +19,6 @@ function getContainerTC(schemaComposer, output) {
|
|
|
19
19
|
}
|
|
20
20
|
exports.getContainerTC = getContainerTC;
|
|
21
21
|
function getUnionTypeComposers({ schemaComposer, typeComposersList, subSchemaAndTypeComposers, logger, }) {
|
|
22
|
-
var _a;
|
|
23
22
|
if (new Set(typeComposersList).size === 1) {
|
|
24
23
|
return typeComposersList[0];
|
|
25
24
|
}
|
|
@@ -57,7 +56,7 @@ function getUnionTypeComposers({ schemaComposer, typeComposersList, subSchemaAnd
|
|
|
57
56
|
const statusCodeOneOfIndexMapEntries = Object.entries(statusCodeOneOfIndexMap || {});
|
|
58
57
|
for (const outputTypeComposerIndex in outputTypeComposers) {
|
|
59
58
|
const outputTypeComposer = outputTypeComposers[outputTypeComposerIndex];
|
|
60
|
-
const statusCode =
|
|
59
|
+
const statusCode = statusCodeOneOfIndexMapEntries.find(([statusCode, index]) => index.toString() === outputTypeComposerIndex.toString())?.[0];
|
|
61
60
|
if ('getFields' in outputTypeComposer) {
|
|
62
61
|
if (statusCode != null) {
|
|
63
62
|
schemaComposer.addDirective(directives_js_1.StatusCodeTypeNameDirective);
|
|
@@ -5,7 +5,6 @@ const graphql_1 = require("graphql");
|
|
|
5
5
|
const utils_1 = require("@graphql-mesh/utils");
|
|
6
6
|
const utils_2 = require("@graphql-tools/utils");
|
|
7
7
|
function resolveDataByUnionInputType(data, type, schema) {
|
|
8
|
-
var _a;
|
|
9
8
|
if (data) {
|
|
10
9
|
if ((0, graphql_1.isListType)(type)) {
|
|
11
10
|
return (0, utils_2.asArray)(data).map(elem => resolveDataByUnionInputType(elem, type.ofType, schema));
|
|
@@ -15,7 +14,7 @@ function resolveDataByUnionInputType(data, type, schema) {
|
|
|
15
14
|
}
|
|
16
15
|
if ((0, graphql_1.isInputObjectType)(type)) {
|
|
17
16
|
const typeOneOfDirectives = (0, utils_2.getDirective)(schema, type, 'oneOf');
|
|
18
|
-
const isOneOf = typeOneOfDirectives
|
|
17
|
+
const isOneOf = typeOneOfDirectives?.length;
|
|
19
18
|
const fieldMap = type.getFields();
|
|
20
19
|
data = (0, utils_2.asArray)(data)[0];
|
|
21
20
|
for (const propertyName in data) {
|
|
@@ -29,7 +28,7 @@ function resolveDataByUnionInputType(data, type, schema) {
|
|
|
29
28
|
const fieldData = data[fieldName];
|
|
30
29
|
data[fieldName] = undefined;
|
|
31
30
|
const fieldResolveRootFieldDirectives = (0, utils_2.getDirective)(schema, field, 'resolveRootField');
|
|
32
|
-
const realFieldName =
|
|
31
|
+
const realFieldName = fieldResolveRootFieldDirectives?.[0]?.field || fieldName;
|
|
33
32
|
data[realFieldName] = resolveDataByUnionInputType(fieldData, field.type, schema);
|
|
34
33
|
}
|
|
35
34
|
}
|
|
@@ -15,7 +15,6 @@ const responseMetadataType = new GraphQLObjectType({
|
|
|
15
15
|
},
|
|
16
16
|
});
|
|
17
17
|
export async function addExecutionDirectivesToComposer(name, { schemaComposer, logger, operations, operationHeaders, endpoint, queryParams, queryStringOptions, }) {
|
|
18
|
-
var _a, _b;
|
|
19
18
|
schemaComposer.addDirective(GlobalOptionsDirective);
|
|
20
19
|
schemaComposer.Query.setDirectiveByName('globalOptions', JSON.parse(JSON.stringify({
|
|
21
20
|
sourceName: name,
|
|
@@ -91,12 +90,12 @@ ${operationConfig.description || ''}
|
|
|
91
90
|
targetField = schemaComposer.Query.getField(linkObj.fieldName);
|
|
92
91
|
fieldTypeName = 'Query';
|
|
93
92
|
}
|
|
94
|
-
catch
|
|
93
|
+
catch {
|
|
95
94
|
try {
|
|
96
95
|
targetField = schemaComposer.Mutation.getField(linkObj.fieldName);
|
|
97
96
|
fieldTypeName = 'Mutation';
|
|
98
97
|
}
|
|
99
|
-
catch
|
|
98
|
+
catch { }
|
|
100
99
|
}
|
|
101
100
|
if (!targetField) {
|
|
102
101
|
logger.debug(`Field ${linkObj.fieldName} not found in ${name} for link ${linkName}`);
|
|
@@ -150,7 +149,8 @@ ${operationConfig.description || ''}
|
|
|
150
149
|
const directives = unionOrSingleTC.getDirectives();
|
|
151
150
|
for (const directive of directives) {
|
|
152
151
|
if (directive.name === 'statusCodeOneOfIndex') {
|
|
153
|
-
statusCodeOneOfIndexMap[
|
|
152
|
+
statusCodeOneOfIndexMap[directive.args?.statusCode] = directive.args
|
|
153
|
+
?.oneOfIndex;
|
|
154
154
|
}
|
|
155
155
|
}
|
|
156
156
|
for (const statusCode in operationConfig.responseByStatusCode) {
|
|
@@ -25,7 +25,6 @@ export function addHTTPRootFieldResolver(schema, field, logger, globalFetch, { p
|
|
|
25
25
|
};
|
|
26
26
|
const returnNamedGraphQLType = getNamedType(field.type);
|
|
27
27
|
field.resolve = async (root, args, context, info) => {
|
|
28
|
-
var _a, _b;
|
|
29
28
|
const operationLogger = logger.child(`${info.parentType.name}.${info.fieldName}`);
|
|
30
29
|
operationLogger.debug(`=> Resolving`);
|
|
31
30
|
const interpolationData = { root, args, context, env: process.env };
|
|
@@ -90,13 +89,13 @@ export function addHTTPRootFieldResolver(schema, field, logger, globalFetch, { p
|
|
|
90
89
|
}
|
|
91
90
|
}
|
|
92
91
|
// Resolve union input
|
|
93
|
-
const input = (args.input = resolveDataByUnionInputType(args.input,
|
|
92
|
+
const input = (args.input = resolveDataByUnionInputType(args.input, field.args?.find(arg => arg.name === 'input')?.type, schema));
|
|
94
93
|
if (input != null) {
|
|
95
94
|
const [, contentType] = Object.entries(headers).find(([key]) => key.toLowerCase() === 'content-type') || [];
|
|
96
|
-
if (contentType
|
|
95
|
+
if (contentType?.startsWith('application/x-www-form-urlencoded')) {
|
|
97
96
|
requestInit.body = qsStringify(input, globalQueryStringOptions);
|
|
98
97
|
}
|
|
99
|
-
else if (contentType
|
|
98
|
+
else if (contentType?.startsWith('multipart/form-data')) {
|
|
100
99
|
delete headers['content-type'];
|
|
101
100
|
delete headers['Content-Type'];
|
|
102
101
|
const formData = new FormData();
|
|
@@ -154,7 +153,7 @@ export function addHTTPRootFieldResolver(schema, field, logger, globalFetch, { p
|
|
|
154
153
|
[queryParamName]: interpolatedQueryParam,
|
|
155
154
|
}, {
|
|
156
155
|
...globalQueryStringOptions,
|
|
157
|
-
...queryStringOptionsByParam
|
|
156
|
+
...queryStringOptionsByParam?.[queryParamName],
|
|
158
157
|
});
|
|
159
158
|
fullPath += fullPath.includes('?') ? '&' : '?';
|
|
160
159
|
fullPath += queryParamsString;
|
|
@@ -171,7 +170,7 @@ export function addHTTPRootFieldResolver(schema, field, logger, globalFetch, { p
|
|
|
171
170
|
}
|
|
172
171
|
const opts = {
|
|
173
172
|
...globalQueryStringOptions,
|
|
174
|
-
...queryStringOptionsByParam
|
|
173
|
+
...queryStringOptionsByParam?.[queryParamName],
|
|
175
174
|
};
|
|
176
175
|
let queryParamObj = argValue;
|
|
177
176
|
if (Array.isArray(argValue) || !(typeof argValue === 'object' && opts.destructObject)) {
|
|
@@ -186,7 +185,7 @@ export function addHTTPRootFieldResolver(schema, field, logger, globalFetch, { p
|
|
|
186
185
|
}
|
|
187
186
|
}
|
|
188
187
|
operationLogger.debug(`=> Fetching `, fullPath, `=>`, requestInit);
|
|
189
|
-
const fetch =
|
|
188
|
+
const fetch = context?.fetch || globalFetch;
|
|
190
189
|
if (!fetch) {
|
|
191
190
|
return createGraphQLError(`You should have fetch defined in either the config or the context!`, {
|
|
192
191
|
extensions: {
|
|
@@ -337,11 +336,10 @@ export function addHTTPRootFieldResolver(schema, field, logger, globalFetch, { p
|
|
|
337
336
|
case 'path':
|
|
338
337
|
return new Proxy(args, {
|
|
339
338
|
get(_, prop) {
|
|
340
|
-
|
|
341
|
-
return args[prop] || ((_a = args.input) === null || _a === void 0 ? void 0 : _a[prop]) || (obj === null || obj === void 0 ? void 0 : obj[prop]);
|
|
339
|
+
return args[prop] || args.input?.[prop] || obj?.[prop];
|
|
342
340
|
},
|
|
343
341
|
has(_, prop) {
|
|
344
|
-
return prop in args || (args.input && prop in args.input) ||
|
|
342
|
+
return prop in args || (args.input && prop in args.input) || obj?.[prop];
|
|
345
343
|
},
|
|
346
344
|
});
|
|
347
345
|
case 'header':
|
|
@@ -367,11 +365,10 @@ export function addHTTPRootFieldResolver(schema, field, logger, globalFetch, { p
|
|
|
367
365
|
case 'path':
|
|
368
366
|
return new Proxy(args, {
|
|
369
367
|
get(_, prop) {
|
|
370
|
-
|
|
371
|
-
return args[prop] || ((_a = args.input) === null || _a === void 0 ? void 0 : _a[prop]) || (obj === null || obj === void 0 ? void 0 : obj[prop]);
|
|
368
|
+
return args[prop] || args.input?.[prop] || obj?.[prop];
|
|
372
369
|
},
|
|
373
370
|
has(_, prop) {
|
|
374
|
-
return prop in args || (args.input && prop in args.input) ||
|
|
371
|
+
return prop in args || (args.input && prop in args.input) || obj?.[prop];
|
|
375
372
|
},
|
|
376
373
|
});
|
|
377
374
|
}
|
package/esm/directives.js
CHANGED
|
@@ -143,7 +143,7 @@ export const PubSubOperationDirective = new GraphQLDirective({
|
|
|
143
143
|
export function processPubSubOperationAnnotations({ field, globalPubsub, pubsubTopic, logger, }) {
|
|
144
144
|
field.subscribe = (root, args, context, info) => {
|
|
145
145
|
const operationLogger = logger.child(`${info.parentType.name}.${field.name}`);
|
|
146
|
-
const pubsub =
|
|
146
|
+
const pubsub = context?.pubsub || globalPubsub;
|
|
147
147
|
if (!pubsub) {
|
|
148
148
|
return createGraphQLError(`You should have PubSub defined in either the config or the context!`);
|
|
149
149
|
}
|
|
@@ -336,7 +336,7 @@ function linkResolver({ linkObjArgs, targetTypeName, targetFieldName }, { root,
|
|
|
336
336
|
}
|
|
337
337
|
function getLinkResolverMap(schema, field) {
|
|
338
338
|
const parentFieldLinkResolverDirectives = getDirective(schema, field, 'linkResolver');
|
|
339
|
-
if (parentFieldLinkResolverDirectives
|
|
339
|
+
if (parentFieldLinkResolverDirectives?.length) {
|
|
340
340
|
const linkResolverMap = parentFieldLinkResolverDirectives[0].linkResolverMap;
|
|
341
341
|
if (linkResolverMap) {
|
|
342
342
|
return linkResolverMap;
|
|
@@ -410,10 +410,10 @@ export function processDirectives({ schema, globalFetch, logger, pubsub, ...extr
|
|
|
410
410
|
for (const typeName in typeMap) {
|
|
411
411
|
const type = typeMap[typeName];
|
|
412
412
|
const exampleAnnotations = getDirective(schema, type, 'example');
|
|
413
|
-
if (exampleAnnotations
|
|
413
|
+
if (exampleAnnotations?.length) {
|
|
414
414
|
const examples = [];
|
|
415
415
|
for (const exampleAnnotation of exampleAnnotations) {
|
|
416
|
-
if (exampleAnnotation
|
|
416
|
+
if (exampleAnnotation?.value) {
|
|
417
417
|
examples.push(exampleAnnotation.value);
|
|
418
418
|
}
|
|
419
419
|
}
|
|
@@ -19,7 +19,6 @@ export function getComposerFromJSONSchema(schema, logger) {
|
|
|
19
19
|
};
|
|
20
20
|
return visitJSONSchema(schema, {
|
|
21
21
|
enter(subSchema, { path, visitedSubschemaResultMap }) {
|
|
22
|
-
var _a, _b, _c, _d, _e, _f;
|
|
23
22
|
if (typeof subSchema === 'boolean' || subSchema.title === 'Any') {
|
|
24
23
|
const typeComposer = schemaComposer.getAnyTC(GraphQLJSON);
|
|
25
24
|
return subSchema
|
|
@@ -192,7 +191,7 @@ export function getComposerFromJSONSchema(schema, logger) {
|
|
|
192
191
|
schemaComposer.addDirective(EnumDirective);
|
|
193
192
|
// Falsy values are ignored by GraphQL
|
|
194
193
|
// eslint-disable-next-line no-unneeded-ternary
|
|
195
|
-
const enumValue = value ? value : value
|
|
194
|
+
const enumValue = value ? value : value?.toString();
|
|
196
195
|
const directives = [];
|
|
197
196
|
if (enumValue !== enumKey) {
|
|
198
197
|
directives.push({
|
|
@@ -208,7 +207,7 @@ export function getComposerFromJSONSchema(schema, logger) {
|
|
|
208
207
|
};
|
|
209
208
|
}
|
|
210
209
|
const directives = [];
|
|
211
|
-
if (
|
|
210
|
+
if (subSchema.examples?.length) {
|
|
212
211
|
schemaComposer.addDirective(ExampleDirective);
|
|
213
212
|
for (const example of subSchema.examples) {
|
|
214
213
|
directives.push({
|
|
@@ -641,14 +640,14 @@ export function getComposerFromJSONSchema(schema, logger) {
|
|
|
641
640
|
});
|
|
642
641
|
const extensions = {};
|
|
643
642
|
const directives = [];
|
|
644
|
-
if (
|
|
643
|
+
if (subSchema.$comment?.startsWith('statusCodeOneOfIndexMap:')) {
|
|
645
644
|
const statusCodeOneOfIndexMapStr = subSchema.$comment.replace('statusCodeOneOfIndexMap:', '');
|
|
646
645
|
const statusCodeOneOfIndexMap = JSON.parse(statusCodeOneOfIndexMapStr);
|
|
647
646
|
if (statusCodeOneOfIndexMap) {
|
|
648
647
|
extensions.statusCodeOneOfIndexMap = statusCodeOneOfIndexMap;
|
|
649
648
|
}
|
|
650
649
|
}
|
|
651
|
-
if (
|
|
650
|
+
if (subSchema.discriminator?.propertyName) {
|
|
652
651
|
schemaComposer.addDirective(DiscriminatorDirective);
|
|
653
652
|
const mappingByName = {};
|
|
654
653
|
for (const discriminatorValue in subSchema.discriminator.mapping) {
|
|
@@ -710,7 +709,7 @@ export function getComposerFromJSONSchema(schema, logger) {
|
|
|
710
709
|
default: subSchema.default,
|
|
711
710
|
},
|
|
712
711
|
};
|
|
713
|
-
if (
|
|
712
|
+
if (subSchema.examples?.length) {
|
|
714
713
|
schemaComposer.addDirective(ExampleDirective);
|
|
715
714
|
for (const example of subSchema.examples) {
|
|
716
715
|
config.directives.push({
|
|
@@ -721,11 +720,11 @@ export function getComposerFromJSONSchema(schema, logger) {
|
|
|
721
720
|
});
|
|
722
721
|
}
|
|
723
722
|
}
|
|
724
|
-
if (
|
|
723
|
+
if (subSchema.discriminator?.propertyName) {
|
|
725
724
|
schemaComposer.addDirective(DiscriminatorDirective);
|
|
726
725
|
}
|
|
727
726
|
const directives = [];
|
|
728
|
-
if (
|
|
727
|
+
if (subSchema.examples?.length) {
|
|
729
728
|
schemaComposer.addDirective(ExampleDirective);
|
|
730
729
|
for (const example of subSchema.examples) {
|
|
731
730
|
directives.push({
|
|
@@ -781,7 +780,6 @@ export function getComposerFromJSONSchema(schema, logger) {
|
|
|
781
780
|
return subSchema;
|
|
782
781
|
},
|
|
783
782
|
leave(subSchemaAndTypeComposers, { path }) {
|
|
784
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
|
|
785
783
|
// const validateWithJSONSchema = getValidateFnForSchemaPath(ajv, path, schema);
|
|
786
784
|
const subSchemaOnly = {
|
|
787
785
|
...subSchemaAndTypeComposers,
|
|
@@ -874,7 +872,7 @@ export function getComposerFromJSONSchema(schema, logger) {
|
|
|
874
872
|
}
|
|
875
873
|
}
|
|
876
874
|
}
|
|
877
|
-
if (
|
|
875
|
+
if (subSchemaAndTypeComposers.examples?.length) {
|
|
878
876
|
schemaComposer.addDirective(ExampleDirective);
|
|
879
877
|
const directives = subSchemaAndTypeComposers.output.getDirectives() || [];
|
|
880
878
|
for (const example of subSchemaAndTypeComposers.examples) {
|
|
@@ -894,7 +892,7 @@ export function getComposerFromJSONSchema(schema, logger) {
|
|
|
894
892
|
});
|
|
895
893
|
if (ableToUseGraphQLInputObjectType) {
|
|
896
894
|
subSchemaAndTypeComposers.input.addFields(inputFieldMap);
|
|
897
|
-
if (
|
|
895
|
+
if (subSchemaAndTypeComposers.examples?.length) {
|
|
898
896
|
schemaComposer.addDirective(ExampleDirective);
|
|
899
897
|
const directives = subSchemaAndTypeComposers.input.getDirectives() || [];
|
|
900
898
|
for (const example of subSchemaAndTypeComposers.examples) {
|
|
@@ -979,7 +977,7 @@ export function getComposerFromJSONSchema(schema, logger) {
|
|
|
979
977
|
// In case of conflict set it to JSON
|
|
980
978
|
// TODO: But instead we can convert that field into a union of all possible types
|
|
981
979
|
if (fieldMap[typeName]) {
|
|
982
|
-
const existingTypeName =
|
|
980
|
+
const existingTypeName = fieldMap[typeName]?.type?.getTypeName();
|
|
983
981
|
if (existingTypeName === 'JSON') {
|
|
984
982
|
schemaComposer.addDirective(ResolveRootDirective);
|
|
985
983
|
fieldMap[typeName] = {
|
|
@@ -1044,7 +1042,7 @@ export function getComposerFromJSONSchema(schema, logger) {
|
|
|
1044
1042
|
outputTypeComposer = outputTypeComposer.ofType;
|
|
1045
1043
|
}
|
|
1046
1044
|
outputTypeComposer.addFields(fieldMap);
|
|
1047
|
-
if (
|
|
1045
|
+
if (subSchemaAndTypeComposers.examples?.length) {
|
|
1048
1046
|
schemaComposer.addDirective(ExampleDirective);
|
|
1049
1047
|
const directives = outputTypeComposer.getDirectives() || [];
|
|
1050
1048
|
for (const example of subSchemaAndTypeComposers.examples) {
|
|
@@ -1067,7 +1065,7 @@ export function getComposerFromJSONSchema(schema, logger) {
|
|
|
1067
1065
|
}
|
|
1068
1066
|
if (ableToUseGraphQLInputObjectType) {
|
|
1069
1067
|
inputTypeComposer.addFields(inputFieldMap);
|
|
1070
|
-
if (
|
|
1068
|
+
if (subSchemaAndTypeComposers.examples?.length) {
|
|
1071
1069
|
schemaComposer.addDirective(ExampleDirective);
|
|
1072
1070
|
const directives = inputTypeComposer.getDirectives() || [];
|
|
1073
1071
|
for (const example of subSchemaAndTypeComposers.examples) {
|
|
@@ -1109,10 +1107,9 @@ export function getComposerFromJSONSchema(schema, logger) {
|
|
|
1109
1107
|
}
|
|
1110
1108
|
fieldMap[fieldName] = {
|
|
1111
1109
|
type: () => {
|
|
1112
|
-
var _a;
|
|
1113
1110
|
const typeComposers = subSchemaAndTypeComposers.properties[propertyName];
|
|
1114
1111
|
let nullable = true;
|
|
1115
|
-
if (
|
|
1112
|
+
if (subSchemaAndTypeComposers.required?.includes(propertyName)) {
|
|
1116
1113
|
nullable = false;
|
|
1117
1114
|
}
|
|
1118
1115
|
// Nullable has more priority
|
|
@@ -1130,7 +1127,7 @@ export function getComposerFromJSONSchema(schema, logger) {
|
|
|
1130
1127
|
// Make sure you get the right property
|
|
1131
1128
|
directives: fieldDirectives,
|
|
1132
1129
|
description: subSchemaAndTypeComposers.properties[propertyName].description ||
|
|
1133
|
-
|
|
1130
|
+
subSchemaAndTypeComposers.properties[propertyName].output?.description,
|
|
1134
1131
|
};
|
|
1135
1132
|
const directives = [];
|
|
1136
1133
|
if (fieldName !== propertyName) {
|
|
@@ -1144,10 +1141,9 @@ export function getComposerFromJSONSchema(schema, logger) {
|
|
|
1144
1141
|
}
|
|
1145
1142
|
inputFieldMap[fieldName] = {
|
|
1146
1143
|
type: () => {
|
|
1147
|
-
var _a, _b;
|
|
1148
1144
|
const typeComposers = subSchemaAndTypeComposers.properties[propertyName];
|
|
1149
1145
|
let nullable = true;
|
|
1150
|
-
if (
|
|
1146
|
+
if (subSchemaAndTypeComposers.required?.includes(propertyName)) {
|
|
1151
1147
|
nullable = false;
|
|
1152
1148
|
}
|
|
1153
1149
|
// Nullable has more priority
|
|
@@ -1160,14 +1156,14 @@ export function getComposerFromJSONSchema(schema, logger) {
|
|
|
1160
1156
|
if (subSchemaAndTypeComposers.properties[propertyName].readOnly) {
|
|
1161
1157
|
nullable = true;
|
|
1162
1158
|
}
|
|
1163
|
-
return !nullable ?
|
|
1159
|
+
return !nullable ? typeComposers.input?.getTypeNonNull() : typeComposers.input;
|
|
1164
1160
|
},
|
|
1165
1161
|
directives,
|
|
1166
1162
|
description: subSchemaAndTypeComposers.properties[propertyName].description ||
|
|
1167
|
-
|
|
1168
|
-
defaultValue:
|
|
1169
|
-
|
|
1170
|
-
|
|
1163
|
+
subSchemaAndTypeComposers.properties[propertyName].input?.description,
|
|
1164
|
+
defaultValue: subSchemaAndTypeComposers.properties[propertyName]?.default ||
|
|
1165
|
+
subSchemaAndTypeComposers.properties[propertyName]?.extensions?.default ||
|
|
1166
|
+
subSchemaAndTypeComposers.properties[propertyName]?.input?.default,
|
|
1171
1167
|
};
|
|
1172
1168
|
}
|
|
1173
1169
|
}
|
|
@@ -1209,8 +1205,8 @@ export function getComposerFromJSONSchema(schema, logger) {
|
|
|
1209
1205
|
}
|
|
1210
1206
|
else {
|
|
1211
1207
|
const typeComposer = schemaComposer.getAnyTC(GraphQLJSON);
|
|
1212
|
-
schemaComposer.delete(
|
|
1213
|
-
schemaComposer.delete(
|
|
1208
|
+
schemaComposer.delete(subSchemaAndTypeComposers.input?.getTypeName?.());
|
|
1209
|
+
schemaComposer.delete(subSchemaAndTypeComposers.output?.getTypeName?.());
|
|
1214
1210
|
return {
|
|
1215
1211
|
input: typeComposer,
|
|
1216
1212
|
output: typeComposer,
|
|
@@ -6,7 +6,7 @@ export function getTypeResolverFromOutputTCs({ possibleTypes, discriminatorField
|
|
|
6
6
|
}
|
|
7
7
|
else if (discriminatorField != null && data[discriminatorField]) {
|
|
8
8
|
const discriminatorValue = data[discriminatorField];
|
|
9
|
-
return
|
|
9
|
+
return discriminatorMapping?.[discriminatorValue] || discriminatorValue;
|
|
10
10
|
}
|
|
11
11
|
if (data.$statusCode && statusCodeTypeNameMap) {
|
|
12
12
|
const typeName = statusCodeTypeNameMap[data.$statusCode.toString()] || statusCodeTypeNameMap.default;
|
|
@@ -22,7 +22,7 @@ export function getTypeResolverFromOutputTCs({ possibleTypes, discriminatorField
|
|
|
22
22
|
if (fields.length === 1) {
|
|
23
23
|
const field = fields[0];
|
|
24
24
|
const directiveObjs = getDirective(info.schema, field, 'resolveRoot');
|
|
25
|
-
if (directiveObjs
|
|
25
|
+
if (directiveObjs?.length) {
|
|
26
26
|
const fieldType = field.type;
|
|
27
27
|
if ('parseValue' in fieldType) {
|
|
28
28
|
try {
|
|
@@ -15,7 +15,6 @@ export function getContainerTC(schemaComposer, output) {
|
|
|
15
15
|
}));
|
|
16
16
|
}
|
|
17
17
|
export function getUnionTypeComposers({ schemaComposer, typeComposersList, subSchemaAndTypeComposers, logger, }) {
|
|
18
|
-
var _a;
|
|
19
18
|
if (new Set(typeComposersList).size === 1) {
|
|
20
19
|
return typeComposersList[0];
|
|
21
20
|
}
|
|
@@ -53,7 +52,7 @@ export function getUnionTypeComposers({ schemaComposer, typeComposersList, subSc
|
|
|
53
52
|
const statusCodeOneOfIndexMapEntries = Object.entries(statusCodeOneOfIndexMap || {});
|
|
54
53
|
for (const outputTypeComposerIndex in outputTypeComposers) {
|
|
55
54
|
const outputTypeComposer = outputTypeComposers[outputTypeComposerIndex];
|
|
56
|
-
const statusCode =
|
|
55
|
+
const statusCode = statusCodeOneOfIndexMapEntries.find(([statusCode, index]) => index.toString() === outputTypeComposerIndex.toString())?.[0];
|
|
57
56
|
if ('getFields' in outputTypeComposer) {
|
|
58
57
|
if (statusCode != null) {
|
|
59
58
|
schemaComposer.addDirective(StatusCodeTypeNameDirective);
|
|
@@ -2,7 +2,6 @@ import { isInputObjectType, isListType, isNonNullType, } from 'graphql';
|
|
|
2
2
|
import { sanitizeNameForGraphQL } from '@graphql-mesh/utils';
|
|
3
3
|
import { asArray, getDirective } from '@graphql-tools/utils';
|
|
4
4
|
export function resolveDataByUnionInputType(data, type, schema) {
|
|
5
|
-
var _a;
|
|
6
5
|
if (data) {
|
|
7
6
|
if (isListType(type)) {
|
|
8
7
|
return asArray(data).map(elem => resolveDataByUnionInputType(elem, type.ofType, schema));
|
|
@@ -12,7 +11,7 @@ export function resolveDataByUnionInputType(data, type, schema) {
|
|
|
12
11
|
}
|
|
13
12
|
if (isInputObjectType(type)) {
|
|
14
13
|
const typeOneOfDirectives = getDirective(schema, type, 'oneOf');
|
|
15
|
-
const isOneOf = typeOneOfDirectives
|
|
14
|
+
const isOneOf = typeOneOfDirectives?.length;
|
|
16
15
|
const fieldMap = type.getFields();
|
|
17
16
|
data = asArray(data)[0];
|
|
18
17
|
for (const propertyName in data) {
|
|
@@ -26,7 +25,7 @@ export function resolveDataByUnionInputType(data, type, schema) {
|
|
|
26
25
|
const fieldData = data[fieldName];
|
|
27
26
|
data[fieldName] = undefined;
|
|
28
27
|
const fieldResolveRootFieldDirectives = getDirective(schema, field, 'resolveRootField');
|
|
29
|
-
const realFieldName =
|
|
28
|
+
const realFieldName = fieldResolveRootFieldDirectives?.[0]?.field || fieldName;
|
|
30
29
|
data[realFieldName] = resolveDataByUnionInputType(fieldData, field.type, schema);
|
|
31
30
|
}
|
|
32
31
|
}
|
package/package.json
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@omnigraph/json-schema",
|
|
3
|
-
"version": "1.0.0-alpha-
|
|
3
|
+
"version": "1.0.0-alpha-20230523155104-df277a22b",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"peerDependencies": {
|
|
6
|
-
"@graphql-mesh/cross-helpers": "0.4.0-alpha-
|
|
7
|
-
"@graphql-mesh/types": "1.0.0-alpha-
|
|
8
|
-
"@graphql-mesh/utils": "1.0.0-alpha-
|
|
9
|
-
"@graphql-tools/utils": "^9.2.1
|
|
6
|
+
"@graphql-mesh/cross-helpers": "0.4.0-alpha-20230523155104-df277a22b",
|
|
7
|
+
"@graphql-mesh/types": "1.0.0-alpha-20230523155104-df277a22b",
|
|
8
|
+
"@graphql-mesh/utils": "1.0.0-alpha-20230523155104-df277a22b",
|
|
9
|
+
"@graphql-tools/utils": "^9.2.1",
|
|
10
10
|
"graphql": "*",
|
|
11
11
|
"tslib": "^2.4.0"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@graphql-mesh/string-interpolation": "0.5.0-alpha-
|
|
14
|
+
"@graphql-mesh/string-interpolation": "0.5.0-alpha-20230523155104-df277a22b",
|
|
15
15
|
"@json-schema-tools/meta-schema": "1.7.0",
|
|
16
|
-
"@whatwg-node/fetch": "^0.
|
|
16
|
+
"@whatwg-node/fetch": "^0.9.0",
|
|
17
17
|
"ajv": "8.12.0",
|
|
18
18
|
"ajv-formats": "2.1.1",
|
|
19
19
|
"dset": "3.1.2",
|
|
20
20
|
"graphql-compose": "9.0.10",
|
|
21
21
|
"graphql-scalars": "^1.20.4",
|
|
22
|
-
"json-machete": "1.0.0-alpha-
|
|
22
|
+
"json-machete": "1.0.0-alpha-20230523155104-df277a22b",
|
|
23
23
|
"pascal-case": "3.1.2",
|
|
24
24
|
"qs": "6.11.2",
|
|
25
25
|
"to-json-schema": "0.2.5",
|
|
@@ -31,6 +31,9 @@
|
|
|
31
31
|
"directory": "packages/loaders/json-schema"
|
|
32
32
|
},
|
|
33
33
|
"license": "MIT",
|
|
34
|
+
"engines": {
|
|
35
|
+
"node": ">=16.0.0"
|
|
36
|
+
},
|
|
34
37
|
"main": "cjs/index.js",
|
|
35
38
|
"module": "esm/index.js",
|
|
36
39
|
"typings": "typings/index.d.ts",
|