@omnigraph/json-schema 1.0.0-alpha-3fc47d119.0 → 1.0.0-alpha-20220804093904-8e2e41f7f

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/index.js CHANGED
@@ -303,8 +303,10 @@ function resolveDataByUnionInputType(data, type, schemaComposer) {
303
303
  const resolvedData = resolveDataByUnionInputType(data[fieldName], field.type, schemaComposer);
304
304
  return resolvedData;
305
305
  }
306
+ const fieldData = data[fieldName];
307
+ data[fieldName] = undefined;
306
308
  const realFieldName = ((_a = field.extensions) === null || _a === void 0 ? void 0 : _a.propertyName) || fieldName;
307
- data[realFieldName] = resolveDataByUnionInputType(data[fieldName], field.type, schemaComposer);
309
+ data[realFieldName] = resolveDataByUnionInputType(fieldData, field.type, schemaComposer);
308
310
  }
309
311
  }
310
312
  }
@@ -824,7 +826,7 @@ function getTypeResolverFromOutputTCs(ajv, outputTypeComposers, statusCodeOneOfI
824
826
  const ONE_OF_DEFINITION = /* GraphQL */ `
825
827
  directive @oneOf on INPUT_OBJECT | FIELD_DEFINITION
826
828
  `;
827
- function getUnionTypeComposers({ schemaComposer, ajv, typeComposersList, subSchema, generateInterfaceFromSharedFields, statusCodeOneOfIndexMap, }) {
829
+ function getUnionTypeComposers({ schemaComposer, ajv, typeComposersList, subSchemaAndTypeComposers, }) {
828
830
  if (typeComposersList.length === 1) {
829
831
  return typeComposersList[0];
830
832
  }
@@ -848,97 +850,25 @@ function getUnionTypeComposers({ schemaComposer, ajv, typeComposersList, subSche
848
850
  type: input,
849
851
  };
850
852
  });
851
- const input = schemaComposer.createInputTC({
852
- name: getValidTypeName({
853
- schemaComposer,
854
- isInput: true,
855
- subSchema,
856
- }),
857
- description: subSchema.description,
858
- fields: unionInputFields,
859
- });
853
+ subSchemaAndTypeComposers.input.addFields(unionInputFields);
860
854
  if (!schemaComposer.hasDirective('oneOf')) {
861
855
  schemaComposer.addTypeDefs(ONE_OF_DEFINITION);
862
856
  }
863
- input.setDirectives([
864
- {
865
- name: 'oneOf',
866
- args: {},
867
- },
868
- ]);
869
- let output;
870
- let sharedFields;
871
- if (generateInterfaceFromSharedFields) {
872
- for (const typeComposer of outputTypeComposers) {
873
- const fieldMap = typeComposer.getFields();
874
- if (!sharedFields) {
875
- sharedFields = { ...fieldMap };
876
- }
877
- else {
878
- for (const potentialSharedFieldName in sharedFields) {
879
- if (!(potentialSharedFieldName in fieldMap &&
880
- fieldMap[potentialSharedFieldName].type.getTypeName() ===
881
- sharedFields[potentialSharedFieldName].type.getTypeName())) {
882
- sharedFields[potentialSharedFieldName] = undefined;
883
- delete sharedFields[potentialSharedFieldName];
884
- }
885
- }
886
- }
857
+ const resolveType = getTypeResolverFromOutputTCs(ajv, outputTypeComposers, subSchemaAndTypeComposers.output.getExtension('statusCodeOneOfIndexMap'));
858
+ subSchemaAndTypeComposers.output.setResolveType(resolveType);
859
+ for (const outputTypeComposer of outputTypeComposers) {
860
+ if ('getFields' in outputTypeComposer) {
861
+ subSchemaAndTypeComposers.output.addType(outputTypeComposer);
887
862
  }
888
- }
889
- const resolveType = getTypeResolverFromOutputTCs(ajv, outputTypeComposers, statusCodeOneOfIndexMap);
890
- if (sharedFields && Object.keys(sharedFields).length > 0) {
891
- output = schemaComposer.createInterfaceTC({
892
- name: getValidTypeName({
893
- schemaComposer,
894
- isInput: false,
895
- subSchema,
896
- }),
897
- description: subSchema.description,
898
- fields: sharedFields,
899
- resolveType,
900
- extensions: {
901
- statusCodeOneOfIndexMap,
902
- },
903
- });
904
- for (const typeComposer of outputTypeComposers) {
905
- typeComposer.addInterface(output);
906
- // GraphQL removes implementations
907
- schemaComposer.addSchemaMustHaveType(typeComposer);
863
+ else {
864
+ for (const possibleType of outputTypeComposer.getTypes()) {
865
+ subSchemaAndTypeComposers.output.addType(possibleType);
866
+ }
908
867
  }
909
868
  }
910
- else {
911
- // If no shared fields found
912
- output = schemaComposer.createUnionTC({
913
- name: getValidTypeName({
914
- schemaComposer,
915
- isInput: false,
916
- subSchema,
917
- }),
918
- description: subSchema.description,
919
- types: () => {
920
- const possibleTypes = [];
921
- for (const outputTypeComposer of outputTypeComposers) {
922
- if ('getFields' in outputTypeComposer) {
923
- possibleTypes.push(outputTypeComposer);
924
- }
925
- else {
926
- for (const possibleType of outputTypeComposer.getTypes()) {
927
- possibleTypes.push(possibleType);
928
- }
929
- }
930
- }
931
- return possibleTypes;
932
- },
933
- resolveType,
934
- extensions: {
935
- statusCodeOneOfIndexMap,
936
- },
937
- });
938
- }
939
869
  return {
940
- input,
941
- output,
870
+ input: subSchemaAndTypeComposers.input,
871
+ output: subSchemaAndTypeComposers.output,
942
872
  };
943
873
  }
944
874
 
@@ -1026,18 +956,22 @@ const GraphQLFile = new graphql.GraphQLScalarType({
1026
956
  codegenScalarType: 'File',
1027
957
  },
1028
958
  });
1029
- function getComposerFromJSONSchema(schema, logger, generateInterfaceFromSharedFields = false) {
959
+ function getComposerFromJSONSchema(schema, logger) {
1030
960
  const schemaComposer = new graphqlCompose.SchemaComposer();
1031
961
  const ajv = new Ajv({
1032
962
  strict: false,
1033
963
  });
1034
964
  addFormats(ajv);
1035
965
  const formatScalarMap = getJSONSchemaStringFormatScalarMap(ajv);
1036
- const futureTasks = new Set();
1037
- return jsonMachete.visitJSONSchema(schema, function mutateFn(subSchema, { path }) {
1038
- logger === null || logger === void 0 ? void 0 : logger.debug(`Processing ${path} for GraphQL Schema`);
1039
- const getTypeComposer = () => {
1040
- var _a, _b, _c, _d, _e;
966
+ const rootInputTypeNameComposerMap = {
967
+ QueryInput: () => schemaComposer.Query,
968
+ MutationInput: () => schemaComposer.Mutation,
969
+ SubscriptionInput: () => schemaComposer.Subscription,
970
+ };
971
+ return jsonMachete.visitJSONSchema(schema, {
972
+ enter(subSchema, { path, visitedSubschemaResultMap }) {
973
+ var _a;
974
+ logger === null || logger === void 0 ? void 0 : logger.debug(`Entering ${path} for GraphQL Schema`);
1041
975
  if (typeof subSchema === 'boolean') {
1042
976
  const typeComposer = schemaComposer.getAnyTC(graphqlScalars.GraphQLJSON);
1043
977
  return subSchema
@@ -1063,6 +997,7 @@ function getComposerFromJSONSchema(schema, logger, generateInterfaceFromSharedFi
1063
997
  return {
1064
998
  input: typeComposer,
1065
999
  output: typeComposer,
1000
+ nullable: subSchema.nullable,
1066
1001
  };
1067
1002
  }
1068
1003
  if (subSchema.const) {
@@ -1083,6 +1018,7 @@ function getComposerFromJSONSchema(schema, logger, generateInterfaceFromSharedFi
1083
1018
  return {
1084
1019
  input: typeComposer,
1085
1020
  output: typeComposer,
1021
+ nullable: subSchema.nullable,
1086
1022
  };
1087
1023
  }
1088
1024
  if (subSchema.enum && subSchema.type !== 'boolean') {
@@ -1117,234 +1053,34 @@ function getComposerFromJSONSchema(schema, logger, generateInterfaceFromSharedFi
1117
1053
  return {
1118
1054
  input: typeComposer,
1119
1055
  output: typeComposer,
1056
+ nullable: subSchema.nullable,
1120
1057
  };
1121
1058
  }
1122
- if (subSchema.oneOf && !subSchema.properties) {
1123
- let statusCodeOneOfIndexMap;
1124
- if ((_a = subSchema.$comment) === null || _a === void 0 ? void 0 : _a.startsWith('statusCodeOneOfIndexMap:')) {
1125
- const statusCodeOneOfIndexMapStr = subSchema.$comment.replace('statusCodeOneOfIndexMap:', '');
1126
- statusCodeOneOfIndexMap = JSON.parse(statusCodeOneOfIndexMapStr);
1059
+ if (Array.isArray(subSchema.type)) {
1060
+ const validTypes = subSchema.type.filter((typeName) => typeName !== 'null');
1061
+ if (validTypes.length === 1) {
1062
+ subSchema.type = validTypes[0];
1063
+ // continue with the single type
1127
1064
  }
1128
- const isPlural = subSchema.oneOf.some(({ output }) => 'ofType' in output);
1129
- if (isPlural) {
1130
- const { input, output } = getUnionTypeComposers({
1131
- schemaComposer,
1132
- ajv,
1133
- typeComposersList: subSchema.oneOf.map(({ input, output }) => ({
1134
- input: input.ofType || input,
1135
- output: output.ofType || output,
1136
- })),
1137
- subSchema,
1138
- generateInterfaceFromSharedFields,
1139
- statusCodeOneOfIndexMap,
1140
- });
1065
+ else if (validTypes.length === 0) {
1066
+ const typeComposer = schemaComposer.getAnyTC(GraphQLVoid);
1141
1067
  return {
1142
- input: input.getTypePlural(),
1143
- output: output.getTypePlural(),
1068
+ input: typeComposer,
1069
+ output: typeComposer,
1070
+ nullable: subSchema.nullable,
1144
1071
  };
1145
1072
  }
1146
- return getUnionTypeComposers({
1147
- schemaComposer,
1148
- ajv,
1149
- typeComposersList: subSchema.oneOf,
1150
- subSchema,
1151
- generateInterfaceFromSharedFields,
1152
- statusCodeOneOfIndexMap,
1153
- });
1154
- }
1155
- if (subSchema.allOf && !subSchema.properties) {
1156
- const inputFieldMap = {};
1157
- const fieldMap = {};
1158
- let ableToUseGraphQLInputObjectType = true;
1159
- for (const maybeTypeComposers of subSchema.allOf) {
1160
- const { input: inputTypeComposer, output: outputTypeComposer } = maybeTypeComposers;
1161
- if (inputTypeComposer instanceof graphqlCompose.ScalarTypeComposer) {
1162
- ableToUseGraphQLInputObjectType = false;
1163
- }
1164
- else {
1165
- const inputTypeElemFieldMap = inputTypeComposer.getFields();
1166
- for (const fieldName in inputTypeElemFieldMap) {
1167
- const field = inputTypeElemFieldMap[fieldName];
1168
- inputFieldMap[fieldName] = field;
1169
- }
1170
- }
1171
- if (outputTypeComposer instanceof graphqlCompose.ScalarTypeComposer) {
1172
- fieldMap[outputTypeComposer.getTypeName()] = {
1173
- type: outputTypeComposer,
1174
- resolve: root => root,
1175
- };
1176
- }
1177
- else if (outputTypeComposer instanceof graphqlCompose.UnionTypeComposer) {
1178
- const outputTCElems = outputTypeComposer.getTypes();
1179
- for (const outputTCElem of outputTCElems) {
1180
- const outputTypeElemFieldMap = outputTCElem.getFields();
1181
- for (const fieldName in outputTypeElemFieldMap) {
1182
- const field = outputTypeElemFieldMap[fieldName];
1183
- fieldMap[fieldName] = field;
1184
- }
1185
- }
1186
- }
1187
- else {
1188
- const typeElemFieldMap = outputTypeComposer.getFields();
1189
- for (const fieldName in typeElemFieldMap) {
1190
- const field = typeElemFieldMap[fieldName];
1191
- fieldMap[fieldName] = field;
1192
- }
1193
- }
1194
- }
1195
- let inputTypeComposer;
1196
- const outputTypeComposer = schemaComposer.createObjectTC({
1197
- name: getValidTypeName({
1198
- schemaComposer,
1199
- isInput: false,
1200
- subSchema,
1201
- }),
1202
- description: subSchema.description,
1203
- fields: fieldMap,
1204
- extensions: {
1205
- validateWithJSONSchema,
1206
- examples: subSchema.examples,
1207
- default: subSchema.default,
1208
- },
1209
- });
1210
- if (ableToUseGraphQLInputObjectType) {
1211
- inputTypeComposer = schemaComposer.createInputTC({
1212
- name: getValidTypeName({
1213
- schemaComposer,
1214
- isInput: true,
1215
- subSchema,
1216
- }),
1217
- description: subSchema.description,
1218
- fields: inputFieldMap,
1219
- extensions: {
1220
- examples: subSchema.examples,
1221
- default: subSchema.default,
1222
- },
1223
- });
1224
- }
1225
1073
  else {
1226
- inputTypeComposer = graphqlCompose.isSomeInputTypeComposer(outputTypeComposer)
1227
- ? outputTypeComposer
1228
- : getGenericJSONScalar({
1229
- schemaComposer,
1230
- isInput: true,
1231
- subSchema,
1232
- validateWithJSONSchema,
1233
- });
1234
- }
1235
- return {
1236
- input: inputTypeComposer,
1237
- output: outputTypeComposer,
1238
- };
1239
- }
1240
- if (subSchema.anyOf && !subSchema.properties) {
1241
- if (subSchema.title === 'Any') {
1242
- const genericJSONScalar = getGenericJSONScalar({
1243
- schemaComposer,
1244
- isInput: false,
1074
+ const typeComposer = getGenericJSONScalar({
1075
+ isInput: true,
1245
1076
  subSchema,
1246
- validateWithJSONSchema,
1247
- });
1248
- return {
1249
- input: genericJSONScalar,
1250
- output: genericJSONScalar,
1251
- };
1252
- }
1253
- // It should not have `required` because it is `anyOf` not `allOf`
1254
- const inputFieldMap = {};
1255
- const fieldMap = {};
1256
- let ableToUseGraphQLInputObjectType = true;
1257
- for (const typeComposers of subSchema.anyOf) {
1258
- const { input: inputTypeComposer, output: outputTypeComposer } = typeComposers;
1259
- if (inputTypeComposer instanceof graphqlCompose.ScalarTypeComposer) {
1260
- ableToUseGraphQLInputObjectType = false;
1261
- }
1262
- else {
1263
- const inputTypeElemFieldMap = inputTypeComposer.getFields();
1264
- for (const fieldName in inputTypeElemFieldMap) {
1265
- const field = inputTypeElemFieldMap[fieldName];
1266
- inputFieldMap[fieldName] = graphql.isNonNullType(field.type.getType())
1267
- ? {
1268
- ...field,
1269
- type: () => field.type.ofType,
1270
- }
1271
- : field;
1272
- }
1273
- }
1274
- if (outputTypeComposer instanceof graphqlCompose.ScalarTypeComposer) {
1275
- const typeName = outputTypeComposer.getTypeName();
1276
- fieldMap[typeName] = {
1277
- type: outputTypeComposer,
1278
- resolve: root => root,
1279
- };
1280
- }
1281
- else {
1282
- const typeElemFieldMap = outputTypeComposer.getFields();
1283
- for (const fieldName in typeElemFieldMap) {
1284
- const field = typeElemFieldMap[fieldName];
1285
- fieldMap[fieldName] = {
1286
- type: () => graphql.getNamedType(field.type.getType()),
1287
- ...field,
1288
- };
1289
- }
1290
- }
1291
- }
1292
- let inputTypeComposer;
1293
- const outputTypeComposer = schemaComposer.createObjectTC({
1294
- name: getValidTypeName({
1295
1077
  schemaComposer,
1296
- isInput: false,
1297
- subSchema,
1298
- }),
1299
- description: subSchema.description,
1300
- fields: fieldMap,
1301
- extensions: {
1302
1078
  validateWithJSONSchema,
1303
- examples: subSchema.examples,
1304
- default: subSchema.default,
1305
- },
1306
- });
1307
- if (ableToUseGraphQLInputObjectType) {
1308
- inputTypeComposer = schemaComposer.createInputTC({
1309
- name: getValidTypeName({
1310
- schemaComposer,
1311
- isInput: true,
1312
- subSchema,
1313
- }),
1314
- description: subSchema.description,
1315
- fields: inputFieldMap,
1316
- extensions: {
1317
- examples: subSchema.examples,
1318
- default: subSchema.default,
1319
- },
1320
1079
  });
1321
- }
1322
- else {
1323
- inputTypeComposer = graphqlCompose.isSomeInputTypeComposer(outputTypeComposer)
1324
- ? outputTypeComposer
1325
- : getGenericJSONScalar({
1326
- schemaComposer,
1327
- isInput: true,
1328
- subSchema,
1329
- validateWithJSONSchema,
1330
- });
1331
- }
1332
- return {
1333
- input: inputTypeComposer,
1334
- output: outputTypeComposer,
1335
- };
1336
- }
1337
- if (Array.isArray(subSchema.type)) {
1338
- const validTypes = subSchema.type.filter((typeName) => typeName !== 'null');
1339
- if (validTypes.length === 1) {
1340
- subSchema.type = validTypes[0];
1341
- // continue with the single type
1342
- }
1343
- else {
1344
- const typeComposer = schemaComposer.getAnyTC(GraphQLVoid);
1345
1080
  return {
1346
1081
  input: typeComposer,
1347
1082
  output: typeComposer,
1083
+ nullable: subSchema.nullable,
1348
1084
  };
1349
1085
  }
1350
1086
  }
@@ -1355,6 +1091,7 @@ function getComposerFromJSONSchema(schema, logger, generateInterfaceFromSharedFi
1355
1091
  input: typeComposer,
1356
1092
  output: typeComposer,
1357
1093
  description: subSchema.description,
1094
+ nullable: subSchema.nullable,
1358
1095
  };
1359
1096
  }
1360
1097
  case 'boolean': {
@@ -1363,6 +1100,7 @@ function getComposerFromJSONSchema(schema, logger, generateInterfaceFromSharedFi
1363
1100
  input: typeComposer,
1364
1101
  output: typeComposer,
1365
1102
  description: subSchema.description,
1103
+ nullable: subSchema.nullable,
1366
1104
  };
1367
1105
  }
1368
1106
  case 'null': {
@@ -1371,6 +1109,7 @@ function getComposerFromJSONSchema(schema, logger, generateInterfaceFromSharedFi
1371
1109
  input: typeComposer,
1372
1110
  output: typeComposer,
1373
1111
  description: subSchema.description,
1112
+ nullable: subSchema.nullable,
1374
1113
  };
1375
1114
  }
1376
1115
  case 'integer': {
@@ -1380,6 +1119,7 @@ function getComposerFromJSONSchema(schema, logger, generateInterfaceFromSharedFi
1380
1119
  input: typeComposer,
1381
1120
  output: typeComposer,
1382
1121
  description: subSchema.description,
1122
+ nullable: subSchema.nullable,
1383
1123
  };
1384
1124
  }
1385
1125
  const typeComposer = schemaComposer.getAnyTC(graphql.GraphQLInt);
@@ -1387,6 +1127,7 @@ function getComposerFromJSONSchema(schema, logger, generateInterfaceFromSharedFi
1387
1127
  input: typeComposer,
1388
1128
  output: typeComposer,
1389
1129
  description: subSchema.description,
1130
+ nullable: subSchema.nullable,
1390
1131
  };
1391
1132
  }
1392
1133
  case 'number': {
@@ -1395,6 +1136,7 @@ function getComposerFromJSONSchema(schema, logger, generateInterfaceFromSharedFi
1395
1136
  input: typeComposer,
1396
1137
  output: typeComposer,
1397
1138
  description: subSchema.description,
1139
+ nullable: subSchema.nullable,
1398
1140
  };
1399
1141
  }
1400
1142
  case 'string': {
@@ -1408,6 +1150,7 @@ function getComposerFromJSONSchema(schema, logger, generateInterfaceFromSharedFi
1408
1150
  input: typeComposer,
1409
1151
  output: typeComposer,
1410
1152
  description: subSchema.description,
1153
+ nullable: subSchema.nullable,
1411
1154
  };
1412
1155
  }
1413
1156
  switch (subSchema.format) {
@@ -1417,6 +1160,7 @@ function getComposerFromJSONSchema(schema, logger, generateInterfaceFromSharedFi
1417
1160
  input: typeComposer,
1418
1161
  output: typeComposer,
1419
1162
  description: subSchema.description,
1163
+ nullable: subSchema.nullable,
1420
1164
  };
1421
1165
  }
1422
1166
  case 'time': {
@@ -1425,6 +1169,7 @@ function getComposerFromJSONSchema(schema, logger, generateInterfaceFromSharedFi
1425
1169
  input: typeComposer,
1426
1170
  output: typeComposer,
1427
1171
  description: subSchema.description,
1172
+ nullable: subSchema.nullable,
1428
1173
  };
1429
1174
  }
1430
1175
  case 'email': {
@@ -1433,6 +1178,7 @@ function getComposerFromJSONSchema(schema, logger, generateInterfaceFromSharedFi
1433
1178
  input: typeComposer,
1434
1179
  output: typeComposer,
1435
1180
  description: subSchema.description,
1181
+ nullable: subSchema.nullable,
1436
1182
  };
1437
1183
  }
1438
1184
  case 'ipv4': {
@@ -1441,6 +1187,7 @@ function getComposerFromJSONSchema(schema, logger, generateInterfaceFromSharedFi
1441
1187
  input: typeComposer,
1442
1188
  output: typeComposer,
1443
1189
  description: subSchema.description,
1190
+ nullable: subSchema.nullable,
1444
1191
  };
1445
1192
  }
1446
1193
  case 'ipv6': {
@@ -1449,6 +1196,7 @@ function getComposerFromJSONSchema(schema, logger, generateInterfaceFromSharedFi
1449
1196
  input: typeComposer,
1450
1197
  output: typeComposer,
1451
1198
  description: subSchema.description,
1199
+ nullable: subSchema.nullable,
1452
1200
  };
1453
1201
  }
1454
1202
  case 'uri': {
@@ -1457,6 +1205,7 @@ function getComposerFromJSONSchema(schema, logger, generateInterfaceFromSharedFi
1457
1205
  input: typeComposer,
1458
1206
  output: typeComposer,
1459
1207
  description: subSchema.description,
1208
+ nullable: subSchema.nullable,
1460
1209
  };
1461
1210
  }
1462
1211
  default: {
@@ -1466,19 +1215,24 @@ function getComposerFromJSONSchema(schema, logger, generateInterfaceFromSharedFi
1466
1215
  input: typeComposer,
1467
1216
  output: typeComposer,
1468
1217
  description: subSchema.description,
1218
+ nullable: subSchema.nullable,
1469
1219
  };
1470
1220
  }
1471
1221
  }
1472
1222
  }
1473
1223
  case 'array':
1474
- if (typeof subSchema.items === 'object' &&
1475
- !Array.isArray(subSchema.items) &&
1476
- Object.keys(subSchema.items).length > 0) {
1477
- const typeComposers = subSchema.items;
1224
+ if (typeof subSchema.items === 'object' && Object.keys(subSchema.items).length > 0) {
1478
1225
  return {
1479
- input: typeComposers.input.getTypePlural(),
1480
- output: typeComposers.output.getTypePlural(),
1481
- description: subSchema.description,
1226
+ // These are filled after enter
1227
+ get input() {
1228
+ const typeComposers = visitedSubschemaResultMap.get(subSchema.items);
1229
+ return typeComposers.input.getTypePlural();
1230
+ },
1231
+ get output() {
1232
+ const typeComposers = visitedSubschemaResultMap.get(subSchema.items);
1233
+ return typeComposers.output.getTypePlural();
1234
+ },
1235
+ ...subSchema,
1482
1236
  };
1483
1237
  }
1484
1238
  if (subSchema.contains) {
@@ -1492,26 +1246,7 @@ function getComposerFromJSONSchema(schema, logger, generateInterfaceFromSharedFi
1492
1246
  return {
1493
1247
  input: typeComposer,
1494
1248
  output: typeComposer,
1495
- };
1496
- }
1497
- if (typeof subSchema.items === 'object' && Array.isArray(subSchema.items)) {
1498
- const existingItems = [...subSchema.items];
1499
- /* TODO
1500
- if (subSchema.additionalItems) {
1501
- existingItems.push(subSchema.additionalItems);
1502
- }
1503
- */
1504
- const { input: inputTypeComposer, output: outputTypeComposer } = getUnionTypeComposers({
1505
- schemaComposer,
1506
- ajv,
1507
- typeComposersList: existingItems,
1508
- subSchema,
1509
- generateInterfaceFromSharedFields,
1510
- });
1511
- return {
1512
- input: inputTypeComposer.getTypePlural(),
1513
- output: outputTypeComposer.getTypePlural(),
1514
- description: subSchema.description,
1249
+ nullable: subSchema.nullable,
1515
1250
  };
1516
1251
  }
1517
1252
  // If it doesn't have any clue
@@ -1527,29 +1262,362 @@ function getComposerFromJSONSchema(schema, logger, generateInterfaceFromSharedFi
1527
1262
  input: typeComposer,
1528
1263
  output: typeComposer,
1529
1264
  description: subSchema.description,
1265
+ nullable: subSchema.nullable,
1266
+ };
1267
+ }
1268
+ case 'object': {
1269
+ switch (subSchema.title) {
1270
+ case '_schema':
1271
+ return {
1272
+ output: schemaComposer,
1273
+ ...subSchema,
1274
+ };
1275
+ case 'Query':
1276
+ return {
1277
+ output: schemaComposer.Query,
1278
+ ...subSchema,
1279
+ };
1280
+ case 'Mutation':
1281
+ return {
1282
+ output: schemaComposer.Mutation,
1283
+ ...subSchema,
1284
+ };
1285
+ case 'Subscription':
1286
+ return {
1287
+ output: schemaComposer.Subscription,
1288
+ ...subSchema,
1289
+ };
1290
+ }
1291
+ if (subSchema.properties || subSchema.allOf || subSchema.additionalProperties) {
1292
+ return {
1293
+ input: schemaComposer.createInputTC({
1294
+ name: getValidTypeName({
1295
+ schemaComposer,
1296
+ isInput: true,
1297
+ subSchema,
1298
+ }),
1299
+ description: subSchema.description,
1300
+ fields: {},
1301
+ extensions: {
1302
+ examples: subSchema.examples,
1303
+ default: subSchema.default,
1304
+ },
1305
+ }),
1306
+ output: schemaComposer.createObjectTC({
1307
+ name: getValidTypeName({
1308
+ schemaComposer,
1309
+ isInput: false,
1310
+ subSchema,
1311
+ }),
1312
+ description: subSchema.description,
1313
+ fields: {},
1314
+ extensions: {
1315
+ validateWithJSONSchema,
1316
+ examples: subSchema.examples,
1317
+ default: subSchema.default,
1318
+ },
1319
+ }),
1320
+ ...subSchema,
1321
+ ...(subSchema.properties ? { properties: { ...subSchema.properties } } : {}),
1322
+ ...(subSchema.allOf ? { allOf: [...subSchema.allOf] } : {}),
1323
+ ...(subSchema.additionalProperties
1324
+ ? {
1325
+ additionalProperties: subSchema.additionalProperties === true ? true : { ...subSchema.additionalProperties },
1326
+ }
1327
+ : {}),
1328
+ };
1329
+ }
1330
+ }
1331
+ }
1332
+ if (subSchema.oneOf && !subSchema.properties) {
1333
+ let statusCodeOneOfIndexMap;
1334
+ if ((_a = subSchema.$comment) === null || _a === void 0 ? void 0 : _a.startsWith('statusCodeOneOfIndexMap:')) {
1335
+ const statusCodeOneOfIndexMapStr = subSchema.$comment.replace('statusCodeOneOfIndexMap:', '');
1336
+ statusCodeOneOfIndexMap = JSON.parse(statusCodeOneOfIndexMapStr);
1337
+ }
1338
+ const input = schemaComposer.createInputTC({
1339
+ name: getValidTypeName({
1340
+ schemaComposer,
1341
+ isInput: true,
1342
+ subSchema,
1343
+ }),
1344
+ fields: {},
1345
+ directives: [
1346
+ {
1347
+ name: 'oneOf',
1348
+ },
1349
+ ],
1350
+ });
1351
+ const output = schemaComposer.createUnionTC({
1352
+ name: getValidTypeName({
1353
+ schemaComposer,
1354
+ isInput: false,
1355
+ subSchema,
1356
+ }),
1357
+ description: subSchema.description,
1358
+ types: [],
1359
+ extensions: {
1360
+ statusCodeOneOfIndexMap,
1361
+ },
1362
+ });
1363
+ return {
1364
+ input,
1365
+ output,
1366
+ ...subSchema,
1367
+ };
1368
+ }
1369
+ if (!subSchema.properties && (subSchema.anyOf || subSchema.allOf)) {
1370
+ if (subSchema.title === 'Any') {
1371
+ const genericJSONScalar = getGenericJSONScalar({
1372
+ schemaComposer,
1373
+ isInput: false,
1374
+ subSchema,
1375
+ validateWithJSONSchema,
1376
+ });
1377
+ return {
1378
+ input: genericJSONScalar,
1379
+ output: genericJSONScalar,
1380
+ nullable: subSchema.nullable,
1381
+ };
1382
+ }
1383
+ const input = schemaComposer.createInputTC({
1384
+ name: getValidTypeName({
1385
+ schemaComposer,
1386
+ isInput: true,
1387
+ subSchema,
1388
+ }),
1389
+ description: subSchema.description,
1390
+ fields: {},
1391
+ extensions: {
1392
+ examples: subSchema.examples,
1393
+ default: subSchema.default,
1394
+ },
1395
+ });
1396
+ const output = schemaComposer.createObjectTC({
1397
+ name: getValidTypeName({
1398
+ schemaComposer,
1399
+ isInput: false,
1400
+ subSchema,
1401
+ }),
1402
+ description: subSchema.description,
1403
+ fields: {},
1404
+ extensions: {
1405
+ validateWithJSONSchema,
1406
+ examples: subSchema.examples,
1407
+ default: subSchema.default,
1408
+ },
1409
+ });
1410
+ return {
1411
+ input,
1412
+ output,
1413
+ ...subSchema,
1414
+ };
1415
+ }
1416
+ return subSchema;
1417
+ },
1418
+ leave(subSchemaAndTypeComposers, { path }) {
1419
+ var _a, _b, _c, _d, _e;
1420
+ logger === null || logger === void 0 ? void 0 : logger.debug(`Leaving ${path} for GraphQL Schema`);
1421
+ const validateWithJSONSchema = getValidateFnForSchemaPath(ajv, path, schema);
1422
+ const subSchemaOnly = {
1423
+ ...subSchemaAndTypeComposers,
1424
+ input: undefined,
1425
+ output: undefined,
1426
+ };
1427
+ if (subSchemaAndTypeComposers.oneOf && !subSchemaAndTypeComposers.properties) {
1428
+ const isPlural = subSchemaAndTypeComposers.oneOf.some(({ output }) => 'ofType' in output);
1429
+ if (isPlural) {
1430
+ const { input, output } = getUnionTypeComposers({
1431
+ schemaComposer,
1432
+ ajv,
1433
+ typeComposersList: subSchemaAndTypeComposers.oneOf.map(({ input, output }) => ({
1434
+ input: input.ofType || input,
1435
+ output: output.ofType || output,
1436
+ })),
1437
+ subSchemaAndTypeComposers,
1438
+ });
1439
+ return {
1440
+ input: input.getTypePlural(),
1441
+ output: output.getTypePlural(),
1442
+ nullable: subSchemaAndTypeComposers.nullable,
1443
+ };
1444
+ }
1445
+ return getUnionTypeComposers({
1446
+ schemaComposer,
1447
+ ajv,
1448
+ typeComposersList: subSchemaAndTypeComposers.oneOf,
1449
+ subSchemaAndTypeComposers,
1450
+ });
1451
+ }
1452
+ if (subSchemaAndTypeComposers.allOf && !subSchemaAndTypeComposers.properties) {
1453
+ const inputFieldMap = {};
1454
+ const fieldMap = {};
1455
+ let ableToUseGraphQLInputObjectType = true;
1456
+ for (const maybeTypeComposers of subSchemaAndTypeComposers.allOf) {
1457
+ const { input: inputTypeComposer, output: outputTypeComposer } = maybeTypeComposers;
1458
+ if (inputTypeComposer instanceof graphqlCompose.ScalarTypeComposer) {
1459
+ ableToUseGraphQLInputObjectType = false;
1460
+ }
1461
+ else {
1462
+ const inputTypeElemFieldMap = inputTypeComposer.getFields();
1463
+ for (const fieldName in inputTypeElemFieldMap) {
1464
+ const field = inputTypeElemFieldMap[fieldName];
1465
+ inputFieldMap[fieldName] = field;
1466
+ }
1467
+ }
1468
+ if (outputTypeComposer instanceof graphqlCompose.ScalarTypeComposer) {
1469
+ fieldMap[outputTypeComposer.getTypeName()] = {
1470
+ type: outputTypeComposer,
1471
+ resolve: root => root,
1530
1472
  };
1531
1473
  }
1474
+ else if (outputTypeComposer instanceof graphqlCompose.UnionTypeComposer) {
1475
+ const outputTCElems = outputTypeComposer.getTypes();
1476
+ for (const outputTCElem of outputTCElems) {
1477
+ const outputTypeElemFieldMap = outputTCElem.getFields();
1478
+ for (const fieldName in outputTypeElemFieldMap) {
1479
+ const field = outputTypeElemFieldMap[fieldName];
1480
+ fieldMap[fieldName] = field;
1481
+ }
1482
+ }
1483
+ }
1484
+ else {
1485
+ const typeElemFieldMap = outputTypeComposer.getFields();
1486
+ for (const fieldName in typeElemFieldMap) {
1487
+ const field = typeElemFieldMap[fieldName];
1488
+ fieldMap[fieldName] = field;
1489
+ }
1490
+ }
1491
+ }
1492
+ let inputTypeComposer = subSchemaAndTypeComposers.input;
1493
+ subSchemaAndTypeComposers.output.addFields(fieldMap);
1494
+ subSchemaAndTypeComposers.output.setExtensions({
1495
+ validateWithJSONSchema,
1496
+ examples: subSchemaAndTypeComposers.examples,
1497
+ default: subSchemaAndTypeComposers.default,
1498
+ });
1499
+ if (ableToUseGraphQLInputObjectType) {
1500
+ inputTypeComposer.addFields(inputFieldMap);
1501
+ inputTypeComposer.setExtensions({
1502
+ examples: subSchemaAndTypeComposers.examples,
1503
+ default: subSchemaAndTypeComposers.default,
1504
+ });
1505
+ }
1506
+ else {
1507
+ schemaComposer.delete(inputTypeComposer);
1508
+ inputTypeComposer = getGenericJSONScalar({
1509
+ schemaComposer,
1510
+ isInput: true,
1511
+ subSchema: subSchemaOnly,
1512
+ validateWithJSONSchema,
1513
+ });
1514
+ }
1515
+ return {
1516
+ input: inputTypeComposer,
1517
+ output: subSchemaAndTypeComposers.output,
1518
+ nullable: subSchemaAndTypeComposers.nullable,
1519
+ };
1520
+ }
1521
+ if (subSchemaAndTypeComposers.anyOf && !subSchemaAndTypeComposers.properties) {
1522
+ // It should not have `required` because it is `anyOf` not `allOf`
1523
+ const inputFieldMap = {};
1524
+ const fieldMap = {};
1525
+ let ableToUseGraphQLInputObjectType = true;
1526
+ for (const typeComposers of subSchemaAndTypeComposers.anyOf) {
1527
+ const { input: inputTypeComposer, output: outputTypeComposer } = typeComposers;
1528
+ if (inputTypeComposer instanceof graphqlCompose.ScalarTypeComposer) {
1529
+ ableToUseGraphQLInputObjectType = false;
1530
+ }
1531
+ else {
1532
+ const inputTypeElemFieldMap = inputTypeComposer.getFields();
1533
+ for (const fieldName in inputTypeElemFieldMap) {
1534
+ const field = inputTypeElemFieldMap[fieldName];
1535
+ inputFieldMap[fieldName] = graphql.isNonNullType(field.type.getType())
1536
+ ? {
1537
+ ...field,
1538
+ type: () => field.type.ofType,
1539
+ }
1540
+ : field;
1541
+ }
1542
+ }
1543
+ if (outputTypeComposer instanceof graphqlCompose.ScalarTypeComposer) {
1544
+ const typeName = outputTypeComposer.getTypeName();
1545
+ fieldMap[typeName] = {
1546
+ type: outputTypeComposer,
1547
+ resolve: root => root,
1548
+ };
1549
+ }
1550
+ else {
1551
+ const typeElemFieldMap = outputTypeComposer.getFields();
1552
+ for (const fieldName in typeElemFieldMap) {
1553
+ const field = typeElemFieldMap[fieldName];
1554
+ fieldMap[fieldName] = {
1555
+ type: () => graphql.getNamedType(field.type.getType()),
1556
+ ...field,
1557
+ };
1558
+ }
1559
+ }
1560
+ }
1561
+ let inputTypeComposer = subSchemaAndTypeComposers.input;
1562
+ subSchemaAndTypeComposers.output.addFields(fieldMap);
1563
+ subSchemaAndTypeComposers.output.setExtensions({
1564
+ validateWithJSONSchema,
1565
+ examples: subSchemaAndTypeComposers.examples,
1566
+ default: subSchemaAndTypeComposers.default,
1567
+ });
1568
+ if (ableToUseGraphQLInputObjectType) {
1569
+ inputTypeComposer.addFields(inputFieldMap);
1570
+ inputTypeComposer.setExtensions({
1571
+ examples: subSchemaAndTypeComposers.examples,
1572
+ default: subSchemaAndTypeComposers.default,
1573
+ });
1574
+ }
1575
+ else {
1576
+ schemaComposer.delete(inputTypeComposer);
1577
+ inputTypeComposer = getGenericJSONScalar({
1578
+ schemaComposer,
1579
+ isInput: true,
1580
+ subSchema: subSchemaOnly,
1581
+ validateWithJSONSchema,
1582
+ });
1583
+ }
1584
+ return {
1585
+ input: inputTypeComposer,
1586
+ output: subSchemaAndTypeComposers.output,
1587
+ nullable: subSchemaAndTypeComposers.nullable,
1588
+ };
1589
+ }
1590
+ switch (subSchemaAndTypeComposers.type) {
1532
1591
  case 'object':
1533
1592
  const fieldMap = {};
1534
1593
  let inputFieldMap = {};
1535
- if (subSchema.properties) {
1536
- subSchema.type = 'object';
1537
- for (const propertyName in subSchema.properties) {
1594
+ if (subSchemaAndTypeComposers.properties) {
1595
+ for (const propertyName in subSchemaAndTypeComposers.properties) {
1538
1596
  // TODO: needs to be fixed
1539
1597
  if (propertyName === 'additionalProperties') {
1540
1598
  continue;
1541
1599
  }
1542
- const typeComposers = subSchema.properties[propertyName];
1543
1600
  const fieldName = utils.sanitizeNameForGraphQL(propertyName);
1544
1601
  fieldMap[fieldName] = {
1545
1602
  type: () => {
1546
1603
  var _a;
1547
- return ((_a = subSchema.required) === null || _a === void 0 ? void 0 : _a.includes(propertyName))
1548
- ? typeComposers.output.getTypeNonNull()
1549
- : typeComposers.output;
1604
+ const typeComposers = subSchemaAndTypeComposers.properties[propertyName];
1605
+ let nullable = true;
1606
+ if ((_a = subSchemaAndTypeComposers.required) === null || _a === void 0 ? void 0 : _a.includes(propertyName)) {
1607
+ nullable = false;
1608
+ }
1609
+ // Nullable has more priority
1610
+ if (typeComposers.nullable === false) {
1611
+ nullable = false;
1612
+ }
1613
+ if (typeComposers.nullable === true) {
1614
+ nullable = true;
1615
+ }
1616
+ return !nullable ? typeComposers.output.getTypeNonNull() : typeComposers.output;
1550
1617
  },
1551
1618
  // Make sure you get the right property
1552
1619
  resolve: root => {
1620
+ const typeComposers = subSchemaAndTypeComposers.properties[propertyName];
1553
1621
  const actualFieldObj = root[propertyName];
1554
1622
  if (actualFieldObj != null) {
1555
1623
  const isArray = Array.isArray(actualFieldObj);
@@ -1563,26 +1631,39 @@ function getComposerFromJSONSchema(schema, logger, generateInterfaceFromSharedFi
1563
1631
  }
1564
1632
  return actualFieldObj;
1565
1633
  },
1566
- description: typeComposers.description || ((_b = typeComposers.output) === null || _b === void 0 ? void 0 : _b.description),
1634
+ description: subSchemaAndTypeComposers.properties[propertyName].description ||
1635
+ ((_a = subSchemaAndTypeComposers.properties[propertyName].output) === null || _a === void 0 ? void 0 : _a.description),
1567
1636
  };
1568
1637
  inputFieldMap[fieldName] = {
1569
1638
  type: () => {
1570
1639
  var _a, _b;
1571
- return ((_a = subSchema.required) === null || _a === void 0 ? void 0 : _a.includes(propertyName))
1572
- ? (_b = typeComposers.input) === null || _b === void 0 ? void 0 : _b.getTypeNonNull()
1573
- : typeComposers.input;
1640
+ const typeComposers = subSchemaAndTypeComposers.properties[propertyName];
1641
+ let nullable = true;
1642
+ if ((_a = subSchemaAndTypeComposers.required) === null || _a === void 0 ? void 0 : _a.includes(propertyName)) {
1643
+ nullable = false;
1644
+ }
1645
+ // Nullable has more priority
1646
+ if (typeComposers.nullable === false) {
1647
+ nullable = false;
1648
+ }
1649
+ if (typeComposers.nullable === true) {
1650
+ nullable = true;
1651
+ }
1652
+ return !nullable ? (_b = typeComposers.input) === null || _b === void 0 ? void 0 : _b.getTypeNonNull() : typeComposers.input;
1574
1653
  },
1575
1654
  // Let execution logic know what is the expected propertyName
1576
1655
  extensions: {
1577
1656
  propertyName,
1578
1657
  },
1579
- description: typeComposers.description || ((_c = typeComposers.input) === null || _c === void 0 ? void 0 : _c.description),
1580
- defaultValue: ((_d = typeComposers === null || typeComposers === void 0 ? void 0 : typeComposers.extensions) === null || _d === void 0 ? void 0 : _d.default) || ((_e = typeComposers.input) === null || _e === void 0 ? void 0 : _e.default),
1658
+ description: subSchemaAndTypeComposers.properties[propertyName].description ||
1659
+ ((_b = subSchemaAndTypeComposers.properties[propertyName].input) === null || _b === void 0 ? void 0 : _b.description),
1660
+ defaultValue: ((_d = (_c = subSchemaAndTypeComposers.properties[propertyName]) === null || _c === void 0 ? void 0 : _c.extensions) === null || _d === void 0 ? void 0 : _d.default) ||
1661
+ ((_e = subSchemaAndTypeComposers.properties[propertyName].input) === null || _e === void 0 ? void 0 : _e.default),
1581
1662
  };
1582
1663
  }
1583
1664
  }
1584
- if (subSchema.allOf) {
1585
- for (const typeComposers of subSchema.allOf) {
1665
+ if (subSchemaAndTypeComposers.allOf) {
1666
+ for (const typeComposers of subSchemaAndTypeComposers.allOf) {
1586
1667
  const outputTC = typeComposers.output;
1587
1668
  if (schemaComposer.isObjectType(outputTC)) {
1588
1669
  for (const outputFieldName of outputTC.getFieldNames()) {
@@ -1601,19 +1682,19 @@ function getComposerFromJSONSchema(schema, logger, generateInterfaceFromSharedFi
1601
1682
  }
1602
1683
  }
1603
1684
  }
1604
- if (subSchema.additionalProperties) {
1605
- if (typeof subSchema.additionalProperties === 'object' &&
1606
- subSchema.additionalProperties.output instanceof graphqlCompose.ObjectTypeComposer) {
1685
+ if (subSchemaAndTypeComposers.additionalProperties) {
1686
+ if (typeof subSchemaAndTypeComposers.additionalProperties === 'object' &&
1687
+ subSchemaAndTypeComposers.additionalProperties.output instanceof graphqlCompose.ObjectTypeComposer) {
1607
1688
  if (Object.keys(fieldMap).length === 0) {
1608
- return subSchema.additionalProperties;
1689
+ return subSchemaAndTypeComposers.additionalProperties;
1609
1690
  }
1610
1691
  else {
1611
- const outputTC = subSchema.additionalProperties.output;
1692
+ const outputTC = subSchemaAndTypeComposers.additionalProperties.output;
1612
1693
  const outputTCFieldMap = outputTC.getFields();
1613
1694
  for (const fieldName in outputTCFieldMap) {
1614
1695
  fieldMap[fieldName] = outputTCFieldMap[fieldName];
1615
1696
  }
1616
- const inputTC = subSchema.additionalProperties.input;
1697
+ const inputTC = subSchemaAndTypeComposers.additionalProperties.input;
1617
1698
  const inputTCFieldMap = inputTC.getFields();
1618
1699
  for (const fieldName in inputTCFieldMap) {
1619
1700
  inputFieldMap[fieldName] = inputTCFieldMap[fieldName];
@@ -1628,33 +1709,6 @@ function getComposerFromJSONSchema(schema, logger, generateInterfaceFromSharedFi
1628
1709
  inputFieldMap = {};
1629
1710
  }
1630
1711
  }
1631
- if (subSchema.title === '_schema') {
1632
- futureTasks.forEach(futureTask => futureTask());
1633
- return {
1634
- output: schemaComposer,
1635
- };
1636
- }
1637
- if (subSchema.title === 'Query') {
1638
- const typeComposer = schemaComposer.Query;
1639
- typeComposer.addFields(fieldMap);
1640
- return {
1641
- output: typeComposer,
1642
- };
1643
- }
1644
- if (subSchema.title === 'Mutation') {
1645
- const typeComposer = schemaComposer.Mutation;
1646
- typeComposer.addFields(fieldMap);
1647
- return {
1648
- output: typeComposer,
1649
- };
1650
- }
1651
- if (subSchema.title === 'Subscription') {
1652
- const typeComposer = schemaComposer.Subscription;
1653
- typeComposer.addFields(fieldMap);
1654
- return {
1655
- output: typeComposer,
1656
- };
1657
- }
1658
1712
  const getCorrectInputFieldType = (fieldName) => {
1659
1713
  const inputType = inputFieldMap[fieldName].type();
1660
1714
  const actualInputType = isListTC(inputType) ? inputType.ofType : inputType;
@@ -1670,112 +1724,77 @@ function getComposerFromJSONSchema(schema, logger, generateInterfaceFromSharedFi
1670
1724
  }
1671
1725
  return inputType;
1672
1726
  };
1673
- if (subSchema.title === 'QueryInput') {
1674
- const typeComposer = schemaComposer.Query;
1675
- for (const fieldName in inputFieldMap) {
1676
- futureTasks.add(() => typeComposer.addFieldArgs(fieldName, {
1677
- input: {
1678
- type: () => getCorrectInputFieldType(fieldName),
1679
- description: inputFieldMap[fieldName].description,
1680
- },
1681
- }));
1682
- }
1683
- return {
1684
- output: typeComposer,
1685
- };
1686
- }
1687
- if (subSchema.title === 'MutationInput') {
1688
- const typeComposer = schemaComposer.Mutation;
1689
- for (const fieldName in inputFieldMap) {
1690
- futureTasks.add(() => typeComposer.addFieldArgs(fieldName, {
1691
- input: {
1692
- type: () => getCorrectInputFieldType(fieldName),
1693
- description: inputFieldMap[fieldName].description,
1694
- },
1695
- }));
1696
- }
1697
- return {
1698
- output: typeComposer,
1699
- };
1700
- }
1701
- if (subSchema.title === 'SubscriptionInput') {
1702
- const typeComposer = schemaComposer.Subscription;
1727
+ if (subSchemaAndTypeComposers.title in rootInputTypeNameComposerMap) {
1728
+ const typeComposer = rootInputTypeNameComposerMap[subSchemaAndTypeComposers.title]();
1703
1729
  for (const fieldName in inputFieldMap) {
1704
- futureTasks.add(() => typeComposer.addFieldArgs(fieldName, {
1730
+ typeComposer.addFieldArgs(fieldName, {
1705
1731
  input: {
1706
1732
  type: () => getCorrectInputFieldType(fieldName),
1707
1733
  description: inputFieldMap[fieldName].description,
1708
1734
  },
1709
- }));
1735
+ });
1710
1736
  }
1711
1737
  return {
1712
1738
  output: typeComposer,
1713
1739
  };
1714
1740
  }
1715
- const output = Object.keys(fieldMap).length === 0
1716
- ? getGenericJSONScalar({
1741
+ let output = subSchemaAndTypeComposers.output;
1742
+ if (Object.keys(fieldMap).length === 0) {
1743
+ output = getGenericJSONScalar({
1717
1744
  schemaComposer,
1718
1745
  isInput: false,
1719
- subSchema,
1746
+ subSchema: subSchemaOnly,
1720
1747
  validateWithJSONSchema,
1721
- })
1722
- : schemaComposer.createObjectTC({
1723
- name: getValidTypeName({
1724
- schemaComposer,
1725
- isInput: false,
1726
- subSchema,
1727
- }),
1728
- description: subSchema.description,
1729
- fields: fieldMap,
1730
- extensions: {
1731
- validateWithJSONSchema,
1732
- examples: subSchema.examples,
1733
- default: subSchema.default,
1734
- },
1735
1748
  });
1736
- const input = Object.keys(inputFieldMap).length === 0
1737
- ? getGenericJSONScalar({
1749
+ }
1750
+ else if ('addFields' in output) {
1751
+ output.addFields(fieldMap);
1752
+ }
1753
+ let input = subSchemaAndTypeComposers.input;
1754
+ if (Object.keys(inputFieldMap).length === 0) {
1755
+ input = getGenericJSONScalar({
1738
1756
  schemaComposer,
1739
1757
  isInput: true,
1740
- subSchema,
1758
+ subSchema: subSchemaOnly,
1741
1759
  validateWithJSONSchema,
1742
- })
1743
- : schemaComposer.createInputTC({
1744
- name: getValidTypeName({
1745
- schemaComposer,
1746
- isInput: true,
1747
- subSchema,
1748
- }),
1749
- description: subSchema.description,
1750
- fields: inputFieldMap,
1751
- extensions: {
1752
- examples: subSchema.examples,
1753
- default: subSchema.default,
1754
- },
1755
1760
  });
1761
+ }
1762
+ else if (input != null && 'addFields' in input) {
1763
+ input.addFields(inputFieldMap);
1764
+ }
1756
1765
  return {
1757
1766
  input,
1758
1767
  output,
1768
+ nullable: subSchemaAndTypeComposers.nullable,
1759
1769
  };
1760
1770
  }
1761
- logger.warn(`GraphQL Type cannot be created for this JSON Schema definition;`, {
1762
- subSchema,
1763
- path,
1764
- });
1765
- const typeComposer = schemaComposer.getAnyTC(graphqlScalars.GraphQLJSON);
1766
- return {
1767
- input: typeComposer,
1768
- output: typeComposer,
1769
- };
1770
- };
1771
- const result = getTypeComposer();
1772
- return result;
1771
+ if (subSchemaAndTypeComposers.input || subSchemaAndTypeComposers.output) {
1772
+ return {
1773
+ input: subSchemaAndTypeComposers.input,
1774
+ output: subSchemaAndTypeComposers.output,
1775
+ description: subSchemaAndTypeComposers.description,
1776
+ nullable: subSchemaAndTypeComposers.nullable,
1777
+ };
1778
+ }
1779
+ else {
1780
+ logger.warn(`GraphQL Type cannot be created for this JSON Schema definition;`, {
1781
+ subSchema: subSchemaOnly,
1782
+ path,
1783
+ });
1784
+ const typeComposer = schemaComposer.getAnyTC(graphqlScalars.GraphQLJSON);
1785
+ return {
1786
+ input: typeComposer,
1787
+ output: typeComposer,
1788
+ nullable: subSchemaAndTypeComposers.nullable,
1789
+ };
1790
+ }
1791
+ },
1773
1792
  });
1774
1793
  }
1775
1794
 
1776
- async function getGraphQLSchemaFromDereferencedJSONSchema(fullyDeferencedSchema, { fetch, logger, operations, operationHeaders, baseUrl, pubsub, generateInterfaceFromSharedFields, queryParams, queryStringOptions, }) {
1795
+ async function getGraphQLSchemaFromDereferencedJSONSchema(fullyDeferencedSchema, { fetch, logger, operations, operationHeaders, baseUrl, pubsub, queryParams, queryStringOptions, }) {
1777
1796
  logger.debug(`Generating GraphQL Schema from the bundled JSON Schema`);
1778
- const visitorResult = await getComposerFromJSONSchema(fullyDeferencedSchema, logger, generateInterfaceFromSharedFields);
1797
+ const visitorResult = await getComposerFromJSONSchema(fullyDeferencedSchema, logger);
1779
1798
  const schemaComposerWithoutExecutionLogic = visitorResult.output;
1780
1799
  if (!(schemaComposerWithoutExecutionLogic instanceof graphqlCompose.SchemaComposer)) {
1781
1800
  throw new Error('The visitor result should be a SchemaComposer instance.');
@@ -1825,7 +1844,6 @@ async function loadGraphQLSchemaFromJSONSchemas(name, options) {
1825
1844
  operationHeaders: options.operationHeaders,
1826
1845
  baseUrl: options.baseUrl,
1827
1846
  pubsub: options.pubsub,
1828
- generateInterfaceFromSharedFields: options.generateInterfaceFromSharedFields,
1829
1847
  queryParams: options.queryParams,
1830
1848
  queryStringOptions: options.queryStringOptions,
1831
1849
  });