@effect-gql/core 1.4.8 → 1.4.10
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 +392 -519
- package/builder/index.cjs.map +1 -1
- package/builder/index.js +393 -520
- package/builder/index.js.map +1 -1
- package/index.cjs +394 -531
- package/index.cjs.map +1 -1
- package/index.js +395 -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) {
|
|
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,20 @@ 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
|
-
|
|
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
|
|
192
|
+
);
|
|
195
193
|
const typeName = schema.annotations?.identifier || `Input_${Math.random().toString(36).slice(2, 11)}`;
|
|
196
194
|
return new graphql.GraphQLInputObjectType({
|
|
197
195
|
name: typeName,
|
|
@@ -232,18 +230,7 @@ var toGraphQLInputType = (schema) => {
|
|
|
232
230
|
var toGraphQLArgs = (schema) => {
|
|
233
231
|
const ast = schema.ast;
|
|
234
232
|
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
|
-
}
|
|
233
|
+
const args = buildFieldsFromPropertySignatures(ast.propertySignatures, toGraphQLInputType);
|
|
247
234
|
return args;
|
|
248
235
|
}
|
|
249
236
|
throw new Error(`Schema must be an object type to convert to GraphQL arguments`);
|
|
@@ -359,7 +346,7 @@ function toGraphQLTypeWithRegistry(schema, ctx) {
|
|
|
359
346
|
if (enumType2) return enumType2;
|
|
360
347
|
}
|
|
361
348
|
if (ast._tag === "TupleType") {
|
|
362
|
-
return
|
|
349
|
+
return handleTupleTypeAST2(ast, ctx);
|
|
363
350
|
}
|
|
364
351
|
if (ast._tag === "Declaration") {
|
|
365
352
|
if (isOptionDeclaration2(ast)) {
|
|
@@ -415,88 +402,112 @@ function getOptionInnerType2(ast) {
|
|
|
415
402
|
}
|
|
416
403
|
return void 0;
|
|
417
404
|
}
|
|
418
|
-
function
|
|
419
|
-
const
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
if (
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
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
|
-
}
|
|
405
|
+
function findRegisteredTypeForAST(memberAst, ctx) {
|
|
406
|
+
const typeName = ctx.astToTypeName?.get(memberAst);
|
|
407
|
+
if (typeName) {
|
|
408
|
+
const result = ctx.typeRegistry.get(typeName);
|
|
409
|
+
if (result) return result;
|
|
410
|
+
}
|
|
411
|
+
for (const [regTypeName, typeReg] of ctx.types) {
|
|
412
|
+
if (typeReg.schema.ast === memberAst) {
|
|
413
|
+
const result = ctx.typeRegistry.get(regTypeName);
|
|
414
|
+
if (result) return result;
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
return void 0;
|
|
418
|
+
}
|
|
419
|
+
function findRegisteredTypeForTransformation(memberAst, ctx) {
|
|
420
|
+
if (memberAst._tag !== "Transformation") return void 0;
|
|
421
|
+
const innerToAst = memberAst.to;
|
|
422
|
+
const transformedTypeName = ctx.astToTypeName?.get(innerToAst);
|
|
423
|
+
if (transformedTypeName) {
|
|
424
|
+
const result = ctx.typeRegistry.get(transformedTypeName);
|
|
425
|
+
if (result) return result;
|
|
426
|
+
}
|
|
427
|
+
for (const [regTypeName, typeReg] of ctx.types) {
|
|
428
|
+
if (typeReg.schema.ast === innerToAst) {
|
|
429
|
+
const result = ctx.typeRegistry.get(regTypeName);
|
|
430
|
+
if (result) return result;
|
|
481
431
|
}
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
432
|
+
}
|
|
433
|
+
return void 0;
|
|
434
|
+
}
|
|
435
|
+
function findRegisteredTypeForOptionSome(memberAst, ctx) {
|
|
436
|
+
if (memberAst._tag !== "TypeLiteral") return void 0;
|
|
437
|
+
const valueField = memberAst.propertySignatures?.find(
|
|
438
|
+
(p) => String(p.name) === "value"
|
|
439
|
+
);
|
|
440
|
+
if (!valueField) return void 0;
|
|
441
|
+
const valueType = valueField.type;
|
|
442
|
+
const valueTypeName = ctx.astToTypeName?.get(valueType);
|
|
443
|
+
if (valueTypeName) {
|
|
444
|
+
const result = ctx.typeRegistry.get(valueTypeName);
|
|
445
|
+
if (result) return result;
|
|
446
|
+
}
|
|
447
|
+
for (const [regTypeName, typeReg] of ctx.types) {
|
|
448
|
+
if (typeReg.schema.ast === valueType) {
|
|
449
|
+
const result = ctx.typeRegistry.get(regTypeName);
|
|
450
|
+
if (result) return result;
|
|
451
|
+
}
|
|
452
|
+
let regAst = typeReg.schema.ast;
|
|
453
|
+
while (regAst._tag === "Transformation") {
|
|
454
|
+
regAst = regAst.to;
|
|
455
|
+
if (regAst === valueType) {
|
|
456
|
+
const result = ctx.typeRegistry.get(regTypeName);
|
|
457
|
+
if (result) return result;
|
|
458
|
+
}
|
|
485
459
|
}
|
|
486
460
|
}
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
461
|
+
const innerResult = toGraphQLTypeWithRegistry(S2__namespace.make(valueType), ctx);
|
|
462
|
+
return innerResult;
|
|
463
|
+
}
|
|
464
|
+
function handleOptionTransformation(ast, fromAst, toAst, ctx) {
|
|
465
|
+
if (fromAst && fromAst._tag === "Union") {
|
|
466
|
+
for (const memberAst of fromAst.types) {
|
|
467
|
+
if (memberAst._tag === "Literal") continue;
|
|
468
|
+
if (memberAst._tag === "UndefinedKeyword") continue;
|
|
469
|
+
const registeredType = findRegisteredTypeForAST(memberAst, ctx) || findRegisteredTypeForTransformation(memberAst, ctx) || findRegisteredTypeForOptionSome(memberAst, ctx);
|
|
470
|
+
if (registeredType) return registeredType;
|
|
496
471
|
}
|
|
497
472
|
}
|
|
473
|
+
const innerType = getOptionInnerType2(toAst);
|
|
474
|
+
if (innerType) {
|
|
475
|
+
return toGraphQLTypeWithRegistry(S2__namespace.make(innerType), ctx);
|
|
476
|
+
}
|
|
477
|
+
return void 0;
|
|
478
|
+
}
|
|
479
|
+
function handleArrayTransformation(toAst, ctx) {
|
|
480
|
+
if (toAst._tag !== "TupleType") return void 0;
|
|
481
|
+
let elementType;
|
|
482
|
+
if (toAst.rest && toAst.rest.length > 0) {
|
|
483
|
+
const elementSchema = S2__namespace.make(toAst.rest[0].type);
|
|
484
|
+
elementType = toGraphQLTypeWithRegistry(elementSchema, ctx);
|
|
485
|
+
} else if (toAst.elements.length > 0) {
|
|
486
|
+
const elementSchema = S2__namespace.make(toAst.elements[0].type);
|
|
487
|
+
elementType = toGraphQLTypeWithRegistry(elementSchema, ctx);
|
|
488
|
+
} else {
|
|
489
|
+
return void 0;
|
|
490
|
+
}
|
|
491
|
+
return new graphql.GraphQLList(elementType);
|
|
492
|
+
}
|
|
493
|
+
function handleTransformationAST(ast, ctx) {
|
|
494
|
+
const toAst = ast.to;
|
|
495
|
+
const fromAst = ast.from;
|
|
496
|
+
if (isOptionDeclaration2(toAst)) {
|
|
497
|
+
const optionResult = handleOptionTransformation(ast, fromAst, toAst, ctx);
|
|
498
|
+
if (optionResult) return optionResult;
|
|
499
|
+
}
|
|
500
|
+
const arrayResult = handleArrayTransformation(toAst, ctx);
|
|
501
|
+
if (arrayResult) return arrayResult;
|
|
498
502
|
return toGraphQLTypeWithRegistry(S2__namespace.make(ast.to), ctx);
|
|
499
503
|
}
|
|
504
|
+
function findRegisteredTypeInUnionMembers(types, ctx) {
|
|
505
|
+
for (const memberAst of types) {
|
|
506
|
+
const registeredType = findRegisteredTypeForAST(memberAst, ctx) || findRegisteredTypeForTransformation(memberAst, ctx) || findRegisteredTypeForOptionSome(memberAst, ctx);
|
|
507
|
+
if (registeredType) return registeredType;
|
|
508
|
+
}
|
|
509
|
+
return void 0;
|
|
510
|
+
}
|
|
500
511
|
function handleUnionAST(ast, ctx) {
|
|
501
512
|
const allLiterals = ast.types.every((t) => t._tag === "Literal");
|
|
502
513
|
if (allLiterals) {
|
|
@@ -506,64 +517,8 @@ function handleUnionAST(ast, ctx) {
|
|
|
506
517
|
const unionType2 = findRegisteredUnion(ast.types, ctx);
|
|
507
518
|
if (unionType2) return unionType2;
|
|
508
519
|
}
|
|
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
|
-
}
|
|
520
|
+
const registeredType = findRegisteredTypeInUnionMembers(ast.types, ctx);
|
|
521
|
+
if (registeredType) return registeredType;
|
|
567
522
|
if (ast.types.length > 0) {
|
|
568
523
|
return toGraphQLTypeWithRegistry(S2__namespace.make(ast.types[0]), ctx);
|
|
569
524
|
}
|
|
@@ -608,7 +563,7 @@ function findEnumForLiteral(ast, ctx) {
|
|
|
608
563
|
}
|
|
609
564
|
return void 0;
|
|
610
565
|
}
|
|
611
|
-
function
|
|
566
|
+
function handleTupleTypeAST2(ast, ctx) {
|
|
612
567
|
if (ast.rest && ast.rest.length > 0) {
|
|
613
568
|
const elementSchema = S2__namespace.make(ast.rest[0].type);
|
|
614
569
|
const elementType = toGraphQLTypeWithRegistry(elementSchema, ctx);
|
|
@@ -708,170 +663,40 @@ function buildInputTypeLookupCache(inputs, enums) {
|
|
|
708
663
|
}
|
|
709
664
|
return cache;
|
|
710
665
|
}
|
|
711
|
-
function
|
|
712
|
-
const ast = schema.ast;
|
|
666
|
+
function findRegisteredInputType(schema, ast, inputs, inputRegistry, cache) {
|
|
713
667
|
if (cache?.schemaToInputName || cache?.astToInputName) {
|
|
714
668
|
const inputName = cache.schemaToInputName?.get(schema) ?? cache.astToInputName?.get(ast);
|
|
715
669
|
if (inputName) {
|
|
716
|
-
|
|
717
|
-
if (result) return result;
|
|
670
|
+
return inputRegistry.get(inputName);
|
|
718
671
|
}
|
|
719
672
|
} else {
|
|
720
673
|
for (const [inputName, inputReg] of inputs) {
|
|
721
674
|
if (inputReg.schema.ast === ast || inputReg.schema === schema) {
|
|
722
|
-
|
|
723
|
-
if (result) return result;
|
|
675
|
+
return inputRegistry.get(inputName);
|
|
724
676
|
}
|
|
725
677
|
}
|
|
726
678
|
}
|
|
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
|
-
}
|
|
679
|
+
return void 0;
|
|
680
|
+
}
|
|
681
|
+
function findRegisteredInputForAST(memberAst, inputs, inputRegistry, enumRegistry, enums, cache) {
|
|
682
|
+
const inputName = cache?.astToInputName?.get(memberAst);
|
|
683
|
+
if (inputName) {
|
|
684
|
+
const inputReg = inputs.get(inputName);
|
|
685
|
+
if (inputReg) {
|
|
686
|
+
return toGraphQLInputTypeWithRegistry(
|
|
687
|
+
inputReg.schema,
|
|
688
|
+
enumRegistry,
|
|
689
|
+
inputRegistry,
|
|
690
|
+
inputs,
|
|
691
|
+
enums,
|
|
692
|
+
cache
|
|
693
|
+
);
|
|
859
694
|
}
|
|
860
|
-
return toGraphQLInputTypeWithRegistry(
|
|
861
|
-
S2__namespace.make(toAst),
|
|
862
|
-
enumRegistry,
|
|
863
|
-
inputRegistry,
|
|
864
|
-
inputs,
|
|
865
|
-
enums,
|
|
866
|
-
cache
|
|
867
|
-
);
|
|
868
695
|
}
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
const nonUndefinedTypes = unionAst.types.filter((t) => t._tag !== "UndefinedKeyword");
|
|
872
|
-
if (nonUndefinedTypes.length === 1 && nonUndefinedTypes[0]._tag === "Union") {
|
|
696
|
+
for (const [, inputReg] of inputs) {
|
|
697
|
+
if (inputReg.schema.ast === memberAst) {
|
|
873
698
|
return toGraphQLInputTypeWithRegistry(
|
|
874
|
-
|
|
699
|
+
inputReg.schema,
|
|
875
700
|
enumRegistry,
|
|
876
701
|
inputRegistry,
|
|
877
702
|
inputs,
|
|
@@ -879,9 +704,18 @@ function toGraphQLInputTypeWithRegistry(schema, enumRegistry, inputRegistry, inp
|
|
|
879
704
|
cache
|
|
880
705
|
);
|
|
881
706
|
}
|
|
882
|
-
|
|
707
|
+
}
|
|
708
|
+
return void 0;
|
|
709
|
+
}
|
|
710
|
+
function findRegisteredInputForTransformation(memberAst, inputs, inputRegistry, enumRegistry, enums, cache) {
|
|
711
|
+
if (memberAst._tag !== "Transformation") return void 0;
|
|
712
|
+
const innerToAst = memberAst.to;
|
|
713
|
+
const transformedInputName = cache?.astToInputName?.get(innerToAst);
|
|
714
|
+
if (transformedInputName) {
|
|
715
|
+
const inputReg = inputs.get(transformedInputName);
|
|
716
|
+
if (inputReg) {
|
|
883
717
|
return toGraphQLInputTypeWithRegistry(
|
|
884
|
-
|
|
718
|
+
inputReg.schema,
|
|
885
719
|
enumRegistry,
|
|
886
720
|
inputRegistry,
|
|
887
721
|
inputs,
|
|
@@ -889,171 +723,210 @@ function toGraphQLInputTypeWithRegistry(schema, enumRegistry, inputRegistry, inp
|
|
|
889
723
|
cache
|
|
890
724
|
);
|
|
891
725
|
}
|
|
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"
|
|
726
|
+
}
|
|
727
|
+
for (const [, inputReg] of inputs) {
|
|
728
|
+
if (inputReg.schema.ast === innerToAst) {
|
|
729
|
+
return toGraphQLInputTypeWithRegistry(
|
|
730
|
+
inputReg.schema,
|
|
731
|
+
enumRegistry,
|
|
732
|
+
inputRegistry,
|
|
733
|
+
inputs,
|
|
734
|
+
enums,
|
|
735
|
+
cache
|
|
736
|
+
);
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
return void 0;
|
|
740
|
+
}
|
|
741
|
+
function findRegisteredInputForOptionSome(memberAst, inputs, inputRegistry, enumRegistry, enums, cache) {
|
|
742
|
+
if (memberAst._tag !== "TypeLiteral") return void 0;
|
|
743
|
+
const valueField = memberAst.propertySignatures?.find(
|
|
744
|
+
(p) => String(p.name) === "value"
|
|
745
|
+
);
|
|
746
|
+
if (!valueField) return void 0;
|
|
747
|
+
const valueType = valueField.type;
|
|
748
|
+
const valueInputName = cache?.astToInputName?.get(valueType);
|
|
749
|
+
if (valueInputName) {
|
|
750
|
+
const inputReg = inputs.get(valueInputName);
|
|
751
|
+
if (inputReg) {
|
|
752
|
+
return toGraphQLInputTypeWithRegistry(
|
|
753
|
+
inputReg.schema,
|
|
754
|
+
enumRegistry,
|
|
755
|
+
inputRegistry,
|
|
756
|
+
inputs,
|
|
757
|
+
enums,
|
|
758
|
+
cache
|
|
759
|
+
);
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
for (const [, inputReg] of inputs) {
|
|
763
|
+
if (inputReg.schema.ast === valueType) {
|
|
764
|
+
return toGraphQLInputTypeWithRegistry(
|
|
765
|
+
inputReg.schema,
|
|
766
|
+
enumRegistry,
|
|
767
|
+
inputRegistry,
|
|
768
|
+
inputs,
|
|
769
|
+
enums,
|
|
770
|
+
cache
|
|
771
|
+
);
|
|
772
|
+
}
|
|
773
|
+
let regAst = inputReg.schema.ast;
|
|
774
|
+
while (regAst._tag === "Transformation") {
|
|
775
|
+
regAst = regAst.to;
|
|
776
|
+
if (regAst === valueType) {
|
|
777
|
+
return toGraphQLInputTypeWithRegistry(
|
|
778
|
+
inputReg.schema,
|
|
779
|
+
enumRegistry,
|
|
780
|
+
inputRegistry,
|
|
781
|
+
inputs,
|
|
782
|
+
enums,
|
|
783
|
+
cache
|
|
951
784
|
);
|
|
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
785
|
}
|
|
1017
786
|
}
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
}
|
|
787
|
+
if (regAst._tag === "Declaration" && regAst.typeParameters?.[0] === valueType) {
|
|
788
|
+
return toGraphQLInputTypeWithRegistry(
|
|
789
|
+
inputReg.schema,
|
|
790
|
+
enumRegistry,
|
|
791
|
+
inputRegistry,
|
|
792
|
+
inputs,
|
|
793
|
+
enums,
|
|
794
|
+
cache
|
|
795
|
+
);
|
|
1028
796
|
}
|
|
1029
797
|
}
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
798
|
+
const innerResult = toGraphQLInputTypeWithRegistry(
|
|
799
|
+
S2__namespace.make(valueType),
|
|
800
|
+
enumRegistry,
|
|
801
|
+
inputRegistry,
|
|
802
|
+
inputs,
|
|
803
|
+
enums,
|
|
804
|
+
cache
|
|
805
|
+
);
|
|
806
|
+
return innerResult || void 0;
|
|
807
|
+
}
|
|
808
|
+
function handleOptionTransformationForInput(fromAst, toAst, inputs, inputRegistry, enumRegistry, enums, cache) {
|
|
809
|
+
if (!fromAst || fromAst._tag !== "Union") return void 0;
|
|
810
|
+
for (const memberAst of fromAst.types) {
|
|
811
|
+
if (memberAst._tag === "Literal") continue;
|
|
812
|
+
if (memberAst._tag === "UndefinedKeyword") continue;
|
|
813
|
+
const registeredInput = findRegisteredInputForAST(memberAst, inputs, inputRegistry, enumRegistry, enums, cache) || findRegisteredInputForTransformation(memberAst, inputs, inputRegistry, enumRegistry, enums, cache) || findRegisteredInputForOptionSome(memberAst, inputs, inputRegistry, enumRegistry, enums, cache);
|
|
814
|
+
if (registeredInput) return registeredInput;
|
|
815
|
+
}
|
|
816
|
+
return void 0;
|
|
817
|
+
}
|
|
818
|
+
function handleTransformationForInput(ast, inputs, inputRegistry, enumRegistry, enums, cache) {
|
|
819
|
+
const toAst = ast.to;
|
|
820
|
+
const fromAst = ast.from;
|
|
821
|
+
if (isOptionDeclaration2(toAst)) {
|
|
822
|
+
const optionResult = handleOptionTransformationForInput(
|
|
823
|
+
fromAst,
|
|
824
|
+
toAst,
|
|
825
|
+
inputs,
|
|
826
|
+
inputRegistry,
|
|
827
|
+
enumRegistry,
|
|
828
|
+
enums,
|
|
829
|
+
cache
|
|
830
|
+
);
|
|
831
|
+
if (optionResult) return optionResult;
|
|
832
|
+
}
|
|
833
|
+
return toGraphQLInputTypeWithRegistry(
|
|
834
|
+
S2__namespace.make(toAst),
|
|
835
|
+
enumRegistry,
|
|
836
|
+
inputRegistry,
|
|
837
|
+
inputs,
|
|
838
|
+
enums,
|
|
839
|
+
cache
|
|
840
|
+
);
|
|
841
|
+
}
|
|
842
|
+
function findRegisteredInputInUnionMembers(types, inputs, inputRegistry, enumRegistry, enums, cache) {
|
|
843
|
+
for (const memberAst of types) {
|
|
844
|
+
const registeredInput = findRegisteredInputForAST(memberAst, inputs, inputRegistry, enumRegistry, enums, cache) || findRegisteredInputForTransformation(memberAst, inputs, inputRegistry, enumRegistry, enums, cache) || findRegisteredInputForOptionSome(memberAst, inputs, inputRegistry, enumRegistry, enums, cache);
|
|
845
|
+
if (registeredInput) return registeredInput;
|
|
846
|
+
}
|
|
847
|
+
return void 0;
|
|
848
|
+
}
|
|
849
|
+
function handleUnionForInput(ast, inputs, inputRegistry, enumRegistry, enums, cache) {
|
|
850
|
+
const unionAst = ast;
|
|
851
|
+
const nonUndefinedTypes = unionAst.types.filter((t) => t._tag !== "UndefinedKeyword");
|
|
852
|
+
if (nonUndefinedTypes.length === 1) {
|
|
853
|
+
if (nonUndefinedTypes[0]._tag === "Union" || nonUndefinedTypes[0]._tag === "TypeLiteral") {
|
|
854
|
+
return toGraphQLInputTypeWithRegistry(
|
|
855
|
+
S2__namespace.make(nonUndefinedTypes[0]),
|
|
856
|
+
enumRegistry,
|
|
857
|
+
inputRegistry,
|
|
858
|
+
inputs,
|
|
859
|
+
enums,
|
|
860
|
+
cache
|
|
861
|
+
);
|
|
862
|
+
}
|
|
863
|
+
}
|
|
864
|
+
const registeredInput = findRegisteredInputInUnionMembers(
|
|
865
|
+
unionAst.types,
|
|
866
|
+
inputs,
|
|
867
|
+
inputRegistry,
|
|
868
|
+
enumRegistry,
|
|
869
|
+
enums,
|
|
870
|
+
cache
|
|
871
|
+
);
|
|
872
|
+
if (registeredInput) return registeredInput;
|
|
873
|
+
const allLiterals = unionAst.types.every((t) => t._tag === "Literal");
|
|
874
|
+
if (allLiterals) {
|
|
875
|
+
const literalValues = unionAst.types.map((t) => String(t.literal)).sort();
|
|
876
|
+
for (const [enumName] of enums) {
|
|
877
|
+
const enumValues = cache?.enumSortedValues?.get(enumName) ?? [...enums.get(enumName).values].sort();
|
|
878
|
+
if (literalValues.length === enumValues.length && literalValues.every((v, i) => v === enumValues[i])) {
|
|
1035
879
|
const result = enumRegistry.get(enumName);
|
|
1036
880
|
if (result) return result;
|
|
1037
881
|
}
|
|
1038
|
-
}
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
882
|
+
}
|
|
883
|
+
}
|
|
884
|
+
return void 0;
|
|
885
|
+
}
|
|
886
|
+
function handleLiteralForInput(ast, enumRegistry, enums, cache) {
|
|
887
|
+
const literalValue = String(ast.literal);
|
|
888
|
+
if (cache?.literalToEnumName) {
|
|
889
|
+
const enumName = cache.literalToEnumName.get(literalValue);
|
|
890
|
+
if (enumName) {
|
|
891
|
+
return enumRegistry.get(enumName);
|
|
892
|
+
}
|
|
893
|
+
} else {
|
|
894
|
+
for (const [enumName, enumReg] of enums) {
|
|
895
|
+
if (enumReg.values.includes(literalValue)) {
|
|
896
|
+
return enumRegistry.get(enumName);
|
|
1044
897
|
}
|
|
1045
898
|
}
|
|
1046
899
|
}
|
|
900
|
+
return void 0;
|
|
901
|
+
}
|
|
902
|
+
function handleSuspendForInput(ast, inputs, inputRegistry, enumRegistry, enums, cache) {
|
|
903
|
+
const innerAst = ast.f();
|
|
904
|
+
return toGraphQLInputTypeWithRegistry(
|
|
905
|
+
S2__namespace.make(innerAst),
|
|
906
|
+
enumRegistry,
|
|
907
|
+
inputRegistry,
|
|
908
|
+
inputs,
|
|
909
|
+
enums,
|
|
910
|
+
cache
|
|
911
|
+
);
|
|
912
|
+
}
|
|
913
|
+
function toGraphQLInputTypeWithRegistry(schema, enumRegistry, inputRegistry, inputs, enums, cache) {
|
|
914
|
+
const ast = schema.ast;
|
|
915
|
+
const registeredInput = findRegisteredInputType(schema, ast, inputs, inputRegistry, cache);
|
|
916
|
+
if (registeredInput) return registeredInput;
|
|
917
|
+
if (ast._tag === "Transformation") {
|
|
918
|
+
return handleTransformationForInput(ast, inputs, inputRegistry, enumRegistry, enums, cache);
|
|
919
|
+
}
|
|
920
|
+
if (ast._tag === "Union") {
|
|
921
|
+
const unionResult = handleUnionForInput(ast, inputs, inputRegistry, enumRegistry, enums, cache);
|
|
922
|
+
if (unionResult) return unionResult;
|
|
923
|
+
}
|
|
924
|
+
if (ast._tag === "Literal") {
|
|
925
|
+
const literalResult = handleLiteralForInput(ast, enumRegistry, enums, cache);
|
|
926
|
+
if (literalResult) return literalResult;
|
|
927
|
+
}
|
|
1047
928
|
if (ast._tag === "Suspend") {
|
|
1048
|
-
|
|
1049
|
-
return toGraphQLInputTypeWithRegistry(
|
|
1050
|
-
S2__namespace.make(innerAst),
|
|
1051
|
-
enumRegistry,
|
|
1052
|
-
inputRegistry,
|
|
1053
|
-
inputs,
|
|
1054
|
-
enums,
|
|
1055
|
-
cache
|
|
1056
|
-
);
|
|
929
|
+
return handleSuspendForInput(ast, inputs, inputRegistry, enumRegistry, enums, cache);
|
|
1057
930
|
}
|
|
1058
931
|
return toGraphQLInputType(schema);
|
|
1059
932
|
}
|