@effect-gql/core 1.4.8 → 1.4.9
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/builder/index.cjs +391 -519
- package/builder/index.cjs.map +1 -1
- package/builder/index.js +392 -520
- package/builder/index.js.map +1 -1
- package/index.cjs +393 -531
- package/index.cjs.map +1 -1
- package/index.js +394 -532
- package/index.js.map +1 -1
- package/package.json +1 -1
package/builder/index.cjs
CHANGED
|
@@ -49,6 +49,51 @@ var isIntegerType = (ast) => {
|
|
|
49
49
|
}
|
|
50
50
|
return false;
|
|
51
51
|
};
|
|
52
|
+
function handlePrimitiveAST(ast) {
|
|
53
|
+
if (ast._tag === "StringKeyword") return graphql.GraphQLString;
|
|
54
|
+
if (ast._tag === "NumberKeyword") return graphql.GraphQLFloat;
|
|
55
|
+
if (ast._tag === "BooleanKeyword") return graphql.GraphQLBoolean;
|
|
56
|
+
return void 0;
|
|
57
|
+
}
|
|
58
|
+
function handleRefinementAST(ast, convertFn) {
|
|
59
|
+
if (isIntegerType(ast)) {
|
|
60
|
+
return graphql.GraphQLInt;
|
|
61
|
+
}
|
|
62
|
+
return convertFn(S2__namespace.make(ast.from));
|
|
63
|
+
}
|
|
64
|
+
function handleLiteralAST(ast) {
|
|
65
|
+
if (ast._tag !== "Literal") return void 0;
|
|
66
|
+
if (typeof ast.literal === "string") return graphql.GraphQLString;
|
|
67
|
+
if (typeof ast.literal === "number") {
|
|
68
|
+
return Number.isInteger(ast.literal) ? graphql.GraphQLInt : graphql.GraphQLFloat;
|
|
69
|
+
}
|
|
70
|
+
if (typeof ast.literal === "boolean") return graphql.GraphQLBoolean;
|
|
71
|
+
return void 0;
|
|
72
|
+
}
|
|
73
|
+
function handleTupleTypeAST(ast, convertFn) {
|
|
74
|
+
if (ast._tag !== "TupleType") return void 0;
|
|
75
|
+
const elements = ast.elements;
|
|
76
|
+
if (elements.length > 0) {
|
|
77
|
+
const elementSchema = S2__namespace.make(elements[0].type);
|
|
78
|
+
return new graphql.GraphQLList(convertFn(elementSchema));
|
|
79
|
+
}
|
|
80
|
+
return void 0;
|
|
81
|
+
}
|
|
82
|
+
function buildFieldsFromPropertySignatures(propertySignatures, convertFn, isInput) {
|
|
83
|
+
const fields = {};
|
|
84
|
+
for (const field2 of propertySignatures) {
|
|
85
|
+
const fieldName = String(field2.name);
|
|
86
|
+
if (fieldName === "_tag") continue;
|
|
87
|
+
const fieldSchema = S2__namespace.make(field2.type);
|
|
88
|
+
let fieldType = convertFn(fieldSchema);
|
|
89
|
+
const isOptionField = isOptionTransformation(field2.type) || isOptionDeclaration(field2.type);
|
|
90
|
+
if (!field2.isOptional && !isOptionField) {
|
|
91
|
+
fieldType = new graphql.GraphQLNonNull(fieldType);
|
|
92
|
+
}
|
|
93
|
+
fields[fieldName] = { type: fieldType };
|
|
94
|
+
}
|
|
95
|
+
return fields;
|
|
96
|
+
}
|
|
52
97
|
var isOptionDeclaration = (ast) => {
|
|
53
98
|
if (ast._tag === "Declaration") {
|
|
54
99
|
const annotations = ast.annotations;
|
|
@@ -79,42 +124,17 @@ var getOptionInnerType = (ast) => {
|
|
|
79
124
|
};
|
|
80
125
|
var toGraphQLType = (schema) => {
|
|
81
126
|
const ast = schema.ast;
|
|
82
|
-
|
|
83
|
-
if (
|
|
84
|
-
if (ast._tag === "BooleanKeyword") return graphql.GraphQLBoolean;
|
|
127
|
+
const primitiveResult = handlePrimitiveAST(ast);
|
|
128
|
+
if (primitiveResult) return primitiveResult;
|
|
85
129
|
if (ast._tag === "Refinement") {
|
|
86
|
-
|
|
87
|
-
return graphql.GraphQLInt;
|
|
88
|
-
}
|
|
89
|
-
return toGraphQLType(S2__namespace.make(ast.from));
|
|
90
|
-
}
|
|
91
|
-
if (ast._tag === "Literal") {
|
|
92
|
-
if (typeof ast.literal === "string") return graphql.GraphQLString;
|
|
93
|
-
if (typeof ast.literal === "number") {
|
|
94
|
-
return Number.isInteger(ast.literal) ? graphql.GraphQLInt : graphql.GraphQLFloat;
|
|
95
|
-
}
|
|
96
|
-
if (typeof ast.literal === "boolean") return graphql.GraphQLBoolean;
|
|
97
|
-
}
|
|
98
|
-
if (ast._tag === "TupleType") {
|
|
99
|
-
const elements = ast.elements;
|
|
100
|
-
if (elements.length > 0) {
|
|
101
|
-
const elementSchema = S2__namespace.make(elements[0].type);
|
|
102
|
-
return new graphql.GraphQLList(toGraphQLType(elementSchema));
|
|
103
|
-
}
|
|
130
|
+
return handleRefinementAST(ast, toGraphQLType);
|
|
104
131
|
}
|
|
132
|
+
const literalResult = handleLiteralAST(ast);
|
|
133
|
+
if (literalResult) return literalResult;
|
|
134
|
+
const tupleResult = handleTupleTypeAST(ast, toGraphQLType);
|
|
135
|
+
if (tupleResult) return tupleResult;
|
|
105
136
|
if (ast._tag === "TypeLiteral") {
|
|
106
|
-
const fields =
|
|
107
|
-
for (const field2 of ast.propertySignatures) {
|
|
108
|
-
const fieldName = String(field2.name);
|
|
109
|
-
if (fieldName === "_tag") continue;
|
|
110
|
-
const fieldSchema = S2__namespace.make(field2.type);
|
|
111
|
-
let fieldType = toGraphQLType(fieldSchema);
|
|
112
|
-
const isOptionField = isOptionTransformation(field2.type) || isOptionDeclaration(field2.type);
|
|
113
|
-
if (!field2.isOptional && !isOptionField) {
|
|
114
|
-
fieldType = new graphql.GraphQLNonNull(fieldType);
|
|
115
|
-
}
|
|
116
|
-
fields[fieldName] = { type: fieldType };
|
|
117
|
-
}
|
|
137
|
+
const fields = buildFieldsFromPropertySignatures(ast.propertySignatures, toGraphQLType);
|
|
118
138
|
const typeName = schema.annotations?.identifier || `Object_${Math.random().toString(36).slice(2, 11)}`;
|
|
119
139
|
return new graphql.GraphQLObjectType({
|
|
120
140
|
name: typeName,
|
|
@@ -156,42 +176,19 @@ var toGraphQLType = (schema) => {
|
|
|
156
176
|
};
|
|
157
177
|
var toGraphQLInputType = (schema) => {
|
|
158
178
|
const ast = schema.ast;
|
|
159
|
-
|
|
160
|
-
if (
|
|
161
|
-
if (ast._tag === "BooleanKeyword") return graphql.GraphQLBoolean;
|
|
179
|
+
const primitiveResult = handlePrimitiveAST(ast);
|
|
180
|
+
if (primitiveResult) return primitiveResult;
|
|
162
181
|
if (ast._tag === "Refinement") {
|
|
163
|
-
|
|
164
|
-
return graphql.GraphQLInt;
|
|
165
|
-
}
|
|
166
|
-
return toGraphQLInputType(S2__namespace.make(ast.from));
|
|
167
|
-
}
|
|
168
|
-
if (ast._tag === "Literal") {
|
|
169
|
-
if (typeof ast.literal === "string") return graphql.GraphQLString;
|
|
170
|
-
if (typeof ast.literal === "number") {
|
|
171
|
-
return Number.isInteger(ast.literal) ? graphql.GraphQLInt : graphql.GraphQLFloat;
|
|
172
|
-
}
|
|
173
|
-
if (typeof ast.literal === "boolean") return graphql.GraphQLBoolean;
|
|
174
|
-
}
|
|
175
|
-
if (ast._tag === "TupleType") {
|
|
176
|
-
const elements = ast.elements;
|
|
177
|
-
if (elements.length > 0) {
|
|
178
|
-
const elementSchema = S2__namespace.make(elements[0].type);
|
|
179
|
-
return new graphql.GraphQLList(toGraphQLInputType(elementSchema));
|
|
180
|
-
}
|
|
182
|
+
return handleRefinementAST(ast, toGraphQLInputType);
|
|
181
183
|
}
|
|
184
|
+
const literalResult = handleLiteralAST(ast);
|
|
185
|
+
if (literalResult) return literalResult;
|
|
186
|
+
const tupleResult = handleTupleTypeAST(ast, toGraphQLInputType);
|
|
187
|
+
if (tupleResult) return tupleResult;
|
|
182
188
|
if (ast._tag === "TypeLiteral") {
|
|
183
|
-
const fields =
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
if (fieldName === "_tag") continue;
|
|
187
|
-
const fieldSchema = S2__namespace.make(field2.type);
|
|
188
|
-
let fieldType = toGraphQLInputType(fieldSchema);
|
|
189
|
-
const isOptionField = isOptionTransformation(field2.type) || isOptionDeclaration(field2.type);
|
|
190
|
-
if (!field2.isOptional && !isOptionField) {
|
|
191
|
-
fieldType = new graphql.GraphQLNonNull(fieldType);
|
|
192
|
-
}
|
|
193
|
-
fields[fieldName] = { type: fieldType };
|
|
194
|
-
}
|
|
189
|
+
const fields = buildFieldsFromPropertySignatures(
|
|
190
|
+
ast.propertySignatures,
|
|
191
|
+
toGraphQLInputType);
|
|
195
192
|
const typeName = schema.annotations?.identifier || `Input_${Math.random().toString(36).slice(2, 11)}`;
|
|
196
193
|
return new graphql.GraphQLInputObjectType({
|
|
197
194
|
name: typeName,
|
|
@@ -232,18 +229,7 @@ var toGraphQLInputType = (schema) => {
|
|
|
232
229
|
var toGraphQLArgs = (schema) => {
|
|
233
230
|
const ast = schema.ast;
|
|
234
231
|
if (ast._tag === "TypeLiteral") {
|
|
235
|
-
const args =
|
|
236
|
-
for (const field2 of ast.propertySignatures) {
|
|
237
|
-
const fieldName = String(field2.name);
|
|
238
|
-
if (fieldName === "_tag") continue;
|
|
239
|
-
const fieldSchema = S2__namespace.make(field2.type);
|
|
240
|
-
let fieldType = toGraphQLInputType(fieldSchema);
|
|
241
|
-
const isOptionField = isOptionTransformation(field2.type) || isOptionDeclaration(field2.type);
|
|
242
|
-
if (!field2.isOptional && !isOptionField) {
|
|
243
|
-
fieldType = new graphql.GraphQLNonNull(fieldType);
|
|
244
|
-
}
|
|
245
|
-
args[fieldName] = { type: fieldType };
|
|
246
|
-
}
|
|
232
|
+
const args = buildFieldsFromPropertySignatures(ast.propertySignatures, toGraphQLInputType);
|
|
247
233
|
return args;
|
|
248
234
|
}
|
|
249
235
|
throw new Error(`Schema must be an object type to convert to GraphQL arguments`);
|
|
@@ -359,7 +345,7 @@ function toGraphQLTypeWithRegistry(schema, ctx) {
|
|
|
359
345
|
if (enumType2) return enumType2;
|
|
360
346
|
}
|
|
361
347
|
if (ast._tag === "TupleType") {
|
|
362
|
-
return
|
|
348
|
+
return handleTupleTypeAST2(ast, ctx);
|
|
363
349
|
}
|
|
364
350
|
if (ast._tag === "Declaration") {
|
|
365
351
|
if (isOptionDeclaration2(ast)) {
|
|
@@ -415,88 +401,112 @@ function getOptionInnerType2(ast) {
|
|
|
415
401
|
}
|
|
416
402
|
return void 0;
|
|
417
403
|
}
|
|
418
|
-
function
|
|
419
|
-
const
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
if (
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
const result = ctx.typeRegistry.get(typeName);
|
|
429
|
-
if (result) return result;
|
|
430
|
-
}
|
|
431
|
-
for (const [regTypeName, typeReg] of ctx.types) {
|
|
432
|
-
if (typeReg.schema.ast === memberAst) {
|
|
433
|
-
const result = ctx.typeRegistry.get(regTypeName);
|
|
434
|
-
if (result) return result;
|
|
435
|
-
}
|
|
436
|
-
}
|
|
437
|
-
if (memberAst._tag === "Transformation") {
|
|
438
|
-
const innerToAst = memberAst.to;
|
|
439
|
-
const transformedTypeName = ctx.astToTypeName?.get(innerToAst);
|
|
440
|
-
if (transformedTypeName) {
|
|
441
|
-
const result = ctx.typeRegistry.get(transformedTypeName);
|
|
442
|
-
if (result) return result;
|
|
443
|
-
}
|
|
444
|
-
for (const [regTypeName, typeReg] of ctx.types) {
|
|
445
|
-
if (typeReg.schema.ast === innerToAst) {
|
|
446
|
-
const result = ctx.typeRegistry.get(regTypeName);
|
|
447
|
-
if (result) return result;
|
|
448
|
-
}
|
|
449
|
-
}
|
|
450
|
-
}
|
|
451
|
-
if (memberAst._tag === "TypeLiteral") {
|
|
452
|
-
const valueField = memberAst.propertySignatures?.find(
|
|
453
|
-
(p) => String(p.name) === "value"
|
|
454
|
-
);
|
|
455
|
-
if (valueField) {
|
|
456
|
-
const valueType = valueField.type;
|
|
457
|
-
const valueTypeName = ctx.astToTypeName?.get(valueType);
|
|
458
|
-
if (valueTypeName) {
|
|
459
|
-
const result = ctx.typeRegistry.get(valueTypeName);
|
|
460
|
-
if (result) return result;
|
|
461
|
-
}
|
|
462
|
-
for (const [regTypeName, typeReg] of ctx.types) {
|
|
463
|
-
if (typeReg.schema.ast === valueType) {
|
|
464
|
-
const result = ctx.typeRegistry.get(regTypeName);
|
|
465
|
-
if (result) return result;
|
|
466
|
-
}
|
|
467
|
-
let regAst = typeReg.schema.ast;
|
|
468
|
-
while (regAst._tag === "Transformation") {
|
|
469
|
-
regAst = regAst.to;
|
|
470
|
-
if (regAst === valueType) {
|
|
471
|
-
const result = ctx.typeRegistry.get(regTypeName);
|
|
472
|
-
if (result) return result;
|
|
473
|
-
}
|
|
474
|
-
}
|
|
475
|
-
}
|
|
476
|
-
const innerResult = toGraphQLTypeWithRegistry(S2__namespace.make(valueType), ctx);
|
|
477
|
-
if (innerResult) return innerResult;
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
}
|
|
404
|
+
function findRegisteredTypeForAST(memberAst, ctx) {
|
|
405
|
+
const typeName = ctx.astToTypeName?.get(memberAst);
|
|
406
|
+
if (typeName) {
|
|
407
|
+
const result = ctx.typeRegistry.get(typeName);
|
|
408
|
+
if (result) return result;
|
|
409
|
+
}
|
|
410
|
+
for (const [regTypeName, typeReg] of ctx.types) {
|
|
411
|
+
if (typeReg.schema.ast === memberAst) {
|
|
412
|
+
const result = ctx.typeRegistry.get(regTypeName);
|
|
413
|
+
if (result) return result;
|
|
481
414
|
}
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
415
|
+
}
|
|
416
|
+
return void 0;
|
|
417
|
+
}
|
|
418
|
+
function findRegisteredTypeForTransformation(memberAst, ctx) {
|
|
419
|
+
if (memberAst._tag !== "Transformation") return void 0;
|
|
420
|
+
const innerToAst = memberAst.to;
|
|
421
|
+
const transformedTypeName = ctx.astToTypeName?.get(innerToAst);
|
|
422
|
+
if (transformedTypeName) {
|
|
423
|
+
const result = ctx.typeRegistry.get(transformedTypeName);
|
|
424
|
+
if (result) return result;
|
|
425
|
+
}
|
|
426
|
+
for (const [regTypeName, typeReg] of ctx.types) {
|
|
427
|
+
if (typeReg.schema.ast === innerToAst) {
|
|
428
|
+
const result = ctx.typeRegistry.get(regTypeName);
|
|
429
|
+
if (result) return result;
|
|
485
430
|
}
|
|
486
431
|
}
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
432
|
+
return void 0;
|
|
433
|
+
}
|
|
434
|
+
function findRegisteredTypeForOptionSome(memberAst, ctx) {
|
|
435
|
+
if (memberAst._tag !== "TypeLiteral") return void 0;
|
|
436
|
+
const valueField = memberAst.propertySignatures?.find(
|
|
437
|
+
(p) => String(p.name) === "value"
|
|
438
|
+
);
|
|
439
|
+
if (!valueField) return void 0;
|
|
440
|
+
const valueType = valueField.type;
|
|
441
|
+
const valueTypeName = ctx.astToTypeName?.get(valueType);
|
|
442
|
+
if (valueTypeName) {
|
|
443
|
+
const result = ctx.typeRegistry.get(valueTypeName);
|
|
444
|
+
if (result) return result;
|
|
445
|
+
}
|
|
446
|
+
for (const [regTypeName, typeReg] of ctx.types) {
|
|
447
|
+
if (typeReg.schema.ast === valueType) {
|
|
448
|
+
const result = ctx.typeRegistry.get(regTypeName);
|
|
449
|
+
if (result) return result;
|
|
450
|
+
}
|
|
451
|
+
let regAst = typeReg.schema.ast;
|
|
452
|
+
while (regAst._tag === "Transformation") {
|
|
453
|
+
regAst = regAst.to;
|
|
454
|
+
if (regAst === valueType) {
|
|
455
|
+
const result = ctx.typeRegistry.get(regTypeName);
|
|
456
|
+
if (result) return result;
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
const innerResult = toGraphQLTypeWithRegistry(S2__namespace.make(valueType), ctx);
|
|
461
|
+
return innerResult;
|
|
462
|
+
}
|
|
463
|
+
function handleOptionTransformation(ast, fromAst, toAst, ctx) {
|
|
464
|
+
if (fromAst && fromAst._tag === "Union") {
|
|
465
|
+
for (const memberAst of fromAst.types) {
|
|
466
|
+
if (memberAst._tag === "Literal") continue;
|
|
467
|
+
if (memberAst._tag === "UndefinedKeyword") continue;
|
|
468
|
+
const registeredType = findRegisteredTypeForAST(memberAst, ctx) || findRegisteredTypeForTransformation(memberAst, ctx) || findRegisteredTypeForOptionSome(memberAst, ctx);
|
|
469
|
+
if (registeredType) return registeredType;
|
|
496
470
|
}
|
|
497
471
|
}
|
|
472
|
+
const innerType = getOptionInnerType2(toAst);
|
|
473
|
+
if (innerType) {
|
|
474
|
+
return toGraphQLTypeWithRegistry(S2__namespace.make(innerType), ctx);
|
|
475
|
+
}
|
|
476
|
+
return void 0;
|
|
477
|
+
}
|
|
478
|
+
function handleArrayTransformation(toAst, ctx) {
|
|
479
|
+
if (toAst._tag !== "TupleType") return void 0;
|
|
480
|
+
let elementType;
|
|
481
|
+
if (toAst.rest && toAst.rest.length > 0) {
|
|
482
|
+
const elementSchema = S2__namespace.make(toAst.rest[0].type);
|
|
483
|
+
elementType = toGraphQLTypeWithRegistry(elementSchema, ctx);
|
|
484
|
+
} else if (toAst.elements.length > 0) {
|
|
485
|
+
const elementSchema = S2__namespace.make(toAst.elements[0].type);
|
|
486
|
+
elementType = toGraphQLTypeWithRegistry(elementSchema, ctx);
|
|
487
|
+
} else {
|
|
488
|
+
return void 0;
|
|
489
|
+
}
|
|
490
|
+
return new graphql.GraphQLList(elementType);
|
|
491
|
+
}
|
|
492
|
+
function handleTransformationAST(ast, ctx) {
|
|
493
|
+
const toAst = ast.to;
|
|
494
|
+
const fromAst = ast.from;
|
|
495
|
+
if (isOptionDeclaration2(toAst)) {
|
|
496
|
+
const optionResult = handleOptionTransformation(ast, fromAst, toAst, ctx);
|
|
497
|
+
if (optionResult) return optionResult;
|
|
498
|
+
}
|
|
499
|
+
const arrayResult = handleArrayTransformation(toAst, ctx);
|
|
500
|
+
if (arrayResult) return arrayResult;
|
|
498
501
|
return toGraphQLTypeWithRegistry(S2__namespace.make(ast.to), ctx);
|
|
499
502
|
}
|
|
503
|
+
function findRegisteredTypeInUnionMembers(types, ctx) {
|
|
504
|
+
for (const memberAst of types) {
|
|
505
|
+
const registeredType = findRegisteredTypeForAST(memberAst, ctx) || findRegisteredTypeForTransformation(memberAst, ctx) || findRegisteredTypeForOptionSome(memberAst, ctx);
|
|
506
|
+
if (registeredType) return registeredType;
|
|
507
|
+
}
|
|
508
|
+
return void 0;
|
|
509
|
+
}
|
|
500
510
|
function handleUnionAST(ast, ctx) {
|
|
501
511
|
const allLiterals = ast.types.every((t) => t._tag === "Literal");
|
|
502
512
|
if (allLiterals) {
|
|
@@ -506,64 +516,8 @@ function handleUnionAST(ast, ctx) {
|
|
|
506
516
|
const unionType2 = findRegisteredUnion(ast.types, ctx);
|
|
507
517
|
if (unionType2) return unionType2;
|
|
508
518
|
}
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
if (typeName) {
|
|
512
|
-
const result = ctx.typeRegistry.get(typeName);
|
|
513
|
-
if (result) return result;
|
|
514
|
-
}
|
|
515
|
-
for (const [regTypeName, typeReg] of ctx.types) {
|
|
516
|
-
if (typeReg.schema.ast === memberAst) {
|
|
517
|
-
const result = ctx.typeRegistry.get(regTypeName);
|
|
518
|
-
if (result) return result;
|
|
519
|
-
}
|
|
520
|
-
}
|
|
521
|
-
if (memberAst._tag === "Transformation") {
|
|
522
|
-
const toAst = memberAst.to;
|
|
523
|
-
const transformedTypeName = ctx.astToTypeName?.get(toAst);
|
|
524
|
-
if (transformedTypeName) {
|
|
525
|
-
const result = ctx.typeRegistry.get(transformedTypeName);
|
|
526
|
-
if (result) return result;
|
|
527
|
-
}
|
|
528
|
-
for (const [regTypeName, typeReg] of ctx.types) {
|
|
529
|
-
if (typeReg.schema.ast === toAst) {
|
|
530
|
-
const result = ctx.typeRegistry.get(regTypeName);
|
|
531
|
-
if (result) return result;
|
|
532
|
-
}
|
|
533
|
-
}
|
|
534
|
-
}
|
|
535
|
-
if (memberAst._tag === "TypeLiteral") {
|
|
536
|
-
const valueField = memberAst.propertySignatures?.find(
|
|
537
|
-
(p) => String(p.name) === "value"
|
|
538
|
-
);
|
|
539
|
-
if (valueField) {
|
|
540
|
-
const valueType = valueField.type;
|
|
541
|
-
const valueTypeName = ctx.astToTypeName?.get(valueType);
|
|
542
|
-
if (valueTypeName) {
|
|
543
|
-
const result = ctx.typeRegistry.get(valueTypeName);
|
|
544
|
-
if (result) return result;
|
|
545
|
-
}
|
|
546
|
-
for (const [regTypeName, typeReg] of ctx.types) {
|
|
547
|
-
if (typeReg.schema.ast === valueType) {
|
|
548
|
-
const result = ctx.typeRegistry.get(regTypeName);
|
|
549
|
-
if (result) return result;
|
|
550
|
-
}
|
|
551
|
-
let regAst = typeReg.schema.ast;
|
|
552
|
-
while (regAst._tag === "Transformation") {
|
|
553
|
-
regAst = regAst.to;
|
|
554
|
-
if (regAst === valueType) {
|
|
555
|
-
const result = ctx.typeRegistry.get(regTypeName);
|
|
556
|
-
if (result) return result;
|
|
557
|
-
}
|
|
558
|
-
}
|
|
559
|
-
}
|
|
560
|
-
const innerResult = toGraphQLTypeWithRegistry(S2__namespace.make(valueType), ctx);
|
|
561
|
-
if (innerResult) {
|
|
562
|
-
return innerResult;
|
|
563
|
-
}
|
|
564
|
-
}
|
|
565
|
-
}
|
|
566
|
-
}
|
|
519
|
+
const registeredType = findRegisteredTypeInUnionMembers(ast.types, ctx);
|
|
520
|
+
if (registeredType) return registeredType;
|
|
567
521
|
if (ast.types.length > 0) {
|
|
568
522
|
return toGraphQLTypeWithRegistry(S2__namespace.make(ast.types[0]), ctx);
|
|
569
523
|
}
|
|
@@ -608,7 +562,7 @@ function findEnumForLiteral(ast, ctx) {
|
|
|
608
562
|
}
|
|
609
563
|
return void 0;
|
|
610
564
|
}
|
|
611
|
-
function
|
|
565
|
+
function handleTupleTypeAST2(ast, ctx) {
|
|
612
566
|
if (ast.rest && ast.rest.length > 0) {
|
|
613
567
|
const elementSchema = S2__namespace.make(ast.rest[0].type);
|
|
614
568
|
const elementType = toGraphQLTypeWithRegistry(elementSchema, ctx);
|
|
@@ -708,170 +662,40 @@ function buildInputTypeLookupCache(inputs, enums) {
|
|
|
708
662
|
}
|
|
709
663
|
return cache;
|
|
710
664
|
}
|
|
711
|
-
function
|
|
712
|
-
const ast = schema.ast;
|
|
665
|
+
function findRegisteredInputType(schema, ast, inputs, inputRegistry, cache) {
|
|
713
666
|
if (cache?.schemaToInputName || cache?.astToInputName) {
|
|
714
667
|
const inputName = cache.schemaToInputName?.get(schema) ?? cache.astToInputName?.get(ast);
|
|
715
668
|
if (inputName) {
|
|
716
|
-
|
|
717
|
-
if (result) return result;
|
|
669
|
+
return inputRegistry.get(inputName);
|
|
718
670
|
}
|
|
719
671
|
} else {
|
|
720
672
|
for (const [inputName, inputReg] of inputs) {
|
|
721
673
|
if (inputReg.schema.ast === ast || inputReg.schema === schema) {
|
|
722
|
-
|
|
723
|
-
if (result) return result;
|
|
674
|
+
return inputRegistry.get(inputName);
|
|
724
675
|
}
|
|
725
676
|
}
|
|
726
677
|
}
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
inputs,
|
|
743
|
-
enums,
|
|
744
|
-
cache
|
|
745
|
-
);
|
|
746
|
-
}
|
|
747
|
-
}
|
|
748
|
-
for (const [, inputReg] of inputs) {
|
|
749
|
-
if (inputReg.schema.ast === memberAst) {
|
|
750
|
-
return toGraphQLInputTypeWithRegistry(
|
|
751
|
-
inputReg.schema,
|
|
752
|
-
enumRegistry,
|
|
753
|
-
inputRegistry,
|
|
754
|
-
inputs,
|
|
755
|
-
enums,
|
|
756
|
-
cache
|
|
757
|
-
);
|
|
758
|
-
}
|
|
759
|
-
}
|
|
760
|
-
if (memberAst._tag === "Transformation") {
|
|
761
|
-
const innerToAst = memberAst.to;
|
|
762
|
-
const transformedInputName = cache?.astToInputName?.get(innerToAst);
|
|
763
|
-
if (transformedInputName) {
|
|
764
|
-
const inputReg = inputs.get(transformedInputName);
|
|
765
|
-
if (inputReg) {
|
|
766
|
-
return toGraphQLInputTypeWithRegistry(
|
|
767
|
-
inputReg.schema,
|
|
768
|
-
enumRegistry,
|
|
769
|
-
inputRegistry,
|
|
770
|
-
inputs,
|
|
771
|
-
enums,
|
|
772
|
-
cache
|
|
773
|
-
);
|
|
774
|
-
}
|
|
775
|
-
}
|
|
776
|
-
for (const [, inputReg] of inputs) {
|
|
777
|
-
if (inputReg.schema.ast === innerToAst) {
|
|
778
|
-
return toGraphQLInputTypeWithRegistry(
|
|
779
|
-
inputReg.schema,
|
|
780
|
-
enumRegistry,
|
|
781
|
-
inputRegistry,
|
|
782
|
-
inputs,
|
|
783
|
-
enums,
|
|
784
|
-
cache
|
|
785
|
-
);
|
|
786
|
-
}
|
|
787
|
-
}
|
|
788
|
-
}
|
|
789
|
-
if (memberAst._tag === "TypeLiteral") {
|
|
790
|
-
const valueField = memberAst.propertySignatures?.find(
|
|
791
|
-
(p) => String(p.name) === "value"
|
|
792
|
-
);
|
|
793
|
-
if (valueField) {
|
|
794
|
-
const valueType = valueField.type;
|
|
795
|
-
const valueInputName = cache?.astToInputName?.get(valueType);
|
|
796
|
-
if (valueInputName) {
|
|
797
|
-
const inputReg = inputs.get(valueInputName);
|
|
798
|
-
if (inputReg) {
|
|
799
|
-
return toGraphQLInputTypeWithRegistry(
|
|
800
|
-
inputReg.schema,
|
|
801
|
-
enumRegistry,
|
|
802
|
-
inputRegistry,
|
|
803
|
-
inputs,
|
|
804
|
-
enums,
|
|
805
|
-
cache
|
|
806
|
-
);
|
|
807
|
-
}
|
|
808
|
-
}
|
|
809
|
-
for (const [, inputReg] of inputs) {
|
|
810
|
-
if (inputReg.schema.ast === valueType) {
|
|
811
|
-
return toGraphQLInputTypeWithRegistry(
|
|
812
|
-
inputReg.schema,
|
|
813
|
-
enumRegistry,
|
|
814
|
-
inputRegistry,
|
|
815
|
-
inputs,
|
|
816
|
-
enums,
|
|
817
|
-
cache
|
|
818
|
-
);
|
|
819
|
-
}
|
|
820
|
-
let regAst = inputReg.schema.ast;
|
|
821
|
-
while (regAst._tag === "Transformation") {
|
|
822
|
-
regAst = regAst.to;
|
|
823
|
-
if (regAst === valueType) {
|
|
824
|
-
return toGraphQLInputTypeWithRegistry(
|
|
825
|
-
inputReg.schema,
|
|
826
|
-
enumRegistry,
|
|
827
|
-
inputRegistry,
|
|
828
|
-
inputs,
|
|
829
|
-
enums,
|
|
830
|
-
cache
|
|
831
|
-
);
|
|
832
|
-
}
|
|
833
|
-
}
|
|
834
|
-
if (regAst._tag === "Declaration" && regAst.typeParameters?.[0] === valueType) {
|
|
835
|
-
return toGraphQLInputTypeWithRegistry(
|
|
836
|
-
inputReg.schema,
|
|
837
|
-
enumRegistry,
|
|
838
|
-
inputRegistry,
|
|
839
|
-
inputs,
|
|
840
|
-
enums,
|
|
841
|
-
cache
|
|
842
|
-
);
|
|
843
|
-
}
|
|
844
|
-
}
|
|
845
|
-
const innerResult = toGraphQLInputTypeWithRegistry(
|
|
846
|
-
S2__namespace.make(valueType),
|
|
847
|
-
enumRegistry,
|
|
848
|
-
inputRegistry,
|
|
849
|
-
inputs,
|
|
850
|
-
enums,
|
|
851
|
-
cache
|
|
852
|
-
);
|
|
853
|
-
if (innerResult) {
|
|
854
|
-
return innerResult;
|
|
855
|
-
}
|
|
856
|
-
}
|
|
857
|
-
}
|
|
858
|
-
}
|
|
678
|
+
return void 0;
|
|
679
|
+
}
|
|
680
|
+
function findRegisteredInputForAST(memberAst, inputs, inputRegistry, enumRegistry, enums, cache) {
|
|
681
|
+
const inputName = cache?.astToInputName?.get(memberAst);
|
|
682
|
+
if (inputName) {
|
|
683
|
+
const inputReg = inputs.get(inputName);
|
|
684
|
+
if (inputReg) {
|
|
685
|
+
return toGraphQLInputTypeWithRegistry(
|
|
686
|
+
inputReg.schema,
|
|
687
|
+
enumRegistry,
|
|
688
|
+
inputRegistry,
|
|
689
|
+
inputs,
|
|
690
|
+
enums,
|
|
691
|
+
cache
|
|
692
|
+
);
|
|
859
693
|
}
|
|
860
|
-
return toGraphQLInputTypeWithRegistry(
|
|
861
|
-
S2__namespace.make(toAst),
|
|
862
|
-
enumRegistry,
|
|
863
|
-
inputRegistry,
|
|
864
|
-
inputs,
|
|
865
|
-
enums,
|
|
866
|
-
cache
|
|
867
|
-
);
|
|
868
694
|
}
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
const nonUndefinedTypes = unionAst.types.filter((t) => t._tag !== "UndefinedKeyword");
|
|
872
|
-
if (nonUndefinedTypes.length === 1 && nonUndefinedTypes[0]._tag === "Union") {
|
|
695
|
+
for (const [, inputReg] of inputs) {
|
|
696
|
+
if (inputReg.schema.ast === memberAst) {
|
|
873
697
|
return toGraphQLInputTypeWithRegistry(
|
|
874
|
-
|
|
698
|
+
inputReg.schema,
|
|
875
699
|
enumRegistry,
|
|
876
700
|
inputRegistry,
|
|
877
701
|
inputs,
|
|
@@ -879,9 +703,18 @@ function toGraphQLInputTypeWithRegistry(schema, enumRegistry, inputRegistry, inp
|
|
|
879
703
|
cache
|
|
880
704
|
);
|
|
881
705
|
}
|
|
882
|
-
|
|
706
|
+
}
|
|
707
|
+
return void 0;
|
|
708
|
+
}
|
|
709
|
+
function findRegisteredInputForTransformation(memberAst, inputs, inputRegistry, enumRegistry, enums, cache) {
|
|
710
|
+
if (memberAst._tag !== "Transformation") return void 0;
|
|
711
|
+
const innerToAst = memberAst.to;
|
|
712
|
+
const transformedInputName = cache?.astToInputName?.get(innerToAst);
|
|
713
|
+
if (transformedInputName) {
|
|
714
|
+
const inputReg = inputs.get(transformedInputName);
|
|
715
|
+
if (inputReg) {
|
|
883
716
|
return toGraphQLInputTypeWithRegistry(
|
|
884
|
-
|
|
717
|
+
inputReg.schema,
|
|
885
718
|
enumRegistry,
|
|
886
719
|
inputRegistry,
|
|
887
720
|
inputs,
|
|
@@ -889,171 +722,210 @@ function toGraphQLInputTypeWithRegistry(schema, enumRegistry, inputRegistry, inp
|
|
|
889
722
|
cache
|
|
890
723
|
);
|
|
891
724
|
}
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
(p) => String(p.name) === "value"
|
|
725
|
+
}
|
|
726
|
+
for (const [, inputReg] of inputs) {
|
|
727
|
+
if (inputReg.schema.ast === innerToAst) {
|
|
728
|
+
return toGraphQLInputTypeWithRegistry(
|
|
729
|
+
inputReg.schema,
|
|
730
|
+
enumRegistry,
|
|
731
|
+
inputRegistry,
|
|
732
|
+
inputs,
|
|
733
|
+
enums,
|
|
734
|
+
cache
|
|
735
|
+
);
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
return void 0;
|
|
739
|
+
}
|
|
740
|
+
function findRegisteredInputForOptionSome(memberAst, inputs, inputRegistry, enumRegistry, enums, cache) {
|
|
741
|
+
if (memberAst._tag !== "TypeLiteral") return void 0;
|
|
742
|
+
const valueField = memberAst.propertySignatures?.find(
|
|
743
|
+
(p) => String(p.name) === "value"
|
|
744
|
+
);
|
|
745
|
+
if (!valueField) return void 0;
|
|
746
|
+
const valueType = valueField.type;
|
|
747
|
+
const valueInputName = cache?.astToInputName?.get(valueType);
|
|
748
|
+
if (valueInputName) {
|
|
749
|
+
const inputReg = inputs.get(valueInputName);
|
|
750
|
+
if (inputReg) {
|
|
751
|
+
return toGraphQLInputTypeWithRegistry(
|
|
752
|
+
inputReg.schema,
|
|
753
|
+
enumRegistry,
|
|
754
|
+
inputRegistry,
|
|
755
|
+
inputs,
|
|
756
|
+
enums,
|
|
757
|
+
cache
|
|
758
|
+
);
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
for (const [, inputReg] of inputs) {
|
|
762
|
+
if (inputReg.schema.ast === valueType) {
|
|
763
|
+
return toGraphQLInputTypeWithRegistry(
|
|
764
|
+
inputReg.schema,
|
|
765
|
+
enumRegistry,
|
|
766
|
+
inputRegistry,
|
|
767
|
+
inputs,
|
|
768
|
+
enums,
|
|
769
|
+
cache
|
|
770
|
+
);
|
|
771
|
+
}
|
|
772
|
+
let regAst = inputReg.schema.ast;
|
|
773
|
+
while (regAst._tag === "Transformation") {
|
|
774
|
+
regAst = regAst.to;
|
|
775
|
+
if (regAst === valueType) {
|
|
776
|
+
return toGraphQLInputTypeWithRegistry(
|
|
777
|
+
inputReg.schema,
|
|
778
|
+
enumRegistry,
|
|
779
|
+
inputRegistry,
|
|
780
|
+
inputs,
|
|
781
|
+
enums,
|
|
782
|
+
cache
|
|
951
783
|
);
|
|
952
|
-
if (valueField) {
|
|
953
|
-
const valueType = valueField.type;
|
|
954
|
-
const valueInputName = cache?.astToInputName?.get(valueType);
|
|
955
|
-
if (valueInputName) {
|
|
956
|
-
const inputReg = inputs.get(valueInputName);
|
|
957
|
-
if (inputReg) {
|
|
958
|
-
return toGraphQLInputTypeWithRegistry(
|
|
959
|
-
inputReg.schema,
|
|
960
|
-
enumRegistry,
|
|
961
|
-
inputRegistry,
|
|
962
|
-
inputs,
|
|
963
|
-
enums,
|
|
964
|
-
cache
|
|
965
|
-
);
|
|
966
|
-
}
|
|
967
|
-
}
|
|
968
|
-
for (const [, inputReg] of inputs) {
|
|
969
|
-
if (inputReg.schema.ast === valueType) {
|
|
970
|
-
return toGraphQLInputTypeWithRegistry(
|
|
971
|
-
inputReg.schema,
|
|
972
|
-
enumRegistry,
|
|
973
|
-
inputRegistry,
|
|
974
|
-
inputs,
|
|
975
|
-
enums,
|
|
976
|
-
cache
|
|
977
|
-
);
|
|
978
|
-
}
|
|
979
|
-
let regAst = inputReg.schema.ast;
|
|
980
|
-
while (regAst._tag === "Transformation") {
|
|
981
|
-
regAst = regAst.to;
|
|
982
|
-
if (regAst === valueType) {
|
|
983
|
-
return toGraphQLInputTypeWithRegistry(
|
|
984
|
-
inputReg.schema,
|
|
985
|
-
enumRegistry,
|
|
986
|
-
inputRegistry,
|
|
987
|
-
inputs,
|
|
988
|
-
enums,
|
|
989
|
-
cache
|
|
990
|
-
);
|
|
991
|
-
}
|
|
992
|
-
}
|
|
993
|
-
if (regAst._tag === "Declaration" && regAst.typeParameters?.[0] === valueType) {
|
|
994
|
-
return toGraphQLInputTypeWithRegistry(
|
|
995
|
-
inputReg.schema,
|
|
996
|
-
enumRegistry,
|
|
997
|
-
inputRegistry,
|
|
998
|
-
inputs,
|
|
999
|
-
enums,
|
|
1000
|
-
cache
|
|
1001
|
-
);
|
|
1002
|
-
}
|
|
1003
|
-
}
|
|
1004
|
-
const innerResult = toGraphQLInputTypeWithRegistry(
|
|
1005
|
-
S2__namespace.make(valueType),
|
|
1006
|
-
enumRegistry,
|
|
1007
|
-
inputRegistry,
|
|
1008
|
-
inputs,
|
|
1009
|
-
enums,
|
|
1010
|
-
cache
|
|
1011
|
-
);
|
|
1012
|
-
if (innerResult) {
|
|
1013
|
-
return innerResult;
|
|
1014
|
-
}
|
|
1015
|
-
}
|
|
1016
784
|
}
|
|
1017
785
|
}
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
}
|
|
786
|
+
if (regAst._tag === "Declaration" && regAst.typeParameters?.[0] === valueType) {
|
|
787
|
+
return toGraphQLInputTypeWithRegistry(
|
|
788
|
+
inputReg.schema,
|
|
789
|
+
enumRegistry,
|
|
790
|
+
inputRegistry,
|
|
791
|
+
inputs,
|
|
792
|
+
enums,
|
|
793
|
+
cache
|
|
794
|
+
);
|
|
1028
795
|
}
|
|
1029
796
|
}
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
797
|
+
const innerResult = toGraphQLInputTypeWithRegistry(
|
|
798
|
+
S2__namespace.make(valueType),
|
|
799
|
+
enumRegistry,
|
|
800
|
+
inputRegistry,
|
|
801
|
+
inputs,
|
|
802
|
+
enums,
|
|
803
|
+
cache
|
|
804
|
+
);
|
|
805
|
+
return innerResult || void 0;
|
|
806
|
+
}
|
|
807
|
+
function handleOptionTransformationForInput(fromAst, toAst, inputs, inputRegistry, enumRegistry, enums, cache) {
|
|
808
|
+
if (!fromAst || fromAst._tag !== "Union") return void 0;
|
|
809
|
+
for (const memberAst of fromAst.types) {
|
|
810
|
+
if (memberAst._tag === "Literal") continue;
|
|
811
|
+
if (memberAst._tag === "UndefinedKeyword") continue;
|
|
812
|
+
const registeredInput = findRegisteredInputForAST(memberAst, inputs, inputRegistry, enumRegistry, enums, cache) || findRegisteredInputForTransformation(memberAst, inputs, inputRegistry, enumRegistry, enums, cache) || findRegisteredInputForOptionSome(memberAst, inputs, inputRegistry, enumRegistry, enums, cache);
|
|
813
|
+
if (registeredInput) return registeredInput;
|
|
814
|
+
}
|
|
815
|
+
return void 0;
|
|
816
|
+
}
|
|
817
|
+
function handleTransformationForInput(ast, inputs, inputRegistry, enumRegistry, enums, cache) {
|
|
818
|
+
const toAst = ast.to;
|
|
819
|
+
const fromAst = ast.from;
|
|
820
|
+
if (isOptionDeclaration2(toAst)) {
|
|
821
|
+
const optionResult = handleOptionTransformationForInput(
|
|
822
|
+
fromAst,
|
|
823
|
+
toAst,
|
|
824
|
+
inputs,
|
|
825
|
+
inputRegistry,
|
|
826
|
+
enumRegistry,
|
|
827
|
+
enums,
|
|
828
|
+
cache
|
|
829
|
+
);
|
|
830
|
+
if (optionResult) return optionResult;
|
|
831
|
+
}
|
|
832
|
+
return toGraphQLInputTypeWithRegistry(
|
|
833
|
+
S2__namespace.make(toAst),
|
|
834
|
+
enumRegistry,
|
|
835
|
+
inputRegistry,
|
|
836
|
+
inputs,
|
|
837
|
+
enums,
|
|
838
|
+
cache
|
|
839
|
+
);
|
|
840
|
+
}
|
|
841
|
+
function findRegisteredInputInUnionMembers(types, inputs, inputRegistry, enumRegistry, enums, cache) {
|
|
842
|
+
for (const memberAst of types) {
|
|
843
|
+
const registeredInput = findRegisteredInputForAST(memberAst, inputs, inputRegistry, enumRegistry, enums, cache) || findRegisteredInputForTransformation(memberAst, inputs, inputRegistry, enumRegistry, enums, cache) || findRegisteredInputForOptionSome(memberAst, inputs, inputRegistry, enumRegistry, enums, cache);
|
|
844
|
+
if (registeredInput) return registeredInput;
|
|
845
|
+
}
|
|
846
|
+
return void 0;
|
|
847
|
+
}
|
|
848
|
+
function handleUnionForInput(ast, inputs, inputRegistry, enumRegistry, enums, cache) {
|
|
849
|
+
const unionAst = ast;
|
|
850
|
+
const nonUndefinedTypes = unionAst.types.filter((t) => t._tag !== "UndefinedKeyword");
|
|
851
|
+
if (nonUndefinedTypes.length === 1) {
|
|
852
|
+
if (nonUndefinedTypes[0]._tag === "Union" || nonUndefinedTypes[0]._tag === "TypeLiteral") {
|
|
853
|
+
return toGraphQLInputTypeWithRegistry(
|
|
854
|
+
S2__namespace.make(nonUndefinedTypes[0]),
|
|
855
|
+
enumRegistry,
|
|
856
|
+
inputRegistry,
|
|
857
|
+
inputs,
|
|
858
|
+
enums,
|
|
859
|
+
cache
|
|
860
|
+
);
|
|
861
|
+
}
|
|
862
|
+
}
|
|
863
|
+
const registeredInput = findRegisteredInputInUnionMembers(
|
|
864
|
+
unionAst.types,
|
|
865
|
+
inputs,
|
|
866
|
+
inputRegistry,
|
|
867
|
+
enumRegistry,
|
|
868
|
+
enums,
|
|
869
|
+
cache
|
|
870
|
+
);
|
|
871
|
+
if (registeredInput) return registeredInput;
|
|
872
|
+
const allLiterals = unionAst.types.every((t) => t._tag === "Literal");
|
|
873
|
+
if (allLiterals) {
|
|
874
|
+
const literalValues = unionAst.types.map((t) => String(t.literal)).sort();
|
|
875
|
+
for (const [enumName] of enums) {
|
|
876
|
+
const enumValues = cache?.enumSortedValues?.get(enumName) ?? [...enums.get(enumName).values].sort();
|
|
877
|
+
if (literalValues.length === enumValues.length && literalValues.every((v, i) => v === enumValues[i])) {
|
|
1035
878
|
const result = enumRegistry.get(enumName);
|
|
1036
879
|
if (result) return result;
|
|
1037
880
|
}
|
|
1038
|
-
}
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
return void 0;
|
|
884
|
+
}
|
|
885
|
+
function handleLiteralForInput(ast, enumRegistry, enums, cache) {
|
|
886
|
+
const literalValue = String(ast.literal);
|
|
887
|
+
if (cache?.literalToEnumName) {
|
|
888
|
+
const enumName = cache.literalToEnumName.get(literalValue);
|
|
889
|
+
if (enumName) {
|
|
890
|
+
return enumRegistry.get(enumName);
|
|
891
|
+
}
|
|
892
|
+
} else {
|
|
893
|
+
for (const [enumName, enumReg] of enums) {
|
|
894
|
+
if (enumReg.values.includes(literalValue)) {
|
|
895
|
+
return enumRegistry.get(enumName);
|
|
1044
896
|
}
|
|
1045
897
|
}
|
|
1046
898
|
}
|
|
899
|
+
return void 0;
|
|
900
|
+
}
|
|
901
|
+
function handleSuspendForInput(ast, inputs, inputRegistry, enumRegistry, enums, cache) {
|
|
902
|
+
const innerAst = ast.f();
|
|
903
|
+
return toGraphQLInputTypeWithRegistry(
|
|
904
|
+
S2__namespace.make(innerAst),
|
|
905
|
+
enumRegistry,
|
|
906
|
+
inputRegistry,
|
|
907
|
+
inputs,
|
|
908
|
+
enums,
|
|
909
|
+
cache
|
|
910
|
+
);
|
|
911
|
+
}
|
|
912
|
+
function toGraphQLInputTypeWithRegistry(schema, enumRegistry, inputRegistry, inputs, enums, cache) {
|
|
913
|
+
const ast = schema.ast;
|
|
914
|
+
const registeredInput = findRegisteredInputType(schema, ast, inputs, inputRegistry, cache);
|
|
915
|
+
if (registeredInput) return registeredInput;
|
|
916
|
+
if (ast._tag === "Transformation") {
|
|
917
|
+
return handleTransformationForInput(ast, inputs, inputRegistry, enumRegistry, enums, cache);
|
|
918
|
+
}
|
|
919
|
+
if (ast._tag === "Union") {
|
|
920
|
+
const unionResult = handleUnionForInput(ast, inputs, inputRegistry, enumRegistry, enums, cache);
|
|
921
|
+
if (unionResult) return unionResult;
|
|
922
|
+
}
|
|
923
|
+
if (ast._tag === "Literal") {
|
|
924
|
+
const literalResult = handleLiteralForInput(ast, enumRegistry, enums, cache);
|
|
925
|
+
if (literalResult) return literalResult;
|
|
926
|
+
}
|
|
1047
927
|
if (ast._tag === "Suspend") {
|
|
1048
|
-
|
|
1049
|
-
return toGraphQLInputTypeWithRegistry(
|
|
1050
|
-
S2__namespace.make(innerAst),
|
|
1051
|
-
enumRegistry,
|
|
1052
|
-
inputRegistry,
|
|
1053
|
-
inputs,
|
|
1054
|
-
enums,
|
|
1055
|
-
cache
|
|
1056
|
-
);
|
|
928
|
+
return handleSuspendForInput(ast, inputs, inputRegistry, enumRegistry, enums, cache);
|
|
1057
929
|
}
|
|
1058
930
|
return toGraphQLInputType(schema);
|
|
1059
931
|
}
|