@effect-gql/core 1.4.7 → 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 +400 -517
- package/builder/index.cjs.map +1 -1
- package/builder/index.js +401 -518
- package/builder/index.js.map +1 -1
- package/index.cjs +402 -528
- package/index.cjs.map +1 -1
- package/index.js +403 -529
- package/index.js.map +1 -1
- package/package.json +1 -1
package/builder/index.cjs
CHANGED
|
@@ -33,7 +33,15 @@ var isIntegerType = (ast) => {
|
|
|
33
33
|
const annotations = refinement.annotations;
|
|
34
34
|
if (annotations) {
|
|
35
35
|
const identifier = AST__namespace.getIdentifierAnnotation(refinement);
|
|
36
|
-
if (identifier._tag === "Some"
|
|
36
|
+
if (identifier._tag === "Some") {
|
|
37
|
+
const id = identifier.value;
|
|
38
|
+
if (id === "Int" || id.includes("Int")) {
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
const JSONSchemaSymbol = /* @__PURE__ */ Symbol.for("effect/annotation/JSONSchema");
|
|
43
|
+
const jsonSchema = annotations[JSONSchemaSymbol];
|
|
44
|
+
if (jsonSchema && jsonSchema.type === "integer") {
|
|
37
45
|
return true;
|
|
38
46
|
}
|
|
39
47
|
}
|
|
@@ -41,6 +49,51 @@ var isIntegerType = (ast) => {
|
|
|
41
49
|
}
|
|
42
50
|
return false;
|
|
43
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
|
+
}
|
|
44
97
|
var isOptionDeclaration = (ast) => {
|
|
45
98
|
if (ast._tag === "Declaration") {
|
|
46
99
|
const annotations = ast.annotations;
|
|
@@ -71,41 +124,17 @@ var getOptionInnerType = (ast) => {
|
|
|
71
124
|
};
|
|
72
125
|
var toGraphQLType = (schema) => {
|
|
73
126
|
const ast = schema.ast;
|
|
74
|
-
|
|
75
|
-
if (
|
|
76
|
-
if (ast._tag === "BooleanKeyword") return graphql.GraphQLBoolean;
|
|
127
|
+
const primitiveResult = handlePrimitiveAST(ast);
|
|
128
|
+
if (primitiveResult) return primitiveResult;
|
|
77
129
|
if (ast._tag === "Refinement") {
|
|
78
|
-
|
|
79
|
-
return graphql.GraphQLInt;
|
|
80
|
-
}
|
|
81
|
-
return toGraphQLType(S2__namespace.make(ast.from));
|
|
82
|
-
}
|
|
83
|
-
if (ast._tag === "Literal") {
|
|
84
|
-
if (typeof ast.literal === "string") return graphql.GraphQLString;
|
|
85
|
-
if (typeof ast.literal === "number") {
|
|
86
|
-
return Number.isInteger(ast.literal) ? graphql.GraphQLInt : graphql.GraphQLFloat;
|
|
87
|
-
}
|
|
88
|
-
if (typeof ast.literal === "boolean") return graphql.GraphQLBoolean;
|
|
89
|
-
}
|
|
90
|
-
if (ast._tag === "TupleType") {
|
|
91
|
-
const elements = ast.elements;
|
|
92
|
-
if (elements.length > 0) {
|
|
93
|
-
const elementSchema = S2__namespace.make(elements[0].type);
|
|
94
|
-
return new graphql.GraphQLList(toGraphQLType(elementSchema));
|
|
95
|
-
}
|
|
130
|
+
return handleRefinementAST(ast, toGraphQLType);
|
|
96
131
|
}
|
|
132
|
+
const literalResult = handleLiteralAST(ast);
|
|
133
|
+
if (literalResult) return literalResult;
|
|
134
|
+
const tupleResult = handleTupleTypeAST(ast, toGraphQLType);
|
|
135
|
+
if (tupleResult) return tupleResult;
|
|
97
136
|
if (ast._tag === "TypeLiteral") {
|
|
98
|
-
const fields =
|
|
99
|
-
for (const field2 of ast.propertySignatures) {
|
|
100
|
-
const fieldName = String(field2.name);
|
|
101
|
-
if (fieldName === "_tag") continue;
|
|
102
|
-
const fieldSchema = S2__namespace.make(field2.type);
|
|
103
|
-
let fieldType = toGraphQLType(fieldSchema);
|
|
104
|
-
if (!field2.isOptional) {
|
|
105
|
-
fieldType = new graphql.GraphQLNonNull(fieldType);
|
|
106
|
-
}
|
|
107
|
-
fields[fieldName] = { type: fieldType };
|
|
108
|
-
}
|
|
137
|
+
const fields = buildFieldsFromPropertySignatures(ast.propertySignatures, toGraphQLType);
|
|
109
138
|
const typeName = schema.annotations?.identifier || `Object_${Math.random().toString(36).slice(2, 11)}`;
|
|
110
139
|
return new graphql.GraphQLObjectType({
|
|
111
140
|
name: typeName,
|
|
@@ -147,41 +176,19 @@ var toGraphQLType = (schema) => {
|
|
|
147
176
|
};
|
|
148
177
|
var toGraphQLInputType = (schema) => {
|
|
149
178
|
const ast = schema.ast;
|
|
150
|
-
|
|
151
|
-
if (
|
|
152
|
-
if (ast._tag === "BooleanKeyword") return graphql.GraphQLBoolean;
|
|
179
|
+
const primitiveResult = handlePrimitiveAST(ast);
|
|
180
|
+
if (primitiveResult) return primitiveResult;
|
|
153
181
|
if (ast._tag === "Refinement") {
|
|
154
|
-
|
|
155
|
-
return graphql.GraphQLInt;
|
|
156
|
-
}
|
|
157
|
-
return toGraphQLInputType(S2__namespace.make(ast.from));
|
|
158
|
-
}
|
|
159
|
-
if (ast._tag === "Literal") {
|
|
160
|
-
if (typeof ast.literal === "string") return graphql.GraphQLString;
|
|
161
|
-
if (typeof ast.literal === "number") {
|
|
162
|
-
return Number.isInteger(ast.literal) ? graphql.GraphQLInt : graphql.GraphQLFloat;
|
|
163
|
-
}
|
|
164
|
-
if (typeof ast.literal === "boolean") return graphql.GraphQLBoolean;
|
|
165
|
-
}
|
|
166
|
-
if (ast._tag === "TupleType") {
|
|
167
|
-
const elements = ast.elements;
|
|
168
|
-
if (elements.length > 0) {
|
|
169
|
-
const elementSchema = S2__namespace.make(elements[0].type);
|
|
170
|
-
return new graphql.GraphQLList(toGraphQLInputType(elementSchema));
|
|
171
|
-
}
|
|
182
|
+
return handleRefinementAST(ast, toGraphQLInputType);
|
|
172
183
|
}
|
|
184
|
+
const literalResult = handleLiteralAST(ast);
|
|
185
|
+
if (literalResult) return literalResult;
|
|
186
|
+
const tupleResult = handleTupleTypeAST(ast, toGraphQLInputType);
|
|
187
|
+
if (tupleResult) return tupleResult;
|
|
173
188
|
if (ast._tag === "TypeLiteral") {
|
|
174
|
-
const fields =
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
if (fieldName === "_tag") continue;
|
|
178
|
-
const fieldSchema = S2__namespace.make(field2.type);
|
|
179
|
-
let fieldType = toGraphQLInputType(fieldSchema);
|
|
180
|
-
if (!field2.isOptional) {
|
|
181
|
-
fieldType = new graphql.GraphQLNonNull(fieldType);
|
|
182
|
-
}
|
|
183
|
-
fields[fieldName] = { type: fieldType };
|
|
184
|
-
}
|
|
189
|
+
const fields = buildFieldsFromPropertySignatures(
|
|
190
|
+
ast.propertySignatures,
|
|
191
|
+
toGraphQLInputType);
|
|
185
192
|
const typeName = schema.annotations?.identifier || `Input_${Math.random().toString(36).slice(2, 11)}`;
|
|
186
193
|
return new graphql.GraphQLInputObjectType({
|
|
187
194
|
name: typeName,
|
|
@@ -222,17 +229,7 @@ var toGraphQLInputType = (schema) => {
|
|
|
222
229
|
var toGraphQLArgs = (schema) => {
|
|
223
230
|
const ast = schema.ast;
|
|
224
231
|
if (ast._tag === "TypeLiteral") {
|
|
225
|
-
const args =
|
|
226
|
-
for (const field2 of ast.propertySignatures) {
|
|
227
|
-
const fieldName = String(field2.name);
|
|
228
|
-
if (fieldName === "_tag") continue;
|
|
229
|
-
const fieldSchema = S2__namespace.make(field2.type);
|
|
230
|
-
let fieldType = toGraphQLInputType(fieldSchema);
|
|
231
|
-
if (!field2.isOptional) {
|
|
232
|
-
fieldType = new graphql.GraphQLNonNull(fieldType);
|
|
233
|
-
}
|
|
234
|
-
args[fieldName] = { type: fieldType };
|
|
235
|
-
}
|
|
232
|
+
const args = buildFieldsFromPropertySignatures(ast.propertySignatures, toGraphQLInputType);
|
|
236
233
|
return args;
|
|
237
234
|
}
|
|
238
235
|
throw new Error(`Schema must be an object type to convert to GraphQL arguments`);
|
|
@@ -348,7 +345,7 @@ function toGraphQLTypeWithRegistry(schema, ctx) {
|
|
|
348
345
|
if (enumType2) return enumType2;
|
|
349
346
|
}
|
|
350
347
|
if (ast._tag === "TupleType") {
|
|
351
|
-
return
|
|
348
|
+
return handleTupleTypeAST2(ast, ctx);
|
|
352
349
|
}
|
|
353
350
|
if (ast._tag === "Declaration") {
|
|
354
351
|
if (isOptionDeclaration2(ast)) {
|
|
@@ -404,88 +401,112 @@ function getOptionInnerType2(ast) {
|
|
|
404
401
|
}
|
|
405
402
|
return void 0;
|
|
406
403
|
}
|
|
407
|
-
function
|
|
408
|
-
const
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
if (
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
const result = ctx.typeRegistry.get(regTypeName);
|
|
454
|
-
if (result) return result;
|
|
455
|
-
}
|
|
456
|
-
let regAst = typeReg.schema.ast;
|
|
457
|
-
while (regAst._tag === "Transformation") {
|
|
458
|
-
regAst = regAst.to;
|
|
459
|
-
if (regAst === valueType) {
|
|
460
|
-
const result = ctx.typeRegistry.get(regTypeName);
|
|
461
|
-
if (result) return result;
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
const innerResult = toGraphQLTypeWithRegistry(S2__namespace.make(valueType), ctx);
|
|
466
|
-
if (innerResult) return innerResult;
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
}
|
|
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;
|
|
414
|
+
}
|
|
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;
|
|
430
|
+
}
|
|
431
|
+
}
|
|
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;
|
|
470
450
|
}
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
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
|
+
}
|
|
474
458
|
}
|
|
475
459
|
}
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
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;
|
|
485
470
|
}
|
|
486
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;
|
|
487
501
|
return toGraphQLTypeWithRegistry(S2__namespace.make(ast.to), ctx);
|
|
488
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
|
+
}
|
|
489
510
|
function handleUnionAST(ast, ctx) {
|
|
490
511
|
const allLiterals = ast.types.every((t) => t._tag === "Literal");
|
|
491
512
|
if (allLiterals) {
|
|
@@ -495,64 +516,8 @@ function handleUnionAST(ast, ctx) {
|
|
|
495
516
|
const unionType2 = findRegisteredUnion(ast.types, ctx);
|
|
496
517
|
if (unionType2) return unionType2;
|
|
497
518
|
}
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
if (typeName) {
|
|
501
|
-
const result = ctx.typeRegistry.get(typeName);
|
|
502
|
-
if (result) return result;
|
|
503
|
-
}
|
|
504
|
-
for (const [regTypeName, typeReg] of ctx.types) {
|
|
505
|
-
if (typeReg.schema.ast === memberAst) {
|
|
506
|
-
const result = ctx.typeRegistry.get(regTypeName);
|
|
507
|
-
if (result) return result;
|
|
508
|
-
}
|
|
509
|
-
}
|
|
510
|
-
if (memberAst._tag === "Transformation") {
|
|
511
|
-
const toAst = memberAst.to;
|
|
512
|
-
const transformedTypeName = ctx.astToTypeName?.get(toAst);
|
|
513
|
-
if (transformedTypeName) {
|
|
514
|
-
const result = ctx.typeRegistry.get(transformedTypeName);
|
|
515
|
-
if (result) return result;
|
|
516
|
-
}
|
|
517
|
-
for (const [regTypeName, typeReg] of ctx.types) {
|
|
518
|
-
if (typeReg.schema.ast === toAst) {
|
|
519
|
-
const result = ctx.typeRegistry.get(regTypeName);
|
|
520
|
-
if (result) return result;
|
|
521
|
-
}
|
|
522
|
-
}
|
|
523
|
-
}
|
|
524
|
-
if (memberAst._tag === "TypeLiteral") {
|
|
525
|
-
const valueField = memberAst.propertySignatures?.find(
|
|
526
|
-
(p) => String(p.name) === "value"
|
|
527
|
-
);
|
|
528
|
-
if (valueField) {
|
|
529
|
-
const valueType = valueField.type;
|
|
530
|
-
const valueTypeName = ctx.astToTypeName?.get(valueType);
|
|
531
|
-
if (valueTypeName) {
|
|
532
|
-
const result = ctx.typeRegistry.get(valueTypeName);
|
|
533
|
-
if (result) return result;
|
|
534
|
-
}
|
|
535
|
-
for (const [regTypeName, typeReg] of ctx.types) {
|
|
536
|
-
if (typeReg.schema.ast === valueType) {
|
|
537
|
-
const result = ctx.typeRegistry.get(regTypeName);
|
|
538
|
-
if (result) return result;
|
|
539
|
-
}
|
|
540
|
-
let regAst = typeReg.schema.ast;
|
|
541
|
-
while (regAst._tag === "Transformation") {
|
|
542
|
-
regAst = regAst.to;
|
|
543
|
-
if (regAst === valueType) {
|
|
544
|
-
const result = ctx.typeRegistry.get(regTypeName);
|
|
545
|
-
if (result) return result;
|
|
546
|
-
}
|
|
547
|
-
}
|
|
548
|
-
}
|
|
549
|
-
const innerResult = toGraphQLTypeWithRegistry(S2__namespace.make(valueType), ctx);
|
|
550
|
-
if (innerResult) {
|
|
551
|
-
return innerResult;
|
|
552
|
-
}
|
|
553
|
-
}
|
|
554
|
-
}
|
|
555
|
-
}
|
|
519
|
+
const registeredType = findRegisteredTypeInUnionMembers(ast.types, ctx);
|
|
520
|
+
if (registeredType) return registeredType;
|
|
556
521
|
if (ast.types.length > 0) {
|
|
557
522
|
return toGraphQLTypeWithRegistry(S2__namespace.make(ast.types[0]), ctx);
|
|
558
523
|
}
|
|
@@ -597,7 +562,7 @@ function findEnumForLiteral(ast, ctx) {
|
|
|
597
562
|
}
|
|
598
563
|
return void 0;
|
|
599
564
|
}
|
|
600
|
-
function
|
|
565
|
+
function handleTupleTypeAST2(ast, ctx) {
|
|
601
566
|
if (ast.rest && ast.rest.length > 0) {
|
|
602
567
|
const elementSchema = S2__namespace.make(ast.rest[0].type);
|
|
603
568
|
const elementType = toGraphQLTypeWithRegistry(elementSchema, ctx);
|
|
@@ -697,170 +662,40 @@ function buildInputTypeLookupCache(inputs, enums) {
|
|
|
697
662
|
}
|
|
698
663
|
return cache;
|
|
699
664
|
}
|
|
700
|
-
function
|
|
701
|
-
const ast = schema.ast;
|
|
665
|
+
function findRegisteredInputType(schema, ast, inputs, inputRegistry, cache) {
|
|
702
666
|
if (cache?.schemaToInputName || cache?.astToInputName) {
|
|
703
667
|
const inputName = cache.schemaToInputName?.get(schema) ?? cache.astToInputName?.get(ast);
|
|
704
668
|
if (inputName) {
|
|
705
|
-
|
|
706
|
-
if (result) return result;
|
|
669
|
+
return inputRegistry.get(inputName);
|
|
707
670
|
}
|
|
708
671
|
} else {
|
|
709
672
|
for (const [inputName, inputReg] of inputs) {
|
|
710
673
|
if (inputReg.schema.ast === ast || inputReg.schema === schema) {
|
|
711
|
-
|
|
712
|
-
if (result) return result;
|
|
674
|
+
return inputRegistry.get(inputName);
|
|
713
675
|
}
|
|
714
676
|
}
|
|
715
677
|
}
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
inputs,
|
|
732
|
-
enums,
|
|
733
|
-
cache
|
|
734
|
-
);
|
|
735
|
-
}
|
|
736
|
-
}
|
|
737
|
-
for (const [, inputReg] of inputs) {
|
|
738
|
-
if (inputReg.schema.ast === memberAst) {
|
|
739
|
-
return toGraphQLInputTypeWithRegistry(
|
|
740
|
-
inputReg.schema,
|
|
741
|
-
enumRegistry,
|
|
742
|
-
inputRegistry,
|
|
743
|
-
inputs,
|
|
744
|
-
enums,
|
|
745
|
-
cache
|
|
746
|
-
);
|
|
747
|
-
}
|
|
748
|
-
}
|
|
749
|
-
if (memberAst._tag === "Transformation") {
|
|
750
|
-
const innerToAst = memberAst.to;
|
|
751
|
-
const transformedInputName = cache?.astToInputName?.get(innerToAst);
|
|
752
|
-
if (transformedInputName) {
|
|
753
|
-
const inputReg = inputs.get(transformedInputName);
|
|
754
|
-
if (inputReg) {
|
|
755
|
-
return toGraphQLInputTypeWithRegistry(
|
|
756
|
-
inputReg.schema,
|
|
757
|
-
enumRegistry,
|
|
758
|
-
inputRegistry,
|
|
759
|
-
inputs,
|
|
760
|
-
enums,
|
|
761
|
-
cache
|
|
762
|
-
);
|
|
763
|
-
}
|
|
764
|
-
}
|
|
765
|
-
for (const [, inputReg] of inputs) {
|
|
766
|
-
if (inputReg.schema.ast === innerToAst) {
|
|
767
|
-
return toGraphQLInputTypeWithRegistry(
|
|
768
|
-
inputReg.schema,
|
|
769
|
-
enumRegistry,
|
|
770
|
-
inputRegistry,
|
|
771
|
-
inputs,
|
|
772
|
-
enums,
|
|
773
|
-
cache
|
|
774
|
-
);
|
|
775
|
-
}
|
|
776
|
-
}
|
|
777
|
-
}
|
|
778
|
-
if (memberAst._tag === "TypeLiteral") {
|
|
779
|
-
const valueField = memberAst.propertySignatures?.find(
|
|
780
|
-
(p) => String(p.name) === "value"
|
|
781
|
-
);
|
|
782
|
-
if (valueField) {
|
|
783
|
-
const valueType = valueField.type;
|
|
784
|
-
const valueInputName = cache?.astToInputName?.get(valueType);
|
|
785
|
-
if (valueInputName) {
|
|
786
|
-
const inputReg = inputs.get(valueInputName);
|
|
787
|
-
if (inputReg) {
|
|
788
|
-
return toGraphQLInputTypeWithRegistry(
|
|
789
|
-
inputReg.schema,
|
|
790
|
-
enumRegistry,
|
|
791
|
-
inputRegistry,
|
|
792
|
-
inputs,
|
|
793
|
-
enums,
|
|
794
|
-
cache
|
|
795
|
-
);
|
|
796
|
-
}
|
|
797
|
-
}
|
|
798
|
-
for (const [, inputReg] of inputs) {
|
|
799
|
-
if (inputReg.schema.ast === valueType) {
|
|
800
|
-
return toGraphQLInputTypeWithRegistry(
|
|
801
|
-
inputReg.schema,
|
|
802
|
-
enumRegistry,
|
|
803
|
-
inputRegistry,
|
|
804
|
-
inputs,
|
|
805
|
-
enums,
|
|
806
|
-
cache
|
|
807
|
-
);
|
|
808
|
-
}
|
|
809
|
-
let regAst = inputReg.schema.ast;
|
|
810
|
-
while (regAst._tag === "Transformation") {
|
|
811
|
-
regAst = regAst.to;
|
|
812
|
-
if (regAst === valueType) {
|
|
813
|
-
return toGraphQLInputTypeWithRegistry(
|
|
814
|
-
inputReg.schema,
|
|
815
|
-
enumRegistry,
|
|
816
|
-
inputRegistry,
|
|
817
|
-
inputs,
|
|
818
|
-
enums,
|
|
819
|
-
cache
|
|
820
|
-
);
|
|
821
|
-
}
|
|
822
|
-
}
|
|
823
|
-
if (regAst._tag === "Declaration" && regAst.typeParameters?.[0] === valueType) {
|
|
824
|
-
return toGraphQLInputTypeWithRegistry(
|
|
825
|
-
inputReg.schema,
|
|
826
|
-
enumRegistry,
|
|
827
|
-
inputRegistry,
|
|
828
|
-
inputs,
|
|
829
|
-
enums,
|
|
830
|
-
cache
|
|
831
|
-
);
|
|
832
|
-
}
|
|
833
|
-
}
|
|
834
|
-
const innerResult = toGraphQLInputTypeWithRegistry(
|
|
835
|
-
S2__namespace.make(valueType),
|
|
836
|
-
enumRegistry,
|
|
837
|
-
inputRegistry,
|
|
838
|
-
inputs,
|
|
839
|
-
enums,
|
|
840
|
-
cache
|
|
841
|
-
);
|
|
842
|
-
if (innerResult) {
|
|
843
|
-
return innerResult;
|
|
844
|
-
}
|
|
845
|
-
}
|
|
846
|
-
}
|
|
847
|
-
}
|
|
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
|
+
);
|
|
848
693
|
}
|
|
849
|
-
return toGraphQLInputTypeWithRegistry(
|
|
850
|
-
S2__namespace.make(toAst),
|
|
851
|
-
enumRegistry,
|
|
852
|
-
inputRegistry,
|
|
853
|
-
inputs,
|
|
854
|
-
enums,
|
|
855
|
-
cache
|
|
856
|
-
);
|
|
857
694
|
}
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
const nonUndefinedTypes = unionAst.types.filter((t) => t._tag !== "UndefinedKeyword");
|
|
861
|
-
if (nonUndefinedTypes.length === 1 && nonUndefinedTypes[0]._tag === "Union") {
|
|
695
|
+
for (const [, inputReg] of inputs) {
|
|
696
|
+
if (inputReg.schema.ast === memberAst) {
|
|
862
697
|
return toGraphQLInputTypeWithRegistry(
|
|
863
|
-
|
|
698
|
+
inputReg.schema,
|
|
864
699
|
enumRegistry,
|
|
865
700
|
inputRegistry,
|
|
866
701
|
inputs,
|
|
@@ -868,9 +703,18 @@ function toGraphQLInputTypeWithRegistry(schema, enumRegistry, inputRegistry, inp
|
|
|
868
703
|
cache
|
|
869
704
|
);
|
|
870
705
|
}
|
|
871
|
-
|
|
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) {
|
|
872
716
|
return toGraphQLInputTypeWithRegistry(
|
|
873
|
-
|
|
717
|
+
inputReg.schema,
|
|
874
718
|
enumRegistry,
|
|
875
719
|
inputRegistry,
|
|
876
720
|
inputs,
|
|
@@ -878,171 +722,210 @@ function toGraphQLInputTypeWithRegistry(schema, enumRegistry, inputRegistry, inp
|
|
|
878
722
|
cache
|
|
879
723
|
);
|
|
880
724
|
}
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
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
|
-
(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
|
|
940
783
|
);
|
|
941
|
-
if (valueField) {
|
|
942
|
-
const valueType = valueField.type;
|
|
943
|
-
const valueInputName = cache?.astToInputName?.get(valueType);
|
|
944
|
-
if (valueInputName) {
|
|
945
|
-
const inputReg = inputs.get(valueInputName);
|
|
946
|
-
if (inputReg) {
|
|
947
|
-
return toGraphQLInputTypeWithRegistry(
|
|
948
|
-
inputReg.schema,
|
|
949
|
-
enumRegistry,
|
|
950
|
-
inputRegistry,
|
|
951
|
-
inputs,
|
|
952
|
-
enums,
|
|
953
|
-
cache
|
|
954
|
-
);
|
|
955
|
-
}
|
|
956
|
-
}
|
|
957
|
-
for (const [, inputReg] of inputs) {
|
|
958
|
-
if (inputReg.schema.ast === valueType) {
|
|
959
|
-
return toGraphQLInputTypeWithRegistry(
|
|
960
|
-
inputReg.schema,
|
|
961
|
-
enumRegistry,
|
|
962
|
-
inputRegistry,
|
|
963
|
-
inputs,
|
|
964
|
-
enums,
|
|
965
|
-
cache
|
|
966
|
-
);
|
|
967
|
-
}
|
|
968
|
-
let regAst = inputReg.schema.ast;
|
|
969
|
-
while (regAst._tag === "Transformation") {
|
|
970
|
-
regAst = regAst.to;
|
|
971
|
-
if (regAst === valueType) {
|
|
972
|
-
return toGraphQLInputTypeWithRegistry(
|
|
973
|
-
inputReg.schema,
|
|
974
|
-
enumRegistry,
|
|
975
|
-
inputRegistry,
|
|
976
|
-
inputs,
|
|
977
|
-
enums,
|
|
978
|
-
cache
|
|
979
|
-
);
|
|
980
|
-
}
|
|
981
|
-
}
|
|
982
|
-
if (regAst._tag === "Declaration" && regAst.typeParameters?.[0] === valueType) {
|
|
983
|
-
return toGraphQLInputTypeWithRegistry(
|
|
984
|
-
inputReg.schema,
|
|
985
|
-
enumRegistry,
|
|
986
|
-
inputRegistry,
|
|
987
|
-
inputs,
|
|
988
|
-
enums,
|
|
989
|
-
cache
|
|
990
|
-
);
|
|
991
|
-
}
|
|
992
|
-
}
|
|
993
|
-
const innerResult = toGraphQLInputTypeWithRegistry(
|
|
994
|
-
S2__namespace.make(valueType),
|
|
995
|
-
enumRegistry,
|
|
996
|
-
inputRegistry,
|
|
997
|
-
inputs,
|
|
998
|
-
enums,
|
|
999
|
-
cache
|
|
1000
|
-
);
|
|
1001
|
-
if (innerResult) {
|
|
1002
|
-
return innerResult;
|
|
1003
|
-
}
|
|
1004
|
-
}
|
|
1005
784
|
}
|
|
1006
785
|
}
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
}
|
|
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
|
+
);
|
|
1017
795
|
}
|
|
1018
796
|
}
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
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])) {
|
|
1024
878
|
const result = enumRegistry.get(enumName);
|
|
1025
879
|
if (result) return result;
|
|
1026
880
|
}
|
|
1027
|
-
}
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
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);
|
|
1033
896
|
}
|
|
1034
897
|
}
|
|
1035
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
|
+
}
|
|
1036
927
|
if (ast._tag === "Suspend") {
|
|
1037
|
-
|
|
1038
|
-
return toGraphQLInputTypeWithRegistry(
|
|
1039
|
-
S2__namespace.make(innerAst),
|
|
1040
|
-
enumRegistry,
|
|
1041
|
-
inputRegistry,
|
|
1042
|
-
inputs,
|
|
1043
|
-
enums,
|
|
1044
|
-
cache
|
|
1045
|
-
);
|
|
928
|
+
return handleSuspendForInput(ast, inputs, inputRegistry, enumRegistry, enums, cache);
|
|
1046
929
|
}
|
|
1047
930
|
return toGraphQLInputType(schema);
|
|
1048
931
|
}
|