@omnigraph/json-schema 1.0.0-alpha-3fc47d119.0 → 1.0.0-alpha-20230420181317-a95037648
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/README.md +5 -4
- package/cjs/addExecutionLogicToComposer.js +208 -0
- package/cjs/addRootFieldResolver.js +395 -0
- package/cjs/bundle.js +65 -0
- package/cjs/directives.js +580 -0
- package/cjs/getComposerFromJSONSchema.js +1297 -0
- package/cjs/getDereferencedJSONSchemaFromOperations.js +33 -0
- package/cjs/getGraphQLSchemaFromDereferencedJSONSchema.js +39 -0
- package/cjs/getJSONSchemaStringFormatScalarMap.js +61 -0
- package/cjs/getReferencedJSONSchemaFromOperations.js +260 -0
- package/cjs/getTypeResolverFromOutputTCs.js +69 -0
- package/cjs/getUnionTypeComposers.js +85 -0
- package/cjs/getValidTypeName.js +20 -0
- package/cjs/index.js +14 -0
- package/cjs/loadGraphQLSchemaFromJSONSchemas.js +59 -0
- package/cjs/package.json +1 -0
- package/cjs/resolveDataByUnionInputType.js +40 -0
- package/cjs/scalars.js +30 -0
- package/cjs/types.js +0 -0
- package/cjs/utils.js +65 -0
- package/esm/addExecutionLogicToComposer.js +204 -0
- package/esm/addRootFieldResolver.js +390 -0
- package/esm/bundle.js +60 -0
- package/esm/directives.js +565 -0
- package/esm/getComposerFromJSONSchema.js +1293 -0
- package/esm/getDereferencedJSONSchemaFromOperations.js +29 -0
- package/esm/getGraphQLSchemaFromDereferencedJSONSchema.js +35 -0
- package/esm/getJSONSchemaStringFormatScalarMap.js +56 -0
- package/esm/getReferencedJSONSchemaFromOperations.js +255 -0
- package/esm/getTypeResolverFromOutputTCs.js +65 -0
- package/esm/getUnionTypeComposers.js +80 -0
- package/esm/getValidTypeName.js +16 -0
- package/esm/index.js +9 -0
- package/esm/loadGraphQLSchemaFromJSONSchemas.js +54 -0
- package/esm/resolveDataByUnionInputType.js +36 -0
- package/esm/scalars.js +27 -0
- package/esm/types.js +0 -0
- package/esm/utils.js +57 -0
- package/package.json +34 -27
- package/typings/addExecutionLogicToComposer.d.cts +14 -0
- package/typings/addExecutionLogicToComposer.d.ts +14 -0
- package/typings/addRootFieldResolver.d.cts +26 -0
- package/typings/addRootFieldResolver.d.ts +26 -0
- package/typings/bundle.d.cts +34 -0
- package/typings/bundle.d.ts +34 -0
- package/typings/directives.d.cts +54 -0
- package/typings/directives.d.ts +54 -0
- package/typings/getComposerFromJSONSchema.d.cts +13 -0
- package/{getComposerFromJSONSchema.d.ts → typings/getComposerFromJSONSchema.d.ts} +7 -4
- package/typings/getDereferencedJSONSchemaFromOperations.d.cts +14 -0
- package/{getDereferencedJSONSchemaFromOperations.d.ts → typings/getDereferencedJSONSchemaFromOperations.d.ts} +5 -3
- package/typings/getGraphQLSchemaFromDereferencedJSONSchema.d.cts +5 -0
- package/typings/getGraphQLSchemaFromDereferencedJSONSchema.d.ts +5 -0
- package/typings/getJSONSchemaStringFormatScalarMap.d.cts +2 -0
- package/typings/getJSONSchemaStringFormatScalarMap.d.ts +2 -0
- package/typings/getReferencedJSONSchemaFromOperations.d.cts +16 -0
- package/{getReferencedJSONSchemaFromOperations.d.ts → typings/getReferencedJSONSchemaFromOperations.d.ts} +6 -4
- package/typings/getTypeResolverFromOutputTCs.d.cts +7 -0
- package/typings/getTypeResolverFromOutputTCs.d.ts +7 -0
- package/typings/getUnionTypeComposers.d.cts +24 -0
- package/typings/getUnionTypeComposers.d.ts +24 -0
- package/{getStringScalarWithMinMaxLength.d.ts → typings/getValidTypeName.d.cts} +4 -3
- package/typings/index.d.cts +9 -0
- package/typings/index.d.ts +9 -0
- package/typings/loadGraphQLSchemaFromJSONSchemas.d.cts +3 -0
- package/typings/loadGraphQLSchemaFromJSONSchemas.d.ts +3 -0
- package/typings/resolveDataByUnionInputType.d.cts +2 -0
- package/typings/resolveDataByUnionInputType.d.ts +2 -0
- package/typings/scalars.d.cts +4 -0
- package/typings/scalars.d.ts +4 -0
- package/typings/types.d.cts +76 -0
- package/typings/types.d.ts +76 -0
- package/typings/utils.d.cts +15 -0
- package/{utils.d.ts → typings/utils.d.ts} +1 -1
- package/addExecutionLogicToComposer.d.ts +0 -15
- package/bundle.d.ts +0 -39
- package/getGenericJSONScalar.d.ts +0 -8
- package/getGraphQLSchemaFromDereferencedJSONSchema.d.ts +0 -5
- package/getJSONSchemaStringFormatScalarMap.d.ts +0 -3
- package/getTypeResolverFromOutputTCs.d.ts +0 -4
- package/getUnionTypeComposers.d.ts +0 -21
- package/getValidateFnForSchemaPath.d.ts +0 -3
- package/index.d.ts +0 -9
- package/index.js +0 -1890
- package/index.mjs +0 -1877
- package/loadGraphQLSchemaFromJSONSchemas.d.ts +0 -2
- package/resolveDataByUnionInputType.d.ts +0 -3
- package/types.d.ts +0 -63
- package/{getValidTypeName.d.ts → typings/getValidTypeName.d.ts} +1 -1
|
@@ -0,0 +1,1293 @@
|
|
|
1
|
+
/* eslint-disable no-case-declarations */
|
|
2
|
+
import { getNamedType, GraphQLBoolean, GraphQLFloat, GraphQLInt, GraphQLString, isNonNullType, } from 'graphql';
|
|
3
|
+
import { EnumTypeComposer, InterfaceTypeComposer, isSomeInputTypeComposer, ListComposer, ObjectTypeComposer, ScalarTypeComposer, SchemaComposer, UnionTypeComposer, } from 'graphql-compose';
|
|
4
|
+
import { GraphQLBigInt, GraphQLByte, GraphQLDateTime, GraphQLEmailAddress, GraphQLIPv4, GraphQLIPv6, GraphQLJSON, GraphQLNegativeFloat, GraphQLNegativeInt, GraphQLNonEmptyString, GraphQLNonNegativeFloat, GraphQLNonNegativeInt, GraphQLNonPositiveFloat, GraphQLNonPositiveInt, GraphQLPositiveFloat, GraphQLPositiveInt, GraphQLTime, GraphQLTimestamp, GraphQLURL, GraphQLUUID, } from 'graphql-scalars';
|
|
5
|
+
import { visitJSONSchema } from 'json-machete';
|
|
6
|
+
import { sanitizeNameForGraphQL } from '@graphql-mesh/utils';
|
|
7
|
+
import { DictionaryDirective, DiscriminatorDirective, EnumDirective, ExampleDirective, LengthDirective, OneOfDirective, RegExpDirective, ResolveRootDirective, ResolveRootFieldDirective, TypeScriptDirective, } from './directives.js';
|
|
8
|
+
import { getJSONSchemaStringFormatScalarMap } from './getJSONSchemaStringFormatScalarMap.js';
|
|
9
|
+
import { getUnionTypeComposers } from './getUnionTypeComposers.js';
|
|
10
|
+
import { getValidTypeName } from './getValidTypeName.js';
|
|
11
|
+
import { GraphQLFile, GraphQLVoid } from './scalars.js';
|
|
12
|
+
export function getComposerFromJSONSchema(schema, logger) {
|
|
13
|
+
const schemaComposer = new SchemaComposer();
|
|
14
|
+
const formatScalarMap = getJSONSchemaStringFormatScalarMap();
|
|
15
|
+
const rootInputTypeNameComposerMap = {
|
|
16
|
+
QueryInput: () => schemaComposer.Query,
|
|
17
|
+
MutationInput: () => schemaComposer.Mutation,
|
|
18
|
+
SubscriptionInput: () => schemaComposer.Subscription,
|
|
19
|
+
};
|
|
20
|
+
return visitJSONSchema(schema, {
|
|
21
|
+
enter(subSchema, { path, visitedSubschemaResultMap }) {
|
|
22
|
+
var _a, _b, _c, _d, _e, _f;
|
|
23
|
+
if (typeof subSchema === 'boolean' || subSchema.title === 'Any') {
|
|
24
|
+
const typeComposer = schemaComposer.getAnyTC(GraphQLJSON);
|
|
25
|
+
return subSchema
|
|
26
|
+
? {
|
|
27
|
+
input: typeComposer,
|
|
28
|
+
output: typeComposer,
|
|
29
|
+
}
|
|
30
|
+
: undefined;
|
|
31
|
+
}
|
|
32
|
+
if (!subSchema) {
|
|
33
|
+
throw new Error(`Something is wrong with ${path}`);
|
|
34
|
+
}
|
|
35
|
+
if (subSchema.type === 'array') {
|
|
36
|
+
if (subSchema.items != null &&
|
|
37
|
+
typeof subSchema.items === 'object' &&
|
|
38
|
+
Object.keys(subSchema.items).length > 0) {
|
|
39
|
+
return {
|
|
40
|
+
// These are filled after enter
|
|
41
|
+
get input() {
|
|
42
|
+
const typeComposers = visitedSubschemaResultMap.get(subSchema.items);
|
|
43
|
+
return typeComposers.input.getTypePlural();
|
|
44
|
+
},
|
|
45
|
+
get output() {
|
|
46
|
+
const typeComposers = visitedSubschemaResultMap.get(subSchema.items);
|
|
47
|
+
return typeComposers.output.getTypePlural();
|
|
48
|
+
},
|
|
49
|
+
...subSchema,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
if (subSchema.contains) {
|
|
53
|
+
// Scalars cannot be in union type
|
|
54
|
+
const typeComposer = schemaComposer.getAnyTC(GraphQLJSON).getTypePlural();
|
|
55
|
+
return {
|
|
56
|
+
input: typeComposer,
|
|
57
|
+
output: typeComposer,
|
|
58
|
+
nullable: subSchema.nullable,
|
|
59
|
+
readOnly: subSchema.readOnly,
|
|
60
|
+
writeOnly: subSchema.writeOnly,
|
|
61
|
+
default: subSchema.default,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
// If it doesn't have any clue
|
|
65
|
+
{
|
|
66
|
+
// const typeComposer = getGenericJSONScalar({
|
|
67
|
+
// schemaComposer,
|
|
68
|
+
// isInput: false,
|
|
69
|
+
// subSchema,
|
|
70
|
+
// validateWithJSONSchema,
|
|
71
|
+
// }).getTypePlural();
|
|
72
|
+
const typeComposer = schemaComposer.getAnyTC(GraphQLJSON).getTypePlural();
|
|
73
|
+
return {
|
|
74
|
+
input: typeComposer,
|
|
75
|
+
output: typeComposer,
|
|
76
|
+
description: subSchema.description,
|
|
77
|
+
nullable: subSchema.nullable,
|
|
78
|
+
readOnly: subSchema.readOnly,
|
|
79
|
+
writeOnly: subSchema.writeOnly,
|
|
80
|
+
default: subSchema.default,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
if (subSchema.pattern) {
|
|
85
|
+
let typeScriptType;
|
|
86
|
+
switch (subSchema.type) {
|
|
87
|
+
case 'number':
|
|
88
|
+
typeScriptType = 'number';
|
|
89
|
+
break;
|
|
90
|
+
case 'integer':
|
|
91
|
+
if (subSchema.format === 'int64') {
|
|
92
|
+
typeScriptType = 'bigint';
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
typeScriptType = 'number';
|
|
96
|
+
}
|
|
97
|
+
break;
|
|
98
|
+
default:
|
|
99
|
+
typeScriptType = 'string';
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
schemaComposer.addDirective(RegExpDirective);
|
|
103
|
+
schemaComposer.addDirective(TypeScriptDirective);
|
|
104
|
+
const typeComposer = schemaComposer.createScalarTC({
|
|
105
|
+
name: getValidTypeName({
|
|
106
|
+
schemaComposer,
|
|
107
|
+
isInput: false,
|
|
108
|
+
subSchema,
|
|
109
|
+
}),
|
|
110
|
+
directives: [
|
|
111
|
+
{
|
|
112
|
+
name: 'regexp',
|
|
113
|
+
args: {
|
|
114
|
+
pattern: subSchema.pattern,
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
name: 'typescript',
|
|
119
|
+
args: {
|
|
120
|
+
type: typeScriptType,
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
],
|
|
124
|
+
});
|
|
125
|
+
return {
|
|
126
|
+
input: typeComposer,
|
|
127
|
+
output: typeComposer,
|
|
128
|
+
nullable: subSchema.nullable,
|
|
129
|
+
readOnly: subSchema.readOnly,
|
|
130
|
+
writeOnly: subSchema.writeOnly,
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
if (subSchema.const) {
|
|
134
|
+
const scalarTypeName = getValidTypeName({
|
|
135
|
+
schemaComposer,
|
|
136
|
+
isInput: false,
|
|
137
|
+
subSchema,
|
|
138
|
+
});
|
|
139
|
+
schemaComposer.addDirective(EnumDirective);
|
|
140
|
+
schemaComposer.addDirective(TypeScriptDirective);
|
|
141
|
+
schemaComposer.addDirective(ExampleDirective);
|
|
142
|
+
const typeComposer = schemaComposer.createEnumTC({
|
|
143
|
+
name: scalarTypeName,
|
|
144
|
+
values: {
|
|
145
|
+
[sanitizeNameForGraphQL(subSchema.const.toString())]: {
|
|
146
|
+
directives: [
|
|
147
|
+
{
|
|
148
|
+
name: 'enum',
|
|
149
|
+
args: {
|
|
150
|
+
value: JSON.stringify(subSchema.const),
|
|
151
|
+
},
|
|
152
|
+
},
|
|
153
|
+
],
|
|
154
|
+
},
|
|
155
|
+
},
|
|
156
|
+
directives: [
|
|
157
|
+
{
|
|
158
|
+
name: 'typescript',
|
|
159
|
+
args: {
|
|
160
|
+
type: JSON.stringify(subSchema.const),
|
|
161
|
+
},
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
name: 'example',
|
|
165
|
+
args: {
|
|
166
|
+
value: subSchema.const,
|
|
167
|
+
},
|
|
168
|
+
},
|
|
169
|
+
],
|
|
170
|
+
extensions: {
|
|
171
|
+
default: subSchema.const,
|
|
172
|
+
},
|
|
173
|
+
});
|
|
174
|
+
return {
|
|
175
|
+
input: typeComposer,
|
|
176
|
+
output: typeComposer,
|
|
177
|
+
nullable: subSchema.nullable,
|
|
178
|
+
readOnly: subSchema.readOnly,
|
|
179
|
+
writeOnly: subSchema.writeOnly,
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
if (subSchema.enum && subSchema.type !== 'boolean') {
|
|
183
|
+
const values = {};
|
|
184
|
+
for (const value of subSchema.enum) {
|
|
185
|
+
let enumKey = sanitizeNameForGraphQL(value.toString());
|
|
186
|
+
if (enumKey === 'false' || enumKey === 'true' || enumKey === 'null') {
|
|
187
|
+
enumKey = enumKey.toUpperCase();
|
|
188
|
+
}
|
|
189
|
+
if (typeof enumKey === 'string' && enumKey.length === 0) {
|
|
190
|
+
enumKey = '_';
|
|
191
|
+
}
|
|
192
|
+
schemaComposer.addDirective(EnumDirective);
|
|
193
|
+
// Falsy values are ignored by GraphQL
|
|
194
|
+
// eslint-disable-next-line no-unneeded-ternary
|
|
195
|
+
const enumValue = value ? value : value === null || value === void 0 ? void 0 : value.toString();
|
|
196
|
+
const directives = [];
|
|
197
|
+
if (enumValue !== enumKey) {
|
|
198
|
+
directives.push({
|
|
199
|
+
name: 'enum',
|
|
200
|
+
args: {
|
|
201
|
+
value: JSON.stringify(enumValue),
|
|
202
|
+
},
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
values[enumKey] = {
|
|
206
|
+
directives,
|
|
207
|
+
value: enumValue,
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
const directives = [];
|
|
211
|
+
if ((_a = subSchema.examples) === null || _a === void 0 ? void 0 : _a.length) {
|
|
212
|
+
schemaComposer.addDirective(ExampleDirective);
|
|
213
|
+
for (const example of subSchema.examples) {
|
|
214
|
+
directives.push({
|
|
215
|
+
name: 'example',
|
|
216
|
+
args: {
|
|
217
|
+
value: example,
|
|
218
|
+
},
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
const typeComposer = schemaComposer.createEnumTC({
|
|
223
|
+
name: getValidTypeName({
|
|
224
|
+
schemaComposer,
|
|
225
|
+
isInput: false,
|
|
226
|
+
subSchema,
|
|
227
|
+
}),
|
|
228
|
+
values,
|
|
229
|
+
description: subSchema.description,
|
|
230
|
+
directives,
|
|
231
|
+
extensions: {
|
|
232
|
+
default: subSchema.default,
|
|
233
|
+
},
|
|
234
|
+
});
|
|
235
|
+
return {
|
|
236
|
+
input: typeComposer,
|
|
237
|
+
output: typeComposer,
|
|
238
|
+
nullable: subSchema.nullable,
|
|
239
|
+
readOnly: subSchema.readOnly,
|
|
240
|
+
writeOnly: subSchema.writeOnly,
|
|
241
|
+
default: subSchema.default,
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
if (Array.isArray(subSchema.type)) {
|
|
245
|
+
const validTypes = subSchema.type.filter((typeName) => typeName !== 'null');
|
|
246
|
+
if (validTypes.length === 1) {
|
|
247
|
+
subSchema.type = validTypes[0];
|
|
248
|
+
// continue with the single type
|
|
249
|
+
}
|
|
250
|
+
else {
|
|
251
|
+
const typeComposer = schemaComposer.getAnyTC(GraphQLJSON);
|
|
252
|
+
return {
|
|
253
|
+
input: typeComposer,
|
|
254
|
+
output: typeComposer,
|
|
255
|
+
nullable: subSchema.nullable,
|
|
256
|
+
readOnly: subSchema.readOnly,
|
|
257
|
+
writeOnly: subSchema.writeOnly,
|
|
258
|
+
default: subSchema.default,
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
if (subSchema.format) {
|
|
263
|
+
switch (subSchema.format) {
|
|
264
|
+
case 'byte': {
|
|
265
|
+
const typeComposer = schemaComposer.getAnyTC(GraphQLByte);
|
|
266
|
+
return {
|
|
267
|
+
input: typeComposer,
|
|
268
|
+
output: typeComposer,
|
|
269
|
+
description: subSchema.description,
|
|
270
|
+
nullable: subSchema.nullable,
|
|
271
|
+
default: subSchema.default,
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
case 'binary': {
|
|
275
|
+
const typeComposer = schemaComposer.getAnyTC(GraphQLFile);
|
|
276
|
+
return {
|
|
277
|
+
input: typeComposer,
|
|
278
|
+
output: typeComposer,
|
|
279
|
+
description: subSchema.description,
|
|
280
|
+
nullable: subSchema.nullable,
|
|
281
|
+
default: subSchema.default,
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
case 'date-time': {
|
|
285
|
+
const typeComposer = schemaComposer.getAnyTC(GraphQLDateTime);
|
|
286
|
+
return {
|
|
287
|
+
input: typeComposer,
|
|
288
|
+
output: typeComposer,
|
|
289
|
+
description: subSchema.description,
|
|
290
|
+
nullable: subSchema.nullable,
|
|
291
|
+
readOnly: subSchema.readOnly,
|
|
292
|
+
writeOnly: subSchema.writeOnly,
|
|
293
|
+
default: subSchema.default,
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
case 'time': {
|
|
297
|
+
const typeComposer = schemaComposer.getAnyTC(GraphQLTime);
|
|
298
|
+
return {
|
|
299
|
+
input: typeComposer,
|
|
300
|
+
output: typeComposer,
|
|
301
|
+
description: subSchema.description,
|
|
302
|
+
nullable: subSchema.nullable,
|
|
303
|
+
readOnly: subSchema.readOnly,
|
|
304
|
+
writeOnly: subSchema.writeOnly,
|
|
305
|
+
default: subSchema.default,
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
case 'email': {
|
|
309
|
+
const typeComposer = schemaComposer.getAnyTC(GraphQLEmailAddress);
|
|
310
|
+
return {
|
|
311
|
+
input: typeComposer,
|
|
312
|
+
output: typeComposer,
|
|
313
|
+
description: subSchema.description,
|
|
314
|
+
nullable: subSchema.nullable,
|
|
315
|
+
readOnly: subSchema.readOnly,
|
|
316
|
+
writeOnly: subSchema.writeOnly,
|
|
317
|
+
default: subSchema.default,
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
case 'ipv4': {
|
|
321
|
+
const typeComposer = schemaComposer.getAnyTC(GraphQLIPv4);
|
|
322
|
+
return {
|
|
323
|
+
input: typeComposer,
|
|
324
|
+
output: typeComposer,
|
|
325
|
+
description: subSchema.description,
|
|
326
|
+
nullable: subSchema.nullable,
|
|
327
|
+
readOnly: subSchema.readOnly,
|
|
328
|
+
writeOnly: subSchema.writeOnly,
|
|
329
|
+
default: subSchema.default,
|
|
330
|
+
};
|
|
331
|
+
}
|
|
332
|
+
case 'ipv6': {
|
|
333
|
+
const typeComposer = schemaComposer.getAnyTC(GraphQLIPv6);
|
|
334
|
+
return {
|
|
335
|
+
input: typeComposer,
|
|
336
|
+
output: typeComposer,
|
|
337
|
+
description: subSchema.description,
|
|
338
|
+
nullable: subSchema.nullable,
|
|
339
|
+
readOnly: subSchema.readOnly,
|
|
340
|
+
writeOnly: subSchema.writeOnly,
|
|
341
|
+
default: subSchema.default,
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
case 'uri': {
|
|
345
|
+
const typeComposer = schemaComposer.getAnyTC(GraphQLURL);
|
|
346
|
+
return {
|
|
347
|
+
input: typeComposer,
|
|
348
|
+
output: typeComposer,
|
|
349
|
+
description: subSchema.description,
|
|
350
|
+
nullable: subSchema.nullable,
|
|
351
|
+
readOnly: subSchema.readOnly,
|
|
352
|
+
writeOnly: subSchema.writeOnly,
|
|
353
|
+
default: subSchema.default,
|
|
354
|
+
};
|
|
355
|
+
}
|
|
356
|
+
case 'uuid': {
|
|
357
|
+
const typeComposer = schemaComposer.getAnyTC(GraphQLUUID);
|
|
358
|
+
return {
|
|
359
|
+
input: typeComposer,
|
|
360
|
+
output: typeComposer,
|
|
361
|
+
description: subSchema.description,
|
|
362
|
+
nullable: subSchema.nullable,
|
|
363
|
+
readOnly: subSchema.readOnly,
|
|
364
|
+
writeOnly: subSchema.writeOnly,
|
|
365
|
+
default: subSchema.default,
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
case 'unix-time': {
|
|
369
|
+
const typeComposer = schemaComposer.createScalarTC(GraphQLTimestamp);
|
|
370
|
+
return {
|
|
371
|
+
input: typeComposer,
|
|
372
|
+
output: typeComposer,
|
|
373
|
+
description: subSchema.description,
|
|
374
|
+
nullable: subSchema.nullable,
|
|
375
|
+
readOnly: subSchema.readOnly,
|
|
376
|
+
writeOnly: subSchema.writeOnly,
|
|
377
|
+
default: subSchema.default,
|
|
378
|
+
};
|
|
379
|
+
}
|
|
380
|
+
case 'int64': {
|
|
381
|
+
const typeComposer = schemaComposer.createScalarTC(GraphQLBigInt);
|
|
382
|
+
return {
|
|
383
|
+
input: typeComposer,
|
|
384
|
+
output: typeComposer,
|
|
385
|
+
description: subSchema.description,
|
|
386
|
+
nullable: subSchema.nullable,
|
|
387
|
+
readOnly: subSchema.readOnly,
|
|
388
|
+
writeOnly: subSchema.writeOnly,
|
|
389
|
+
default: subSchema.default,
|
|
390
|
+
};
|
|
391
|
+
}
|
|
392
|
+
case 'int32': {
|
|
393
|
+
const typeComposer = schemaComposer.createScalarTC(GraphQLInt);
|
|
394
|
+
return {
|
|
395
|
+
input: typeComposer,
|
|
396
|
+
output: typeComposer,
|
|
397
|
+
description: subSchema.description,
|
|
398
|
+
nullable: subSchema.nullable,
|
|
399
|
+
readOnly: subSchema.readOnly,
|
|
400
|
+
writeOnly: subSchema.writeOnly,
|
|
401
|
+
default: subSchema.default,
|
|
402
|
+
};
|
|
403
|
+
}
|
|
404
|
+
case 'decimal':
|
|
405
|
+
case 'float': {
|
|
406
|
+
const typeComposer = schemaComposer.createScalarTC(GraphQLFloat);
|
|
407
|
+
return {
|
|
408
|
+
input: typeComposer,
|
|
409
|
+
output: typeComposer,
|
|
410
|
+
description: subSchema.description,
|
|
411
|
+
nullable: subSchema.nullable,
|
|
412
|
+
readOnly: subSchema.readOnly,
|
|
413
|
+
writeOnly: subSchema.writeOnly,
|
|
414
|
+
default: subSchema.default,
|
|
415
|
+
};
|
|
416
|
+
}
|
|
417
|
+
default: {
|
|
418
|
+
const formatScalar = formatScalarMap.get(subSchema.format);
|
|
419
|
+
if (formatScalar) {
|
|
420
|
+
const typeComposer = schemaComposer.getAnyTC(formatScalar);
|
|
421
|
+
return {
|
|
422
|
+
input: typeComposer,
|
|
423
|
+
output: typeComposer,
|
|
424
|
+
description: subSchema.description,
|
|
425
|
+
nullable: subSchema.nullable,
|
|
426
|
+
readOnly: subSchema.readOnly,
|
|
427
|
+
writeOnly: subSchema.writeOnly,
|
|
428
|
+
default: subSchema.default,
|
|
429
|
+
};
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
if (subSchema.minimum === 0) {
|
|
435
|
+
const typeComposer = schemaComposer.getAnyTC(subSchema.type === 'integer' ? GraphQLNonNegativeInt : GraphQLNonNegativeFloat);
|
|
436
|
+
return {
|
|
437
|
+
input: typeComposer,
|
|
438
|
+
output: typeComposer,
|
|
439
|
+
description: subSchema.description,
|
|
440
|
+
nullable: subSchema.nullable,
|
|
441
|
+
readOnly: subSchema.readOnly,
|
|
442
|
+
writeOnly: subSchema.writeOnly,
|
|
443
|
+
default: subSchema.default,
|
|
444
|
+
};
|
|
445
|
+
}
|
|
446
|
+
else if (subSchema.minimum > 0) {
|
|
447
|
+
const typeComposer = schemaComposer.getAnyTC(subSchema.type === 'integer' ? GraphQLPositiveInt : GraphQLPositiveFloat);
|
|
448
|
+
return {
|
|
449
|
+
input: typeComposer,
|
|
450
|
+
output: typeComposer,
|
|
451
|
+
description: subSchema.description,
|
|
452
|
+
nullable: subSchema.nullable,
|
|
453
|
+
readOnly: subSchema.readOnly,
|
|
454
|
+
writeOnly: subSchema.writeOnly,
|
|
455
|
+
default: subSchema.default,
|
|
456
|
+
};
|
|
457
|
+
}
|
|
458
|
+
if (subSchema.maximum === 0) {
|
|
459
|
+
const typeComposer = schemaComposer.getAnyTC(subSchema.type === 'integer' ? GraphQLNonPositiveInt : GraphQLNonPositiveFloat);
|
|
460
|
+
return {
|
|
461
|
+
input: typeComposer,
|
|
462
|
+
output: typeComposer,
|
|
463
|
+
description: subSchema.description,
|
|
464
|
+
nullable: subSchema.nullable,
|
|
465
|
+
readOnly: subSchema.readOnly,
|
|
466
|
+
writeOnly: subSchema.writeOnly,
|
|
467
|
+
default: subSchema.default,
|
|
468
|
+
};
|
|
469
|
+
}
|
|
470
|
+
else if (subSchema.maximum < 0) {
|
|
471
|
+
const typeComposer = schemaComposer.getAnyTC(subSchema.type === 'integer' ? GraphQLNegativeInt : GraphQLNegativeFloat);
|
|
472
|
+
return {
|
|
473
|
+
input: typeComposer,
|
|
474
|
+
output: typeComposer,
|
|
475
|
+
description: subSchema.description,
|
|
476
|
+
nullable: subSchema.nullable,
|
|
477
|
+
readOnly: subSchema.readOnly,
|
|
478
|
+
writeOnly: subSchema.writeOnly,
|
|
479
|
+
default: subSchema.default,
|
|
480
|
+
};
|
|
481
|
+
}
|
|
482
|
+
if (subSchema.maximum > Number.MAX_SAFE_INTEGER ||
|
|
483
|
+
subSchema.minimum < Number.MIN_SAFE_INTEGER) {
|
|
484
|
+
const typeComposer = schemaComposer.getAnyTC(GraphQLBigInt);
|
|
485
|
+
return {
|
|
486
|
+
input: typeComposer,
|
|
487
|
+
output: typeComposer,
|
|
488
|
+
description: subSchema.description,
|
|
489
|
+
nullable: subSchema.nullable,
|
|
490
|
+
readOnly: subSchema.readOnly,
|
|
491
|
+
writeOnly: subSchema.writeOnly,
|
|
492
|
+
default: subSchema.default,
|
|
493
|
+
};
|
|
494
|
+
}
|
|
495
|
+
switch (subSchema.type) {
|
|
496
|
+
case 'boolean': {
|
|
497
|
+
const typeComposer = schemaComposer.getAnyTC(GraphQLBoolean);
|
|
498
|
+
return {
|
|
499
|
+
input: typeComposer,
|
|
500
|
+
output: typeComposer,
|
|
501
|
+
description: subSchema.description,
|
|
502
|
+
nullable: subSchema.nullable,
|
|
503
|
+
readOnly: subSchema.readOnly,
|
|
504
|
+
writeOnly: subSchema.writeOnly,
|
|
505
|
+
default: subSchema.default,
|
|
506
|
+
};
|
|
507
|
+
}
|
|
508
|
+
case 'null': {
|
|
509
|
+
const typeComposer = schemaComposer.getAnyTC(GraphQLVoid);
|
|
510
|
+
return {
|
|
511
|
+
input: typeComposer,
|
|
512
|
+
output: typeComposer,
|
|
513
|
+
description: subSchema.description,
|
|
514
|
+
nullable: subSchema.nullable,
|
|
515
|
+
readOnly: subSchema.readOnly,
|
|
516
|
+
writeOnly: subSchema.writeOnly,
|
|
517
|
+
default: subSchema.default,
|
|
518
|
+
};
|
|
519
|
+
}
|
|
520
|
+
case 'integer': {
|
|
521
|
+
const typeComposer = schemaComposer.getAnyTC(GraphQLInt);
|
|
522
|
+
return {
|
|
523
|
+
input: typeComposer,
|
|
524
|
+
output: typeComposer,
|
|
525
|
+
description: subSchema.description,
|
|
526
|
+
nullable: subSchema.nullable,
|
|
527
|
+
readOnly: subSchema.readOnly,
|
|
528
|
+
writeOnly: subSchema.writeOnly,
|
|
529
|
+
default: subSchema.default,
|
|
530
|
+
};
|
|
531
|
+
}
|
|
532
|
+
case 'number': {
|
|
533
|
+
const typeComposer = schemaComposer.getAnyTC(GraphQLFloat);
|
|
534
|
+
return {
|
|
535
|
+
input: typeComposer,
|
|
536
|
+
output: typeComposer,
|
|
537
|
+
description: subSchema.description,
|
|
538
|
+
nullable: subSchema.nullable,
|
|
539
|
+
readOnly: subSchema.readOnly,
|
|
540
|
+
writeOnly: subSchema.writeOnly,
|
|
541
|
+
default: subSchema.default,
|
|
542
|
+
};
|
|
543
|
+
}
|
|
544
|
+
case 'string': {
|
|
545
|
+
if (subSchema.minLength === 1 && subSchema.maxLength == null) {
|
|
546
|
+
const tc = schemaComposer.getAnyTC(GraphQLNonEmptyString);
|
|
547
|
+
return {
|
|
548
|
+
input: tc,
|
|
549
|
+
output: tc,
|
|
550
|
+
description: subSchema.description,
|
|
551
|
+
nullable: subSchema.nullable,
|
|
552
|
+
readOnly: subSchema.readOnly,
|
|
553
|
+
writeOnly: subSchema.writeOnly,
|
|
554
|
+
default: subSchema.default,
|
|
555
|
+
};
|
|
556
|
+
}
|
|
557
|
+
if (subSchema.minLength || subSchema.maxLength) {
|
|
558
|
+
schemaComposer.addDirective(LengthDirective);
|
|
559
|
+
const typeComposer = schemaComposer.createScalarTC({
|
|
560
|
+
name: getValidTypeName({
|
|
561
|
+
schemaComposer,
|
|
562
|
+
isInput: false,
|
|
563
|
+
subSchema,
|
|
564
|
+
}),
|
|
565
|
+
description: subSchema.description,
|
|
566
|
+
directives: [
|
|
567
|
+
{
|
|
568
|
+
name: 'length',
|
|
569
|
+
args: {
|
|
570
|
+
min: subSchema.minLength,
|
|
571
|
+
max: subSchema.maxLength,
|
|
572
|
+
},
|
|
573
|
+
},
|
|
574
|
+
],
|
|
575
|
+
});
|
|
576
|
+
return {
|
|
577
|
+
input: typeComposer,
|
|
578
|
+
output: typeComposer,
|
|
579
|
+
description: subSchema.description,
|
|
580
|
+
nullable: subSchema.nullable,
|
|
581
|
+
readOnly: subSchema.readOnly,
|
|
582
|
+
writeOnly: subSchema.writeOnly,
|
|
583
|
+
default: subSchema.default,
|
|
584
|
+
};
|
|
585
|
+
}
|
|
586
|
+
const typeComposer = schemaComposer.getAnyTC(GraphQLString);
|
|
587
|
+
return {
|
|
588
|
+
input: typeComposer,
|
|
589
|
+
output: typeComposer,
|
|
590
|
+
description: subSchema.description,
|
|
591
|
+
nullable: subSchema.nullable,
|
|
592
|
+
readOnly: subSchema.readOnly,
|
|
593
|
+
writeOnly: subSchema.writeOnly,
|
|
594
|
+
default: subSchema.default,
|
|
595
|
+
};
|
|
596
|
+
}
|
|
597
|
+
case 'object': {
|
|
598
|
+
switch (subSchema.title) {
|
|
599
|
+
case '_schema':
|
|
600
|
+
return {
|
|
601
|
+
output: schemaComposer,
|
|
602
|
+
...subSchema,
|
|
603
|
+
};
|
|
604
|
+
case 'Query':
|
|
605
|
+
return {
|
|
606
|
+
output: schemaComposer.Query,
|
|
607
|
+
...subSchema,
|
|
608
|
+
};
|
|
609
|
+
case 'Mutation':
|
|
610
|
+
return {
|
|
611
|
+
output: schemaComposer.Mutation,
|
|
612
|
+
...subSchema,
|
|
613
|
+
};
|
|
614
|
+
case 'Subscription':
|
|
615
|
+
if (path === '/properties/subscription') {
|
|
616
|
+
return {
|
|
617
|
+
output: schemaComposer.Subscription,
|
|
618
|
+
...subSchema,
|
|
619
|
+
};
|
|
620
|
+
}
|
|
621
|
+
subSchema.title = 'Subscription_';
|
|
622
|
+
break;
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
if (subSchema.oneOf && !subSchema.properties) {
|
|
627
|
+
schemaComposer.addDirective(OneOfDirective);
|
|
628
|
+
const input = schemaComposer.createInputTC({
|
|
629
|
+
name: getValidTypeName({
|
|
630
|
+
schemaComposer,
|
|
631
|
+
isInput: true,
|
|
632
|
+
subSchema,
|
|
633
|
+
}),
|
|
634
|
+
fields: {},
|
|
635
|
+
directives: [
|
|
636
|
+
{
|
|
637
|
+
name: 'oneOf',
|
|
638
|
+
},
|
|
639
|
+
],
|
|
640
|
+
});
|
|
641
|
+
const extensions = {};
|
|
642
|
+
const directives = [];
|
|
643
|
+
if ((_b = subSchema.$comment) === null || _b === void 0 ? void 0 : _b.startsWith('statusCodeOneOfIndexMap:')) {
|
|
644
|
+
const statusCodeOneOfIndexMapStr = subSchema.$comment.replace('statusCodeOneOfIndexMap:', '');
|
|
645
|
+
const statusCodeOneOfIndexMap = JSON.parse(statusCodeOneOfIndexMapStr);
|
|
646
|
+
if (statusCodeOneOfIndexMap) {
|
|
647
|
+
extensions.statusCodeOneOfIndexMap = statusCodeOneOfIndexMap;
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
if ((_c = subSchema.discriminator) === null || _c === void 0 ? void 0 : _c.propertyName) {
|
|
651
|
+
schemaComposer.addDirective(DiscriminatorDirective);
|
|
652
|
+
const mappingByName = {};
|
|
653
|
+
for (const discriminatorValue in subSchema.discriminator.mapping) {
|
|
654
|
+
const ref = subSchema.discriminator.mapping[discriminatorValue];
|
|
655
|
+
const typeName = ref.replace('#/components/schemas/', '');
|
|
656
|
+
mappingByName[discriminatorValue] = typeName;
|
|
657
|
+
}
|
|
658
|
+
directives.push({
|
|
659
|
+
name: 'discriminator',
|
|
660
|
+
args: {
|
|
661
|
+
field: subSchema.discriminator.propertyName,
|
|
662
|
+
mapping: mappingByName,
|
|
663
|
+
},
|
|
664
|
+
});
|
|
665
|
+
}
|
|
666
|
+
const output = schemaComposer.createUnionTC({
|
|
667
|
+
name: getValidTypeName({
|
|
668
|
+
schemaComposer,
|
|
669
|
+
isInput: false,
|
|
670
|
+
subSchema,
|
|
671
|
+
}),
|
|
672
|
+
description: subSchema.description,
|
|
673
|
+
types: [],
|
|
674
|
+
directives,
|
|
675
|
+
extensions,
|
|
676
|
+
});
|
|
677
|
+
return {
|
|
678
|
+
input,
|
|
679
|
+
output,
|
|
680
|
+
...subSchema,
|
|
681
|
+
};
|
|
682
|
+
}
|
|
683
|
+
if (subSchema.properties ||
|
|
684
|
+
subSchema.allOf ||
|
|
685
|
+
subSchema.anyOf ||
|
|
686
|
+
subSchema.additionalProperties) {
|
|
687
|
+
if (subSchema.title === 'Any') {
|
|
688
|
+
const typeComposer = schemaComposer.getAnyTC(GraphQLJSON);
|
|
689
|
+
return {
|
|
690
|
+
input: typeComposer,
|
|
691
|
+
output: typeComposer,
|
|
692
|
+
description: subSchema.description,
|
|
693
|
+
nullable: subSchema.nullable,
|
|
694
|
+
readOnly: subSchema.readOnly,
|
|
695
|
+
writeOnly: subSchema.writeOnly,
|
|
696
|
+
default: subSchema.default,
|
|
697
|
+
};
|
|
698
|
+
}
|
|
699
|
+
const config = {
|
|
700
|
+
name: getValidTypeName({
|
|
701
|
+
schemaComposer,
|
|
702
|
+
isInput: false,
|
|
703
|
+
subSchema,
|
|
704
|
+
}),
|
|
705
|
+
description: subSchema.description,
|
|
706
|
+
fields: {},
|
|
707
|
+
directives: [],
|
|
708
|
+
extensions: {
|
|
709
|
+
default: subSchema.default,
|
|
710
|
+
},
|
|
711
|
+
};
|
|
712
|
+
if ((_d = subSchema.examples) === null || _d === void 0 ? void 0 : _d.length) {
|
|
713
|
+
schemaComposer.addDirective(ExampleDirective);
|
|
714
|
+
for (const example of subSchema.examples) {
|
|
715
|
+
config.directives.push({
|
|
716
|
+
name: 'example',
|
|
717
|
+
args: {
|
|
718
|
+
value: example,
|
|
719
|
+
},
|
|
720
|
+
});
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
if ((_e = subSchema.discriminator) === null || _e === void 0 ? void 0 : _e.propertyName) {
|
|
724
|
+
schemaComposer.addDirective(DiscriminatorDirective);
|
|
725
|
+
}
|
|
726
|
+
const directives = [];
|
|
727
|
+
if ((_f = subSchema.examples) === null || _f === void 0 ? void 0 : _f.length) {
|
|
728
|
+
schemaComposer.addDirective(ExampleDirective);
|
|
729
|
+
for (const example of subSchema.examples) {
|
|
730
|
+
directives.push({
|
|
731
|
+
name: 'example',
|
|
732
|
+
args: {
|
|
733
|
+
value: example,
|
|
734
|
+
},
|
|
735
|
+
});
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
return {
|
|
739
|
+
input: schemaComposer.createInputTC({
|
|
740
|
+
name: getValidTypeName({
|
|
741
|
+
schemaComposer,
|
|
742
|
+
isInput: true,
|
|
743
|
+
subSchema,
|
|
744
|
+
}),
|
|
745
|
+
description: subSchema.description,
|
|
746
|
+
fields: {},
|
|
747
|
+
directives,
|
|
748
|
+
extensions: {
|
|
749
|
+
default: subSchema.default,
|
|
750
|
+
},
|
|
751
|
+
}),
|
|
752
|
+
output: subSchema.discriminator
|
|
753
|
+
? schemaComposer.createInterfaceTC({
|
|
754
|
+
...config,
|
|
755
|
+
resolveType(root) {
|
|
756
|
+
return root[subSchema.discriminator.propertyName];
|
|
757
|
+
},
|
|
758
|
+
directives: [
|
|
759
|
+
{
|
|
760
|
+
name: 'discriminator',
|
|
761
|
+
args: {
|
|
762
|
+
propertyName: subSchema.discriminator.propertyName,
|
|
763
|
+
},
|
|
764
|
+
},
|
|
765
|
+
],
|
|
766
|
+
})
|
|
767
|
+
: schemaComposer.createObjectTC(config),
|
|
768
|
+
...subSchema,
|
|
769
|
+
...(subSchema.properties ? { properties: { ...subSchema.properties } } : {}),
|
|
770
|
+
...(subSchema.allOf ? { allOf: [...subSchema.allOf] } : {}),
|
|
771
|
+
...(subSchema.additionalProperties
|
|
772
|
+
? {
|
|
773
|
+
additionalProperties: subSchema.additionalProperties === true
|
|
774
|
+
? true
|
|
775
|
+
: { ...subSchema.additionalProperties },
|
|
776
|
+
}
|
|
777
|
+
: {}),
|
|
778
|
+
};
|
|
779
|
+
}
|
|
780
|
+
return subSchema;
|
|
781
|
+
},
|
|
782
|
+
leave(subSchemaAndTypeComposers, { path }) {
|
|
783
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
|
|
784
|
+
// const validateWithJSONSchema = getValidateFnForSchemaPath(ajv, path, schema);
|
|
785
|
+
const subSchemaOnly = {
|
|
786
|
+
...subSchemaAndTypeComposers,
|
|
787
|
+
input: undefined,
|
|
788
|
+
output: undefined,
|
|
789
|
+
};
|
|
790
|
+
if (subSchemaAndTypeComposers.oneOf && !subSchemaAndTypeComposers.properties) {
|
|
791
|
+
const isPlural = subSchemaAndTypeComposers.oneOf.some(({ output }) => 'ofType' in output);
|
|
792
|
+
if (isPlural) {
|
|
793
|
+
const { input, output } = getUnionTypeComposers({
|
|
794
|
+
schemaComposer,
|
|
795
|
+
typeComposersList: subSchemaAndTypeComposers.oneOf.map(({ input, output }) => ({
|
|
796
|
+
input: input.ofType || input,
|
|
797
|
+
output: output.ofType || output,
|
|
798
|
+
})),
|
|
799
|
+
subSchemaAndTypeComposers,
|
|
800
|
+
logger,
|
|
801
|
+
});
|
|
802
|
+
return {
|
|
803
|
+
input: input.getTypePlural(),
|
|
804
|
+
output: output.getTypePlural(),
|
|
805
|
+
nullable: subSchemaAndTypeComposers.nullable,
|
|
806
|
+
default: subSchemaAndTypeComposers.default,
|
|
807
|
+
readOnly: subSchemaAndTypeComposers.readOnly,
|
|
808
|
+
writeOnly: subSchemaAndTypeComposers.writeOnly,
|
|
809
|
+
};
|
|
810
|
+
}
|
|
811
|
+
return getUnionTypeComposers({
|
|
812
|
+
schemaComposer,
|
|
813
|
+
typeComposersList: subSchemaAndTypeComposers.oneOf,
|
|
814
|
+
subSchemaAndTypeComposers,
|
|
815
|
+
logger,
|
|
816
|
+
});
|
|
817
|
+
}
|
|
818
|
+
const fieldMap = {};
|
|
819
|
+
const inputFieldMap = {};
|
|
820
|
+
let isList = false;
|
|
821
|
+
if (subSchemaAndTypeComposers.allOf) {
|
|
822
|
+
let ableToUseGraphQLInputObjectType = true;
|
|
823
|
+
for (const maybeTypeComposers of subSchemaAndTypeComposers.allOf) {
|
|
824
|
+
let { input: inputTypeComposer, output: outputTypeComposer } = maybeTypeComposers;
|
|
825
|
+
if (inputTypeComposer instanceof ListComposer) {
|
|
826
|
+
isList = true;
|
|
827
|
+
inputTypeComposer = inputTypeComposer.ofType;
|
|
828
|
+
}
|
|
829
|
+
if (outputTypeComposer instanceof ListComposer) {
|
|
830
|
+
isList = true;
|
|
831
|
+
outputTypeComposer = outputTypeComposer.ofType;
|
|
832
|
+
}
|
|
833
|
+
if (inputTypeComposer instanceof ScalarTypeComposer ||
|
|
834
|
+
inputTypeComposer instanceof EnumTypeComposer) {
|
|
835
|
+
ableToUseGraphQLInputObjectType = false;
|
|
836
|
+
}
|
|
837
|
+
else {
|
|
838
|
+
const inputTypeElemFieldMap = inputTypeComposer.getFields();
|
|
839
|
+
for (const fieldName in inputTypeElemFieldMap) {
|
|
840
|
+
const field = inputTypeElemFieldMap[fieldName];
|
|
841
|
+
inputFieldMap[fieldName] = field;
|
|
842
|
+
}
|
|
843
|
+
}
|
|
844
|
+
if (isSomeInputTypeComposer(outputTypeComposer)) {
|
|
845
|
+
schemaComposer.addDirective(ResolveRootDirective);
|
|
846
|
+
fieldMap[outputTypeComposer.getTypeName()] = {
|
|
847
|
+
type: outputTypeComposer,
|
|
848
|
+
directives: [
|
|
849
|
+
{
|
|
850
|
+
name: 'resolveRoot',
|
|
851
|
+
},
|
|
852
|
+
],
|
|
853
|
+
};
|
|
854
|
+
}
|
|
855
|
+
else if (outputTypeComposer instanceof UnionTypeComposer) {
|
|
856
|
+
const outputTCElems = outputTypeComposer.getTypes();
|
|
857
|
+
for (const outputTCElem of outputTCElems) {
|
|
858
|
+
const outputTypeElemFieldMap = outputTCElem.getFields();
|
|
859
|
+
for (const fieldName in outputTypeElemFieldMap) {
|
|
860
|
+
const field = outputTypeElemFieldMap[fieldName];
|
|
861
|
+
fieldMap[fieldName] = field;
|
|
862
|
+
}
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
else {
|
|
866
|
+
if (outputTypeComposer instanceof InterfaceTypeComposer) {
|
|
867
|
+
subSchemaAndTypeComposers.output.addInterface(outputTypeComposer);
|
|
868
|
+
}
|
|
869
|
+
const typeElemFieldMap = outputTypeComposer.getFields();
|
|
870
|
+
for (const fieldName in typeElemFieldMap) {
|
|
871
|
+
const field = typeElemFieldMap[fieldName];
|
|
872
|
+
fieldMap[fieldName] = field;
|
|
873
|
+
}
|
|
874
|
+
}
|
|
875
|
+
}
|
|
876
|
+
if ((_a = subSchemaAndTypeComposers.examples) === null || _a === void 0 ? void 0 : _a.length) {
|
|
877
|
+
schemaComposer.addDirective(ExampleDirective);
|
|
878
|
+
const directives = subSchemaAndTypeComposers.output.getDirectives() || [];
|
|
879
|
+
for (const example of subSchemaAndTypeComposers.examples) {
|
|
880
|
+
directives.push({
|
|
881
|
+
name: 'example',
|
|
882
|
+
args: {
|
|
883
|
+
value: example,
|
|
884
|
+
},
|
|
885
|
+
});
|
|
886
|
+
}
|
|
887
|
+
subSchemaAndTypeComposers.output.setDirectives(directives);
|
|
888
|
+
}
|
|
889
|
+
subSchemaAndTypeComposers.output.addFields(fieldMap);
|
|
890
|
+
subSchemaAndTypeComposers.output.setExtensions({
|
|
891
|
+
// validateWithJSONSchema,
|
|
892
|
+
default: subSchemaAndTypeComposers.default,
|
|
893
|
+
});
|
|
894
|
+
if (ableToUseGraphQLInputObjectType) {
|
|
895
|
+
subSchemaAndTypeComposers.input.addFields(inputFieldMap);
|
|
896
|
+
if ((_b = subSchemaAndTypeComposers.examples) === null || _b === void 0 ? void 0 : _b.length) {
|
|
897
|
+
schemaComposer.addDirective(ExampleDirective);
|
|
898
|
+
const directives = subSchemaAndTypeComposers.input.getDirectives() || [];
|
|
899
|
+
for (const example of subSchemaAndTypeComposers.examples) {
|
|
900
|
+
directives.push({
|
|
901
|
+
name: 'example',
|
|
902
|
+
args: {
|
|
903
|
+
value: example,
|
|
904
|
+
},
|
|
905
|
+
});
|
|
906
|
+
}
|
|
907
|
+
subSchemaAndTypeComposers.input.setDirectives(directives);
|
|
908
|
+
}
|
|
909
|
+
subSchemaAndTypeComposers.input.setExtensions({
|
|
910
|
+
default: subSchemaAndTypeComposers.default,
|
|
911
|
+
});
|
|
912
|
+
}
|
|
913
|
+
else {
|
|
914
|
+
subSchemaAndTypeComposers.input = schemaComposer.getAnyTC(GraphQLJSON);
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
if (subSchemaAndTypeComposers.anyOf) {
|
|
918
|
+
// It should not have `required` because it is `anyOf` not `allOf`
|
|
919
|
+
let ableToUseGraphQLInputObjectType = true;
|
|
920
|
+
for (const typeComposers of subSchemaAndTypeComposers.anyOf) {
|
|
921
|
+
let { input: inputTypeComposer, output: outputTypeComposer } = typeComposers;
|
|
922
|
+
if (inputTypeComposer instanceof ListComposer ||
|
|
923
|
+
outputTypeComposer instanceof ListComposer) {
|
|
924
|
+
isList = true;
|
|
925
|
+
inputTypeComposer = inputTypeComposer.ofType;
|
|
926
|
+
outputTypeComposer = outputTypeComposer.ofType;
|
|
927
|
+
}
|
|
928
|
+
if (inputTypeComposer instanceof ScalarTypeComposer ||
|
|
929
|
+
inputTypeComposer instanceof EnumTypeComposer) {
|
|
930
|
+
ableToUseGraphQLInputObjectType = false;
|
|
931
|
+
}
|
|
932
|
+
else {
|
|
933
|
+
const inputTypeElemFieldMap = inputTypeComposer.getFields();
|
|
934
|
+
for (const fieldName in inputTypeElemFieldMap) {
|
|
935
|
+
// In case of conflict set it to JSON
|
|
936
|
+
// TODO: But instead we can convert that field into a oneOf of all possible types
|
|
937
|
+
if (inputFieldMap[fieldName]) {
|
|
938
|
+
let existingType = inputFieldMap[fieldName].type;
|
|
939
|
+
if (typeof existingType === 'function') {
|
|
940
|
+
existingType = existingType();
|
|
941
|
+
}
|
|
942
|
+
let newType = inputTypeElemFieldMap[fieldName].type;
|
|
943
|
+
if (typeof newType === 'function') {
|
|
944
|
+
newType = newType();
|
|
945
|
+
}
|
|
946
|
+
const newTypeName = newType.getTypeName().replace('!', '');
|
|
947
|
+
const existingTypeName = existingType.getTypeName().replace('!', '');
|
|
948
|
+
if (existingTypeName !== newTypeName) {
|
|
949
|
+
if (newTypeName !== 'JSON') {
|
|
950
|
+
inputFieldMap[fieldName] = {
|
|
951
|
+
type: schemaComposer.getAnyTC(GraphQLJSON),
|
|
952
|
+
};
|
|
953
|
+
}
|
|
954
|
+
if (existingTypeName === 'JSON') {
|
|
955
|
+
const field = inputTypeElemFieldMap[fieldName];
|
|
956
|
+
inputFieldMap[fieldName] = isNonNullType(field.type.getType())
|
|
957
|
+
? {
|
|
958
|
+
...field,
|
|
959
|
+
type: () => field.type.ofType,
|
|
960
|
+
}
|
|
961
|
+
: field;
|
|
962
|
+
}
|
|
963
|
+
}
|
|
964
|
+
}
|
|
965
|
+
else {
|
|
966
|
+
const field = inputTypeElemFieldMap[fieldName];
|
|
967
|
+
inputFieldMap[fieldName] = isNonNullType(field.type.getType())
|
|
968
|
+
? {
|
|
969
|
+
...field,
|
|
970
|
+
type: () => field.type.ofType,
|
|
971
|
+
}
|
|
972
|
+
: field;
|
|
973
|
+
}
|
|
974
|
+
}
|
|
975
|
+
}
|
|
976
|
+
if (outputTypeComposer instanceof ScalarTypeComposer) {
|
|
977
|
+
const typeName = outputTypeComposer.getTypeName();
|
|
978
|
+
// In case of conflict set it to JSON
|
|
979
|
+
// TODO: But instead we can convert that field into a union of all possible types
|
|
980
|
+
if (fieldMap[typeName]) {
|
|
981
|
+
const existingTypeName = (_d = (_c = fieldMap[typeName]) === null || _c === void 0 ? void 0 : _c.type) === null || _d === void 0 ? void 0 : _d.getTypeName();
|
|
982
|
+
if (existingTypeName === 'JSON') {
|
|
983
|
+
schemaComposer.addDirective(ResolveRootDirective);
|
|
984
|
+
fieldMap[typeName] = {
|
|
985
|
+
type: outputTypeComposer,
|
|
986
|
+
directives: [
|
|
987
|
+
{
|
|
988
|
+
name: 'resolveRoot',
|
|
989
|
+
},
|
|
990
|
+
],
|
|
991
|
+
};
|
|
992
|
+
}
|
|
993
|
+
if (typeName !== 'JSON' && existingTypeName !== typeName) {
|
|
994
|
+
fieldMap[typeName] = {
|
|
995
|
+
type: schemaComposer.getAnyTC(GraphQLJSON),
|
|
996
|
+
};
|
|
997
|
+
}
|
|
998
|
+
}
|
|
999
|
+
else {
|
|
1000
|
+
schemaComposer.addDirective(ResolveRootDirective);
|
|
1001
|
+
fieldMap[typeName] = {
|
|
1002
|
+
type: outputTypeComposer,
|
|
1003
|
+
directives: [
|
|
1004
|
+
{
|
|
1005
|
+
name: 'resolveRoot',
|
|
1006
|
+
},
|
|
1007
|
+
],
|
|
1008
|
+
};
|
|
1009
|
+
}
|
|
1010
|
+
}
|
|
1011
|
+
else {
|
|
1012
|
+
const typeElemFieldMap = outputTypeComposer.getFields();
|
|
1013
|
+
for (const fieldName in typeElemFieldMap) {
|
|
1014
|
+
// In case of conflict set it to JSON
|
|
1015
|
+
// TODO: But instead we can convert that field into a union of all possible types
|
|
1016
|
+
const field = typeElemFieldMap[fieldName];
|
|
1017
|
+
const existingField = fieldMap[fieldName];
|
|
1018
|
+
fieldMap[fieldName] = {
|
|
1019
|
+
...field,
|
|
1020
|
+
type: () => {
|
|
1021
|
+
const fieldType = field.type.getType();
|
|
1022
|
+
const namedType = getNamedType(fieldType);
|
|
1023
|
+
if (existingField) {
|
|
1024
|
+
const existingFieldType = existingField.type();
|
|
1025
|
+
const existingNamedType = getNamedType(existingFieldType);
|
|
1026
|
+
const existingTypeName = existingNamedType.name;
|
|
1027
|
+
const newTypeName = namedType.name;
|
|
1028
|
+
if (existingTypeName !== 'JSON' && existingNamedType.name !== namedType.name) {
|
|
1029
|
+
return schemaComposer.getAnyTC(GraphQLJSON);
|
|
1030
|
+
}
|
|
1031
|
+
if (newTypeName === 'JSON') {
|
|
1032
|
+
return existingFieldType;
|
|
1033
|
+
}
|
|
1034
|
+
}
|
|
1035
|
+
return field.type.getType();
|
|
1036
|
+
},
|
|
1037
|
+
};
|
|
1038
|
+
}
|
|
1039
|
+
}
|
|
1040
|
+
}
|
|
1041
|
+
let outputTypeComposer = subSchemaAndTypeComposers.output;
|
|
1042
|
+
if ('ofType' in outputTypeComposer) {
|
|
1043
|
+
outputTypeComposer = outputTypeComposer.ofType;
|
|
1044
|
+
}
|
|
1045
|
+
outputTypeComposer.addFields(fieldMap);
|
|
1046
|
+
if ((_e = subSchemaAndTypeComposers.examples) === null || _e === void 0 ? void 0 : _e.length) {
|
|
1047
|
+
schemaComposer.addDirective(ExampleDirective);
|
|
1048
|
+
const directives = outputTypeComposer.getDirectives() || [];
|
|
1049
|
+
for (const example of subSchemaAndTypeComposers.examples) {
|
|
1050
|
+
directives.push({
|
|
1051
|
+
name: 'example',
|
|
1052
|
+
args: {
|
|
1053
|
+
value: example,
|
|
1054
|
+
},
|
|
1055
|
+
});
|
|
1056
|
+
}
|
|
1057
|
+
outputTypeComposer.setDirectives(directives);
|
|
1058
|
+
}
|
|
1059
|
+
outputTypeComposer.setExtensions({
|
|
1060
|
+
// validateWithJSONSchema,
|
|
1061
|
+
default: subSchemaAndTypeComposers.default,
|
|
1062
|
+
});
|
|
1063
|
+
let inputTypeComposer = subSchemaAndTypeComposers.input;
|
|
1064
|
+
if ('ofType' in inputTypeComposer) {
|
|
1065
|
+
inputTypeComposer = inputTypeComposer.ofType;
|
|
1066
|
+
}
|
|
1067
|
+
if (ableToUseGraphQLInputObjectType) {
|
|
1068
|
+
inputTypeComposer.addFields(inputFieldMap);
|
|
1069
|
+
if ((_f = subSchemaAndTypeComposers.examples) === null || _f === void 0 ? void 0 : _f.length) {
|
|
1070
|
+
schemaComposer.addDirective(ExampleDirective);
|
|
1071
|
+
const directives = inputTypeComposer.getDirectives() || [];
|
|
1072
|
+
for (const example of subSchemaAndTypeComposers.examples) {
|
|
1073
|
+
directives.push({
|
|
1074
|
+
name: 'example',
|
|
1075
|
+
args: {
|
|
1076
|
+
value: example,
|
|
1077
|
+
},
|
|
1078
|
+
});
|
|
1079
|
+
}
|
|
1080
|
+
inputTypeComposer.setDirectives(directives);
|
|
1081
|
+
}
|
|
1082
|
+
inputTypeComposer.setExtensions({
|
|
1083
|
+
default: subSchemaAndTypeComposers.default,
|
|
1084
|
+
});
|
|
1085
|
+
}
|
|
1086
|
+
else {
|
|
1087
|
+
subSchemaAndTypeComposers.input = schemaComposer.getAnyTC(GraphQLJSON);
|
|
1088
|
+
}
|
|
1089
|
+
}
|
|
1090
|
+
switch (subSchemaAndTypeComposers.type) {
|
|
1091
|
+
case 'object':
|
|
1092
|
+
if (subSchemaAndTypeComposers.properties) {
|
|
1093
|
+
for (const propertyName in subSchemaAndTypeComposers.properties) {
|
|
1094
|
+
// TODO: needs to be fixed
|
|
1095
|
+
if (propertyName === 'additionalProperties') {
|
|
1096
|
+
continue;
|
|
1097
|
+
}
|
|
1098
|
+
const fieldName = sanitizeNameForGraphQL(propertyName);
|
|
1099
|
+
const fieldDirectives = [];
|
|
1100
|
+
if (propertyName !== fieldName) {
|
|
1101
|
+
schemaComposer.addDirective(ResolveRootFieldDirective);
|
|
1102
|
+
fieldDirectives.push({
|
|
1103
|
+
name: 'resolveRootField',
|
|
1104
|
+
args: {
|
|
1105
|
+
field: propertyName,
|
|
1106
|
+
},
|
|
1107
|
+
});
|
|
1108
|
+
}
|
|
1109
|
+
fieldMap[fieldName] = {
|
|
1110
|
+
type: () => {
|
|
1111
|
+
var _a;
|
|
1112
|
+
const typeComposers = subSchemaAndTypeComposers.properties[propertyName];
|
|
1113
|
+
let nullable = true;
|
|
1114
|
+
if ((_a = subSchemaAndTypeComposers.required) === null || _a === void 0 ? void 0 : _a.includes(propertyName)) {
|
|
1115
|
+
nullable = false;
|
|
1116
|
+
}
|
|
1117
|
+
// Nullable has more priority
|
|
1118
|
+
if (typeComposers.nullable === false) {
|
|
1119
|
+
nullable = false;
|
|
1120
|
+
}
|
|
1121
|
+
if (typeComposers.nullable === true) {
|
|
1122
|
+
nullable = true;
|
|
1123
|
+
}
|
|
1124
|
+
if (subSchemaAndTypeComposers.properties[propertyName].writeOnly) {
|
|
1125
|
+
nullable = true;
|
|
1126
|
+
}
|
|
1127
|
+
return !nullable ? typeComposers.output.getTypeNonNull() : typeComposers.output;
|
|
1128
|
+
},
|
|
1129
|
+
// Make sure you get the right property
|
|
1130
|
+
directives: fieldDirectives,
|
|
1131
|
+
description: subSchemaAndTypeComposers.properties[propertyName].description ||
|
|
1132
|
+
((_g = subSchemaAndTypeComposers.properties[propertyName].output) === null || _g === void 0 ? void 0 : _g.description),
|
|
1133
|
+
};
|
|
1134
|
+
const directives = [];
|
|
1135
|
+
if (fieldName !== propertyName) {
|
|
1136
|
+
schemaComposer.addDirective(ResolveRootFieldDirective);
|
|
1137
|
+
directives.push({
|
|
1138
|
+
name: 'resolveRootField',
|
|
1139
|
+
args: {
|
|
1140
|
+
field: propertyName,
|
|
1141
|
+
},
|
|
1142
|
+
});
|
|
1143
|
+
}
|
|
1144
|
+
inputFieldMap[fieldName] = {
|
|
1145
|
+
type: () => {
|
|
1146
|
+
var _a, _b;
|
|
1147
|
+
const typeComposers = subSchemaAndTypeComposers.properties[propertyName];
|
|
1148
|
+
let nullable = true;
|
|
1149
|
+
if ((_a = subSchemaAndTypeComposers.required) === null || _a === void 0 ? void 0 : _a.includes(propertyName)) {
|
|
1150
|
+
nullable = false;
|
|
1151
|
+
}
|
|
1152
|
+
// Nullable has more priority
|
|
1153
|
+
if (typeComposers.nullable === false) {
|
|
1154
|
+
nullable = false;
|
|
1155
|
+
}
|
|
1156
|
+
if (typeComposers.nullable === true) {
|
|
1157
|
+
nullable = true;
|
|
1158
|
+
}
|
|
1159
|
+
if (subSchemaAndTypeComposers.properties[propertyName].readOnly) {
|
|
1160
|
+
nullable = true;
|
|
1161
|
+
}
|
|
1162
|
+
return !nullable ? (_b = typeComposers.input) === null || _b === void 0 ? void 0 : _b.getTypeNonNull() : typeComposers.input;
|
|
1163
|
+
},
|
|
1164
|
+
directives,
|
|
1165
|
+
description: subSchemaAndTypeComposers.properties[propertyName].description ||
|
|
1166
|
+
((_h = subSchemaAndTypeComposers.properties[propertyName].input) === null || _h === void 0 ? void 0 : _h.description),
|
|
1167
|
+
defaultValue: ((_j = subSchemaAndTypeComposers.properties[propertyName]) === null || _j === void 0 ? void 0 : _j.default) ||
|
|
1168
|
+
((_l = (_k = subSchemaAndTypeComposers.properties[propertyName]) === null || _k === void 0 ? void 0 : _k.extensions) === null || _l === void 0 ? void 0 : _l.default) ||
|
|
1169
|
+
((_o = (_m = subSchemaAndTypeComposers.properties[propertyName]) === null || _m === void 0 ? void 0 : _m.input) === null || _o === void 0 ? void 0 : _o.default),
|
|
1170
|
+
};
|
|
1171
|
+
}
|
|
1172
|
+
}
|
|
1173
|
+
if (subSchemaAndTypeComposers.additionalProperties) {
|
|
1174
|
+
// Take a look later
|
|
1175
|
+
if (typeof subSchemaAndTypeComposers.additionalProperties === 'object' &&
|
|
1176
|
+
subSchemaAndTypeComposers.additionalProperties.output instanceof ObjectTypeComposer) {
|
|
1177
|
+
const containerOutputTC = schemaComposer.createObjectTC({
|
|
1178
|
+
name: `${subSchemaAndTypeComposers.additionalProperties.output.getTypeName()}_entry`,
|
|
1179
|
+
fields: {
|
|
1180
|
+
key: {
|
|
1181
|
+
type: 'ID!',
|
|
1182
|
+
},
|
|
1183
|
+
value: {
|
|
1184
|
+
type: subSchemaAndTypeComposers.additionalProperties.output,
|
|
1185
|
+
},
|
|
1186
|
+
},
|
|
1187
|
+
});
|
|
1188
|
+
schemaComposer.addDirective(DictionaryDirective);
|
|
1189
|
+
fieldMap.additionalProperties = {
|
|
1190
|
+
type: containerOutputTC.List,
|
|
1191
|
+
directives: [
|
|
1192
|
+
{
|
|
1193
|
+
name: 'dictionary',
|
|
1194
|
+
},
|
|
1195
|
+
],
|
|
1196
|
+
};
|
|
1197
|
+
}
|
|
1198
|
+
else if (Object.keys(fieldMap).length > 0) {
|
|
1199
|
+
schemaComposer.addDirective(ResolveRootDirective);
|
|
1200
|
+
fieldMap.additionalProperties = {
|
|
1201
|
+
type: GraphQLJSON,
|
|
1202
|
+
directives: [
|
|
1203
|
+
{
|
|
1204
|
+
name: 'resolveRoot',
|
|
1205
|
+
},
|
|
1206
|
+
],
|
|
1207
|
+
};
|
|
1208
|
+
}
|
|
1209
|
+
else {
|
|
1210
|
+
const typeComposer = schemaComposer.getAnyTC(GraphQLJSON);
|
|
1211
|
+
schemaComposer.delete((_q = (_p = subSchemaAndTypeComposers.input) === null || _p === void 0 ? void 0 : _p.getTypeName) === null || _q === void 0 ? void 0 : _q.call(_p));
|
|
1212
|
+
schemaComposer.delete((_s = (_r = subSchemaAndTypeComposers.output) === null || _r === void 0 ? void 0 : _r.getTypeName) === null || _s === void 0 ? void 0 : _s.call(_r));
|
|
1213
|
+
return {
|
|
1214
|
+
input: typeComposer,
|
|
1215
|
+
output: typeComposer,
|
|
1216
|
+
description: subSchemaAndTypeComposers.description,
|
|
1217
|
+
nullable: subSchemaAndTypeComposers.nullable,
|
|
1218
|
+
default: subSchemaAndTypeComposers.default,
|
|
1219
|
+
readOnly: subSchemaAndTypeComposers.readOnly,
|
|
1220
|
+
writeOnly: subSchemaAndTypeComposers.writeOnly,
|
|
1221
|
+
};
|
|
1222
|
+
}
|
|
1223
|
+
}
|
|
1224
|
+
if (subSchemaAndTypeComposers.title in rootInputTypeNameComposerMap) {
|
|
1225
|
+
const typeComposer = rootInputTypeNameComposerMap[subSchemaAndTypeComposers.title]();
|
|
1226
|
+
for (const fieldName in inputFieldMap) {
|
|
1227
|
+
let inputTC = inputFieldMap[fieldName].type();
|
|
1228
|
+
if ('ofType' in inputTC) {
|
|
1229
|
+
inputTC = inputTC.ofType;
|
|
1230
|
+
}
|
|
1231
|
+
typeComposer.addFieldArgs(fieldName, inputTC.getFields());
|
|
1232
|
+
}
|
|
1233
|
+
return {
|
|
1234
|
+
output: typeComposer,
|
|
1235
|
+
};
|
|
1236
|
+
}
|
|
1237
|
+
let output = subSchemaAndTypeComposers.output;
|
|
1238
|
+
if (Object.keys(fieldMap).length === 0) {
|
|
1239
|
+
output = schemaComposer.getAnyTC(GraphQLJSON);
|
|
1240
|
+
}
|
|
1241
|
+
else if ('addFields' in output) {
|
|
1242
|
+
output.addFields(fieldMap);
|
|
1243
|
+
}
|
|
1244
|
+
let input = subSchemaAndTypeComposers.input;
|
|
1245
|
+
if (Object.keys(inputFieldMap).length === 0) {
|
|
1246
|
+
input = schemaComposer.getAnyTC(GraphQLJSON);
|
|
1247
|
+
}
|
|
1248
|
+
else if (input != null && 'addFields' in input) {
|
|
1249
|
+
input.addFields(inputFieldMap);
|
|
1250
|
+
}
|
|
1251
|
+
if (isList) {
|
|
1252
|
+
input = input.List;
|
|
1253
|
+
output = output.List;
|
|
1254
|
+
}
|
|
1255
|
+
return {
|
|
1256
|
+
input,
|
|
1257
|
+
output,
|
|
1258
|
+
nullable: subSchemaAndTypeComposers.nullable,
|
|
1259
|
+
default: subSchemaAndTypeComposers.default,
|
|
1260
|
+
readOnly: subSchemaAndTypeComposers.readOnly,
|
|
1261
|
+
writeOnly: subSchemaAndTypeComposers.writeOnly,
|
|
1262
|
+
};
|
|
1263
|
+
}
|
|
1264
|
+
if (subSchemaAndTypeComposers.input || subSchemaAndTypeComposers.output) {
|
|
1265
|
+
return {
|
|
1266
|
+
input: subSchemaAndTypeComposers.input,
|
|
1267
|
+
output: subSchemaAndTypeComposers.output,
|
|
1268
|
+
description: subSchemaAndTypeComposers.description,
|
|
1269
|
+
nullable: subSchemaAndTypeComposers.nullable,
|
|
1270
|
+
default: subSchemaAndTypeComposers.default,
|
|
1271
|
+
readOnly: subSchemaAndTypeComposers.readOnly,
|
|
1272
|
+
writeOnly: subSchemaAndTypeComposers.writeOnly,
|
|
1273
|
+
};
|
|
1274
|
+
}
|
|
1275
|
+
else {
|
|
1276
|
+
logger.debug(`GraphQL Type cannot be created for this JSON Schema definition;`, {
|
|
1277
|
+
subSchema: subSchemaOnly,
|
|
1278
|
+
path,
|
|
1279
|
+
});
|
|
1280
|
+
const typeComposer = schemaComposer.getAnyTC(GraphQLJSON);
|
|
1281
|
+
return {
|
|
1282
|
+
input: typeComposer,
|
|
1283
|
+
output: typeComposer,
|
|
1284
|
+
description: subSchemaAndTypeComposers.description,
|
|
1285
|
+
nullable: subSchemaAndTypeComposers.nullable,
|
|
1286
|
+
readOnly: subSchemaAndTypeComposers.readOnly,
|
|
1287
|
+
writeOnly: subSchemaAndTypeComposers.writeOnly,
|
|
1288
|
+
default: subSchemaAndTypeComposers.default,
|
|
1289
|
+
};
|
|
1290
|
+
}
|
|
1291
|
+
},
|
|
1292
|
+
});
|
|
1293
|
+
}
|