@omnigraph/json-schema 1.0.0-alpha-20230523155104-df277a22b → 1.0.0-alpha-20230523160518-5443a1139

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