@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/index.cjs
CHANGED
|
@@ -38,7 +38,15 @@ var isIntegerType = (ast) => {
|
|
|
38
38
|
const annotations = refinement.annotations;
|
|
39
39
|
if (annotations) {
|
|
40
40
|
const identifier = AST__namespace.getIdentifierAnnotation(refinement);
|
|
41
|
-
if (identifier._tag === "Some"
|
|
41
|
+
if (identifier._tag === "Some") {
|
|
42
|
+
const id = identifier.value;
|
|
43
|
+
if (id === "Int" || id.includes("Int")) {
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
const JSONSchemaSymbol = /* @__PURE__ */ Symbol.for("effect/annotation/JSONSchema");
|
|
48
|
+
const jsonSchema = annotations[JSONSchemaSymbol];
|
|
49
|
+
if (jsonSchema && jsonSchema.type === "integer") {
|
|
42
50
|
return true;
|
|
43
51
|
}
|
|
44
52
|
}
|
|
@@ -46,6 +54,51 @@ var isIntegerType = (ast) => {
|
|
|
46
54
|
}
|
|
47
55
|
return false;
|
|
48
56
|
};
|
|
57
|
+
function handlePrimitiveAST(ast) {
|
|
58
|
+
if (ast._tag === "StringKeyword") return graphql.GraphQLString;
|
|
59
|
+
if (ast._tag === "NumberKeyword") return graphql.GraphQLFloat;
|
|
60
|
+
if (ast._tag === "BooleanKeyword") return graphql.GraphQLBoolean;
|
|
61
|
+
return void 0;
|
|
62
|
+
}
|
|
63
|
+
function handleRefinementAST(ast, convertFn) {
|
|
64
|
+
if (isIntegerType(ast)) {
|
|
65
|
+
return graphql.GraphQLInt;
|
|
66
|
+
}
|
|
67
|
+
return convertFn(S2__namespace.make(ast.from));
|
|
68
|
+
}
|
|
69
|
+
function handleLiteralAST(ast) {
|
|
70
|
+
if (ast._tag !== "Literal") return void 0;
|
|
71
|
+
if (typeof ast.literal === "string") return graphql.GraphQLString;
|
|
72
|
+
if (typeof ast.literal === "number") {
|
|
73
|
+
return Number.isInteger(ast.literal) ? graphql.GraphQLInt : graphql.GraphQLFloat;
|
|
74
|
+
}
|
|
75
|
+
if (typeof ast.literal === "boolean") return graphql.GraphQLBoolean;
|
|
76
|
+
return void 0;
|
|
77
|
+
}
|
|
78
|
+
function handleTupleTypeAST(ast, convertFn) {
|
|
79
|
+
if (ast._tag !== "TupleType") return void 0;
|
|
80
|
+
const elements = ast.elements;
|
|
81
|
+
if (elements.length > 0) {
|
|
82
|
+
const elementSchema = S2__namespace.make(elements[0].type);
|
|
83
|
+
return new graphql.GraphQLList(convertFn(elementSchema));
|
|
84
|
+
}
|
|
85
|
+
return void 0;
|
|
86
|
+
}
|
|
87
|
+
function buildFieldsFromPropertySignatures(propertySignatures, convertFn, isInput) {
|
|
88
|
+
const fields = {};
|
|
89
|
+
for (const field2 of propertySignatures) {
|
|
90
|
+
const fieldName = String(field2.name);
|
|
91
|
+
if (fieldName === "_tag") continue;
|
|
92
|
+
const fieldSchema = S2__namespace.make(field2.type);
|
|
93
|
+
let fieldType = convertFn(fieldSchema);
|
|
94
|
+
const isOptionField = isOptionTransformation(field2.type) || isOptionDeclaration(field2.type);
|
|
95
|
+
if (!field2.isOptional && !isOptionField) {
|
|
96
|
+
fieldType = new graphql.GraphQLNonNull(fieldType);
|
|
97
|
+
}
|
|
98
|
+
fields[fieldName] = { type: fieldType };
|
|
99
|
+
}
|
|
100
|
+
return fields;
|
|
101
|
+
}
|
|
49
102
|
var isOptionDeclaration = (ast) => {
|
|
50
103
|
if (ast._tag === "Declaration") {
|
|
51
104
|
const annotations = ast.annotations;
|
|
@@ -76,41 +129,17 @@ var getOptionInnerType = (ast) => {
|
|
|
76
129
|
};
|
|
77
130
|
var toGraphQLType = (schema) => {
|
|
78
131
|
const ast = schema.ast;
|
|
79
|
-
|
|
80
|
-
if (
|
|
81
|
-
if (ast._tag === "BooleanKeyword") return graphql.GraphQLBoolean;
|
|
132
|
+
const primitiveResult = handlePrimitiveAST(ast);
|
|
133
|
+
if (primitiveResult) return primitiveResult;
|
|
82
134
|
if (ast._tag === "Refinement") {
|
|
83
|
-
|
|
84
|
-
return graphql.GraphQLInt;
|
|
85
|
-
}
|
|
86
|
-
return toGraphQLType(S2__namespace.make(ast.from));
|
|
87
|
-
}
|
|
88
|
-
if (ast._tag === "Literal") {
|
|
89
|
-
if (typeof ast.literal === "string") return graphql.GraphQLString;
|
|
90
|
-
if (typeof ast.literal === "number") {
|
|
91
|
-
return Number.isInteger(ast.literal) ? graphql.GraphQLInt : graphql.GraphQLFloat;
|
|
92
|
-
}
|
|
93
|
-
if (typeof ast.literal === "boolean") return graphql.GraphQLBoolean;
|
|
94
|
-
}
|
|
95
|
-
if (ast._tag === "TupleType") {
|
|
96
|
-
const elements = ast.elements;
|
|
97
|
-
if (elements.length > 0) {
|
|
98
|
-
const elementSchema = S2__namespace.make(elements[0].type);
|
|
99
|
-
return new graphql.GraphQLList(toGraphQLType(elementSchema));
|
|
100
|
-
}
|
|
135
|
+
return handleRefinementAST(ast, toGraphQLType);
|
|
101
136
|
}
|
|
137
|
+
const literalResult = handleLiteralAST(ast);
|
|
138
|
+
if (literalResult) return literalResult;
|
|
139
|
+
const tupleResult = handleTupleTypeAST(ast, toGraphQLType);
|
|
140
|
+
if (tupleResult) return tupleResult;
|
|
102
141
|
if (ast._tag === "TypeLiteral") {
|
|
103
|
-
const fields =
|
|
104
|
-
for (const field2 of ast.propertySignatures) {
|
|
105
|
-
const fieldName = String(field2.name);
|
|
106
|
-
if (fieldName === "_tag") continue;
|
|
107
|
-
const fieldSchema = S2__namespace.make(field2.type);
|
|
108
|
-
let fieldType = toGraphQLType(fieldSchema);
|
|
109
|
-
if (!field2.isOptional) {
|
|
110
|
-
fieldType = new graphql.GraphQLNonNull(fieldType);
|
|
111
|
-
}
|
|
112
|
-
fields[fieldName] = { type: fieldType };
|
|
113
|
-
}
|
|
142
|
+
const fields = buildFieldsFromPropertySignatures(ast.propertySignatures, toGraphQLType);
|
|
114
143
|
const typeName = schema.annotations?.identifier || `Object_${Math.random().toString(36).slice(2, 11)}`;
|
|
115
144
|
return new graphql.GraphQLObjectType({
|
|
116
145
|
name: typeName,
|
|
@@ -152,41 +181,19 @@ var toGraphQLType = (schema) => {
|
|
|
152
181
|
};
|
|
153
182
|
var toGraphQLInputType = (schema) => {
|
|
154
183
|
const ast = schema.ast;
|
|
155
|
-
|
|
156
|
-
if (
|
|
157
|
-
if (ast._tag === "BooleanKeyword") return graphql.GraphQLBoolean;
|
|
184
|
+
const primitiveResult = handlePrimitiveAST(ast);
|
|
185
|
+
if (primitiveResult) return primitiveResult;
|
|
158
186
|
if (ast._tag === "Refinement") {
|
|
159
|
-
|
|
160
|
-
return graphql.GraphQLInt;
|
|
161
|
-
}
|
|
162
|
-
return toGraphQLInputType(S2__namespace.make(ast.from));
|
|
163
|
-
}
|
|
164
|
-
if (ast._tag === "Literal") {
|
|
165
|
-
if (typeof ast.literal === "string") return graphql.GraphQLString;
|
|
166
|
-
if (typeof ast.literal === "number") {
|
|
167
|
-
return Number.isInteger(ast.literal) ? graphql.GraphQLInt : graphql.GraphQLFloat;
|
|
168
|
-
}
|
|
169
|
-
if (typeof ast.literal === "boolean") return graphql.GraphQLBoolean;
|
|
170
|
-
}
|
|
171
|
-
if (ast._tag === "TupleType") {
|
|
172
|
-
const elements = ast.elements;
|
|
173
|
-
if (elements.length > 0) {
|
|
174
|
-
const elementSchema = S2__namespace.make(elements[0].type);
|
|
175
|
-
return new graphql.GraphQLList(toGraphQLInputType(elementSchema));
|
|
176
|
-
}
|
|
187
|
+
return handleRefinementAST(ast, toGraphQLInputType);
|
|
177
188
|
}
|
|
189
|
+
const literalResult = handleLiteralAST(ast);
|
|
190
|
+
if (literalResult) return literalResult;
|
|
191
|
+
const tupleResult = handleTupleTypeAST(ast, toGraphQLInputType);
|
|
192
|
+
if (tupleResult) return tupleResult;
|
|
178
193
|
if (ast._tag === "TypeLiteral") {
|
|
179
|
-
const fields =
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
if (fieldName === "_tag") continue;
|
|
183
|
-
const fieldSchema = S2__namespace.make(field2.type);
|
|
184
|
-
let fieldType = toGraphQLInputType(fieldSchema);
|
|
185
|
-
if (!field2.isOptional) {
|
|
186
|
-
fieldType = new graphql.GraphQLNonNull(fieldType);
|
|
187
|
-
}
|
|
188
|
-
fields[fieldName] = { type: fieldType };
|
|
189
|
-
}
|
|
194
|
+
const fields = buildFieldsFromPropertySignatures(
|
|
195
|
+
ast.propertySignatures,
|
|
196
|
+
toGraphQLInputType);
|
|
190
197
|
const typeName = schema.annotations?.identifier || `Input_${Math.random().toString(36).slice(2, 11)}`;
|
|
191
198
|
return new graphql.GraphQLInputObjectType({
|
|
192
199
|
name: typeName,
|
|
@@ -239,17 +246,8 @@ var toGraphQLObjectType = (name, schema, additionalFields) => {
|
|
|
239
246
|
}
|
|
240
247
|
}
|
|
241
248
|
if (ast._tag === "TypeLiteral") {
|
|
242
|
-
const
|
|
243
|
-
|
|
244
|
-
const fieldName = String(field2.name);
|
|
245
|
-
if (fieldName === "_tag") continue;
|
|
246
|
-
const fieldSchema = S2__namespace.make(field2.type);
|
|
247
|
-
let fieldType = toGraphQLType(fieldSchema);
|
|
248
|
-
if (!field2.isOptional) {
|
|
249
|
-
fieldType = new graphql.GraphQLNonNull(fieldType);
|
|
250
|
-
}
|
|
251
|
-
fields[fieldName] = { type: fieldType };
|
|
252
|
-
}
|
|
249
|
+
const baseFields = buildFieldsFromPropertySignatures(ast.propertySignatures, toGraphQLType);
|
|
250
|
+
const fields = { ...baseFields };
|
|
253
251
|
if (additionalFields) {
|
|
254
252
|
for (const [fieldName, fieldConfig] of Object.entries(additionalFields)) {
|
|
255
253
|
fields[fieldName] = {
|
|
@@ -271,17 +269,7 @@ var toGraphQLObjectType = (name, schema, additionalFields) => {
|
|
|
271
269
|
var toGraphQLArgs = (schema) => {
|
|
272
270
|
const ast = schema.ast;
|
|
273
271
|
if (ast._tag === "TypeLiteral") {
|
|
274
|
-
const args =
|
|
275
|
-
for (const field2 of ast.propertySignatures) {
|
|
276
|
-
const fieldName = String(field2.name);
|
|
277
|
-
if (fieldName === "_tag") continue;
|
|
278
|
-
const fieldSchema = S2__namespace.make(field2.type);
|
|
279
|
-
let fieldType = toGraphQLInputType(fieldSchema);
|
|
280
|
-
if (!field2.isOptional) {
|
|
281
|
-
fieldType = new graphql.GraphQLNonNull(fieldType);
|
|
282
|
-
}
|
|
283
|
-
args[fieldName] = { type: fieldType };
|
|
284
|
-
}
|
|
272
|
+
const args = buildFieldsFromPropertySignatures(ast.propertySignatures, toGraphQLInputType);
|
|
285
273
|
return args;
|
|
286
274
|
}
|
|
287
275
|
throw new Error(`Schema must be an object type to convert to GraphQL arguments`);
|
|
@@ -397,7 +385,7 @@ function toGraphQLTypeWithRegistry(schema, ctx) {
|
|
|
397
385
|
if (enumType2) return enumType2;
|
|
398
386
|
}
|
|
399
387
|
if (ast._tag === "TupleType") {
|
|
400
|
-
return
|
|
388
|
+
return handleTupleTypeAST2(ast, ctx);
|
|
401
389
|
}
|
|
402
390
|
if (ast._tag === "Declaration") {
|
|
403
391
|
if (isOptionDeclaration2(ast)) {
|
|
@@ -453,88 +441,112 @@ function getOptionInnerType2(ast) {
|
|
|
453
441
|
}
|
|
454
442
|
return void 0;
|
|
455
443
|
}
|
|
456
|
-
function
|
|
457
|
-
const
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
if (
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
const result = ctx.typeRegistry.get(regTypeName);
|
|
503
|
-
if (result) return result;
|
|
504
|
-
}
|
|
505
|
-
let regAst = typeReg.schema.ast;
|
|
506
|
-
while (regAst._tag === "Transformation") {
|
|
507
|
-
regAst = regAst.to;
|
|
508
|
-
if (regAst === valueType) {
|
|
509
|
-
const result = ctx.typeRegistry.get(regTypeName);
|
|
510
|
-
if (result) return result;
|
|
511
|
-
}
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
const innerResult = toGraphQLTypeWithRegistry(S2__namespace.make(valueType), ctx);
|
|
515
|
-
if (innerResult) return innerResult;
|
|
516
|
-
}
|
|
517
|
-
}
|
|
518
|
-
}
|
|
444
|
+
function findRegisteredTypeForAST(memberAst, ctx) {
|
|
445
|
+
const typeName = ctx.astToTypeName?.get(memberAst);
|
|
446
|
+
if (typeName) {
|
|
447
|
+
const result = ctx.typeRegistry.get(typeName);
|
|
448
|
+
if (result) return result;
|
|
449
|
+
}
|
|
450
|
+
for (const [regTypeName, typeReg] of ctx.types) {
|
|
451
|
+
if (typeReg.schema.ast === memberAst) {
|
|
452
|
+
const result = ctx.typeRegistry.get(regTypeName);
|
|
453
|
+
if (result) return result;
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
return void 0;
|
|
457
|
+
}
|
|
458
|
+
function findRegisteredTypeForTransformation(memberAst, ctx) {
|
|
459
|
+
if (memberAst._tag !== "Transformation") return void 0;
|
|
460
|
+
const innerToAst = memberAst.to;
|
|
461
|
+
const transformedTypeName = ctx.astToTypeName?.get(innerToAst);
|
|
462
|
+
if (transformedTypeName) {
|
|
463
|
+
const result = ctx.typeRegistry.get(transformedTypeName);
|
|
464
|
+
if (result) return result;
|
|
465
|
+
}
|
|
466
|
+
for (const [regTypeName, typeReg] of ctx.types) {
|
|
467
|
+
if (typeReg.schema.ast === innerToAst) {
|
|
468
|
+
const result = ctx.typeRegistry.get(regTypeName);
|
|
469
|
+
if (result) return result;
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
return void 0;
|
|
473
|
+
}
|
|
474
|
+
function findRegisteredTypeForOptionSome(memberAst, ctx) {
|
|
475
|
+
if (memberAst._tag !== "TypeLiteral") return void 0;
|
|
476
|
+
const valueField = memberAst.propertySignatures?.find(
|
|
477
|
+
(p) => String(p.name) === "value"
|
|
478
|
+
);
|
|
479
|
+
if (!valueField) return void 0;
|
|
480
|
+
const valueType = valueField.type;
|
|
481
|
+
const valueTypeName = ctx.astToTypeName?.get(valueType);
|
|
482
|
+
if (valueTypeName) {
|
|
483
|
+
const result = ctx.typeRegistry.get(valueTypeName);
|
|
484
|
+
if (result) return result;
|
|
485
|
+
}
|
|
486
|
+
for (const [regTypeName, typeReg] of ctx.types) {
|
|
487
|
+
if (typeReg.schema.ast === valueType) {
|
|
488
|
+
const result = ctx.typeRegistry.get(regTypeName);
|
|
489
|
+
if (result) return result;
|
|
519
490
|
}
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
491
|
+
let regAst = typeReg.schema.ast;
|
|
492
|
+
while (regAst._tag === "Transformation") {
|
|
493
|
+
regAst = regAst.to;
|
|
494
|
+
if (regAst === valueType) {
|
|
495
|
+
const result = ctx.typeRegistry.get(regTypeName);
|
|
496
|
+
if (result) return result;
|
|
497
|
+
}
|
|
523
498
|
}
|
|
524
499
|
}
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
500
|
+
const innerResult = toGraphQLTypeWithRegistry(S2__namespace.make(valueType), ctx);
|
|
501
|
+
return innerResult;
|
|
502
|
+
}
|
|
503
|
+
function handleOptionTransformation(ast, fromAst, toAst, ctx) {
|
|
504
|
+
if (fromAst && fromAst._tag === "Union") {
|
|
505
|
+
for (const memberAst of fromAst.types) {
|
|
506
|
+
if (memberAst._tag === "Literal") continue;
|
|
507
|
+
if (memberAst._tag === "UndefinedKeyword") continue;
|
|
508
|
+
const registeredType = findRegisteredTypeForAST(memberAst, ctx) || findRegisteredTypeForTransformation(memberAst, ctx) || findRegisteredTypeForOptionSome(memberAst, ctx);
|
|
509
|
+
if (registeredType) return registeredType;
|
|
534
510
|
}
|
|
535
511
|
}
|
|
512
|
+
const innerType = getOptionInnerType2(toAst);
|
|
513
|
+
if (innerType) {
|
|
514
|
+
return toGraphQLTypeWithRegistry(S2__namespace.make(innerType), ctx);
|
|
515
|
+
}
|
|
516
|
+
return void 0;
|
|
517
|
+
}
|
|
518
|
+
function handleArrayTransformation(toAst, ctx) {
|
|
519
|
+
if (toAst._tag !== "TupleType") return void 0;
|
|
520
|
+
let elementType;
|
|
521
|
+
if (toAst.rest && toAst.rest.length > 0) {
|
|
522
|
+
const elementSchema = S2__namespace.make(toAst.rest[0].type);
|
|
523
|
+
elementType = toGraphQLTypeWithRegistry(elementSchema, ctx);
|
|
524
|
+
} else if (toAst.elements.length > 0) {
|
|
525
|
+
const elementSchema = S2__namespace.make(toAst.elements[0].type);
|
|
526
|
+
elementType = toGraphQLTypeWithRegistry(elementSchema, ctx);
|
|
527
|
+
} else {
|
|
528
|
+
return void 0;
|
|
529
|
+
}
|
|
530
|
+
return new graphql.GraphQLList(elementType);
|
|
531
|
+
}
|
|
532
|
+
function handleTransformationAST(ast, ctx) {
|
|
533
|
+
const toAst = ast.to;
|
|
534
|
+
const fromAst = ast.from;
|
|
535
|
+
if (isOptionDeclaration2(toAst)) {
|
|
536
|
+
const optionResult = handleOptionTransformation(ast, fromAst, toAst, ctx);
|
|
537
|
+
if (optionResult) return optionResult;
|
|
538
|
+
}
|
|
539
|
+
const arrayResult = handleArrayTransformation(toAst, ctx);
|
|
540
|
+
if (arrayResult) return arrayResult;
|
|
536
541
|
return toGraphQLTypeWithRegistry(S2__namespace.make(ast.to), ctx);
|
|
537
542
|
}
|
|
543
|
+
function findRegisteredTypeInUnionMembers(types, ctx) {
|
|
544
|
+
for (const memberAst of types) {
|
|
545
|
+
const registeredType = findRegisteredTypeForAST(memberAst, ctx) || findRegisteredTypeForTransformation(memberAst, ctx) || findRegisteredTypeForOptionSome(memberAst, ctx);
|
|
546
|
+
if (registeredType) return registeredType;
|
|
547
|
+
}
|
|
548
|
+
return void 0;
|
|
549
|
+
}
|
|
538
550
|
function handleUnionAST(ast, ctx) {
|
|
539
551
|
const allLiterals = ast.types.every((t) => t._tag === "Literal");
|
|
540
552
|
if (allLiterals) {
|
|
@@ -544,64 +556,8 @@ function handleUnionAST(ast, ctx) {
|
|
|
544
556
|
const unionType2 = findRegisteredUnion(ast.types, ctx);
|
|
545
557
|
if (unionType2) return unionType2;
|
|
546
558
|
}
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
if (typeName) {
|
|
550
|
-
const result = ctx.typeRegistry.get(typeName);
|
|
551
|
-
if (result) return result;
|
|
552
|
-
}
|
|
553
|
-
for (const [regTypeName, typeReg] of ctx.types) {
|
|
554
|
-
if (typeReg.schema.ast === memberAst) {
|
|
555
|
-
const result = ctx.typeRegistry.get(regTypeName);
|
|
556
|
-
if (result) return result;
|
|
557
|
-
}
|
|
558
|
-
}
|
|
559
|
-
if (memberAst._tag === "Transformation") {
|
|
560
|
-
const toAst = memberAst.to;
|
|
561
|
-
const transformedTypeName = ctx.astToTypeName?.get(toAst);
|
|
562
|
-
if (transformedTypeName) {
|
|
563
|
-
const result = ctx.typeRegistry.get(transformedTypeName);
|
|
564
|
-
if (result) return result;
|
|
565
|
-
}
|
|
566
|
-
for (const [regTypeName, typeReg] of ctx.types) {
|
|
567
|
-
if (typeReg.schema.ast === toAst) {
|
|
568
|
-
const result = ctx.typeRegistry.get(regTypeName);
|
|
569
|
-
if (result) return result;
|
|
570
|
-
}
|
|
571
|
-
}
|
|
572
|
-
}
|
|
573
|
-
if (memberAst._tag === "TypeLiteral") {
|
|
574
|
-
const valueField = memberAst.propertySignatures?.find(
|
|
575
|
-
(p) => String(p.name) === "value"
|
|
576
|
-
);
|
|
577
|
-
if (valueField) {
|
|
578
|
-
const valueType = valueField.type;
|
|
579
|
-
const valueTypeName = ctx.astToTypeName?.get(valueType);
|
|
580
|
-
if (valueTypeName) {
|
|
581
|
-
const result = ctx.typeRegistry.get(valueTypeName);
|
|
582
|
-
if (result) return result;
|
|
583
|
-
}
|
|
584
|
-
for (const [regTypeName, typeReg] of ctx.types) {
|
|
585
|
-
if (typeReg.schema.ast === valueType) {
|
|
586
|
-
const result = ctx.typeRegistry.get(regTypeName);
|
|
587
|
-
if (result) return result;
|
|
588
|
-
}
|
|
589
|
-
let regAst = typeReg.schema.ast;
|
|
590
|
-
while (regAst._tag === "Transformation") {
|
|
591
|
-
regAst = regAst.to;
|
|
592
|
-
if (regAst === valueType) {
|
|
593
|
-
const result = ctx.typeRegistry.get(regTypeName);
|
|
594
|
-
if (result) return result;
|
|
595
|
-
}
|
|
596
|
-
}
|
|
597
|
-
}
|
|
598
|
-
const innerResult = toGraphQLTypeWithRegistry(S2__namespace.make(valueType), ctx);
|
|
599
|
-
if (innerResult) {
|
|
600
|
-
return innerResult;
|
|
601
|
-
}
|
|
602
|
-
}
|
|
603
|
-
}
|
|
604
|
-
}
|
|
559
|
+
const registeredType = findRegisteredTypeInUnionMembers(ast.types, ctx);
|
|
560
|
+
if (registeredType) return registeredType;
|
|
605
561
|
if (ast.types.length > 0) {
|
|
606
562
|
return toGraphQLTypeWithRegistry(S2__namespace.make(ast.types[0]), ctx);
|
|
607
563
|
}
|
|
@@ -646,7 +602,7 @@ function findEnumForLiteral(ast, ctx) {
|
|
|
646
602
|
}
|
|
647
603
|
return void 0;
|
|
648
604
|
}
|
|
649
|
-
function
|
|
605
|
+
function handleTupleTypeAST2(ast, ctx) {
|
|
650
606
|
if (ast.rest && ast.rest.length > 0) {
|
|
651
607
|
const elementSchema = S2__namespace.make(ast.rest[0].type);
|
|
652
608
|
const elementType = toGraphQLTypeWithRegistry(elementSchema, ctx);
|
|
@@ -746,170 +702,40 @@ function buildInputTypeLookupCache(inputs, enums) {
|
|
|
746
702
|
}
|
|
747
703
|
return cache;
|
|
748
704
|
}
|
|
749
|
-
function
|
|
750
|
-
const ast = schema.ast;
|
|
705
|
+
function findRegisteredInputType(schema, ast, inputs, inputRegistry, cache) {
|
|
751
706
|
if (cache?.schemaToInputName || cache?.astToInputName) {
|
|
752
707
|
const inputName = cache.schemaToInputName?.get(schema) ?? cache.astToInputName?.get(ast);
|
|
753
708
|
if (inputName) {
|
|
754
|
-
|
|
755
|
-
if (result) return result;
|
|
709
|
+
return inputRegistry.get(inputName);
|
|
756
710
|
}
|
|
757
711
|
} else {
|
|
758
712
|
for (const [inputName, inputReg] of inputs) {
|
|
759
713
|
if (inputReg.schema.ast === ast || inputReg.schema === schema) {
|
|
760
|
-
|
|
761
|
-
if (result) return result;
|
|
714
|
+
return inputRegistry.get(inputName);
|
|
762
715
|
}
|
|
763
716
|
}
|
|
764
717
|
}
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
inputs,
|
|
781
|
-
enums,
|
|
782
|
-
cache
|
|
783
|
-
);
|
|
784
|
-
}
|
|
785
|
-
}
|
|
786
|
-
for (const [, inputReg] of inputs) {
|
|
787
|
-
if (inputReg.schema.ast === memberAst) {
|
|
788
|
-
return toGraphQLInputTypeWithRegistry(
|
|
789
|
-
inputReg.schema,
|
|
790
|
-
enumRegistry,
|
|
791
|
-
inputRegistry,
|
|
792
|
-
inputs,
|
|
793
|
-
enums,
|
|
794
|
-
cache
|
|
795
|
-
);
|
|
796
|
-
}
|
|
797
|
-
}
|
|
798
|
-
if (memberAst._tag === "Transformation") {
|
|
799
|
-
const innerToAst = memberAst.to;
|
|
800
|
-
const transformedInputName = cache?.astToInputName?.get(innerToAst);
|
|
801
|
-
if (transformedInputName) {
|
|
802
|
-
const inputReg = inputs.get(transformedInputName);
|
|
803
|
-
if (inputReg) {
|
|
804
|
-
return toGraphQLInputTypeWithRegistry(
|
|
805
|
-
inputReg.schema,
|
|
806
|
-
enumRegistry,
|
|
807
|
-
inputRegistry,
|
|
808
|
-
inputs,
|
|
809
|
-
enums,
|
|
810
|
-
cache
|
|
811
|
-
);
|
|
812
|
-
}
|
|
813
|
-
}
|
|
814
|
-
for (const [, inputReg] of inputs) {
|
|
815
|
-
if (inputReg.schema.ast === innerToAst) {
|
|
816
|
-
return toGraphQLInputTypeWithRegistry(
|
|
817
|
-
inputReg.schema,
|
|
818
|
-
enumRegistry,
|
|
819
|
-
inputRegistry,
|
|
820
|
-
inputs,
|
|
821
|
-
enums,
|
|
822
|
-
cache
|
|
823
|
-
);
|
|
824
|
-
}
|
|
825
|
-
}
|
|
826
|
-
}
|
|
827
|
-
if (memberAst._tag === "TypeLiteral") {
|
|
828
|
-
const valueField = memberAst.propertySignatures?.find(
|
|
829
|
-
(p) => String(p.name) === "value"
|
|
830
|
-
);
|
|
831
|
-
if (valueField) {
|
|
832
|
-
const valueType = valueField.type;
|
|
833
|
-
const valueInputName = cache?.astToInputName?.get(valueType);
|
|
834
|
-
if (valueInputName) {
|
|
835
|
-
const inputReg = inputs.get(valueInputName);
|
|
836
|
-
if (inputReg) {
|
|
837
|
-
return toGraphQLInputTypeWithRegistry(
|
|
838
|
-
inputReg.schema,
|
|
839
|
-
enumRegistry,
|
|
840
|
-
inputRegistry,
|
|
841
|
-
inputs,
|
|
842
|
-
enums,
|
|
843
|
-
cache
|
|
844
|
-
);
|
|
845
|
-
}
|
|
846
|
-
}
|
|
847
|
-
for (const [, inputReg] of inputs) {
|
|
848
|
-
if (inputReg.schema.ast === valueType) {
|
|
849
|
-
return toGraphQLInputTypeWithRegistry(
|
|
850
|
-
inputReg.schema,
|
|
851
|
-
enumRegistry,
|
|
852
|
-
inputRegistry,
|
|
853
|
-
inputs,
|
|
854
|
-
enums,
|
|
855
|
-
cache
|
|
856
|
-
);
|
|
857
|
-
}
|
|
858
|
-
let regAst = inputReg.schema.ast;
|
|
859
|
-
while (regAst._tag === "Transformation") {
|
|
860
|
-
regAst = regAst.to;
|
|
861
|
-
if (regAst === valueType) {
|
|
862
|
-
return toGraphQLInputTypeWithRegistry(
|
|
863
|
-
inputReg.schema,
|
|
864
|
-
enumRegistry,
|
|
865
|
-
inputRegistry,
|
|
866
|
-
inputs,
|
|
867
|
-
enums,
|
|
868
|
-
cache
|
|
869
|
-
);
|
|
870
|
-
}
|
|
871
|
-
}
|
|
872
|
-
if (regAst._tag === "Declaration" && regAst.typeParameters?.[0] === valueType) {
|
|
873
|
-
return toGraphQLInputTypeWithRegistry(
|
|
874
|
-
inputReg.schema,
|
|
875
|
-
enumRegistry,
|
|
876
|
-
inputRegistry,
|
|
877
|
-
inputs,
|
|
878
|
-
enums,
|
|
879
|
-
cache
|
|
880
|
-
);
|
|
881
|
-
}
|
|
882
|
-
}
|
|
883
|
-
const innerResult = toGraphQLInputTypeWithRegistry(
|
|
884
|
-
S2__namespace.make(valueType),
|
|
885
|
-
enumRegistry,
|
|
886
|
-
inputRegistry,
|
|
887
|
-
inputs,
|
|
888
|
-
enums,
|
|
889
|
-
cache
|
|
890
|
-
);
|
|
891
|
-
if (innerResult) {
|
|
892
|
-
return innerResult;
|
|
893
|
-
}
|
|
894
|
-
}
|
|
895
|
-
}
|
|
896
|
-
}
|
|
718
|
+
return void 0;
|
|
719
|
+
}
|
|
720
|
+
function findRegisteredInputForAST(memberAst, inputs, inputRegistry, enumRegistry, enums, cache) {
|
|
721
|
+
const inputName = cache?.astToInputName?.get(memberAst);
|
|
722
|
+
if (inputName) {
|
|
723
|
+
const inputReg = inputs.get(inputName);
|
|
724
|
+
if (inputReg) {
|
|
725
|
+
return toGraphQLInputTypeWithRegistry(
|
|
726
|
+
inputReg.schema,
|
|
727
|
+
enumRegistry,
|
|
728
|
+
inputRegistry,
|
|
729
|
+
inputs,
|
|
730
|
+
enums,
|
|
731
|
+
cache
|
|
732
|
+
);
|
|
897
733
|
}
|
|
898
|
-
return toGraphQLInputTypeWithRegistry(
|
|
899
|
-
S2__namespace.make(toAst),
|
|
900
|
-
enumRegistry,
|
|
901
|
-
inputRegistry,
|
|
902
|
-
inputs,
|
|
903
|
-
enums,
|
|
904
|
-
cache
|
|
905
|
-
);
|
|
906
734
|
}
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
const nonUndefinedTypes = unionAst.types.filter((t) => t._tag !== "UndefinedKeyword");
|
|
910
|
-
if (nonUndefinedTypes.length === 1 && nonUndefinedTypes[0]._tag === "Union") {
|
|
735
|
+
for (const [, inputReg] of inputs) {
|
|
736
|
+
if (inputReg.schema.ast === memberAst) {
|
|
911
737
|
return toGraphQLInputTypeWithRegistry(
|
|
912
|
-
|
|
738
|
+
inputReg.schema,
|
|
913
739
|
enumRegistry,
|
|
914
740
|
inputRegistry,
|
|
915
741
|
inputs,
|
|
@@ -917,9 +743,18 @@ function toGraphQLInputTypeWithRegistry(schema, enumRegistry, inputRegistry, inp
|
|
|
917
743
|
cache
|
|
918
744
|
);
|
|
919
745
|
}
|
|
920
|
-
|
|
746
|
+
}
|
|
747
|
+
return void 0;
|
|
748
|
+
}
|
|
749
|
+
function findRegisteredInputForTransformation(memberAst, inputs, inputRegistry, enumRegistry, enums, cache) {
|
|
750
|
+
if (memberAst._tag !== "Transformation") return void 0;
|
|
751
|
+
const innerToAst = memberAst.to;
|
|
752
|
+
const transformedInputName = cache?.astToInputName?.get(innerToAst);
|
|
753
|
+
if (transformedInputName) {
|
|
754
|
+
const inputReg = inputs.get(transformedInputName);
|
|
755
|
+
if (inputReg) {
|
|
921
756
|
return toGraphQLInputTypeWithRegistry(
|
|
922
|
-
|
|
757
|
+
inputReg.schema,
|
|
923
758
|
enumRegistry,
|
|
924
759
|
inputRegistry,
|
|
925
760
|
inputs,
|
|
@@ -927,171 +762,210 @@ function toGraphQLInputTypeWithRegistry(schema, enumRegistry, inputRegistry, inp
|
|
|
927
762
|
cache
|
|
928
763
|
);
|
|
929
764
|
}
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
(p) => String(p.name) === "value"
|
|
765
|
+
}
|
|
766
|
+
for (const [, inputReg] of inputs) {
|
|
767
|
+
if (inputReg.schema.ast === innerToAst) {
|
|
768
|
+
return toGraphQLInputTypeWithRegistry(
|
|
769
|
+
inputReg.schema,
|
|
770
|
+
enumRegistry,
|
|
771
|
+
inputRegistry,
|
|
772
|
+
inputs,
|
|
773
|
+
enums,
|
|
774
|
+
cache
|
|
775
|
+
);
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
return void 0;
|
|
779
|
+
}
|
|
780
|
+
function findRegisteredInputForOptionSome(memberAst, inputs, inputRegistry, enumRegistry, enums, cache) {
|
|
781
|
+
if (memberAst._tag !== "TypeLiteral") return void 0;
|
|
782
|
+
const valueField = memberAst.propertySignatures?.find(
|
|
783
|
+
(p) => String(p.name) === "value"
|
|
784
|
+
);
|
|
785
|
+
if (!valueField) return void 0;
|
|
786
|
+
const valueType = valueField.type;
|
|
787
|
+
const valueInputName = cache?.astToInputName?.get(valueType);
|
|
788
|
+
if (valueInputName) {
|
|
789
|
+
const inputReg = inputs.get(valueInputName);
|
|
790
|
+
if (inputReg) {
|
|
791
|
+
return toGraphQLInputTypeWithRegistry(
|
|
792
|
+
inputReg.schema,
|
|
793
|
+
enumRegistry,
|
|
794
|
+
inputRegistry,
|
|
795
|
+
inputs,
|
|
796
|
+
enums,
|
|
797
|
+
cache
|
|
798
|
+
);
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
for (const [, inputReg] of inputs) {
|
|
802
|
+
if (inputReg.schema.ast === valueType) {
|
|
803
|
+
return toGraphQLInputTypeWithRegistry(
|
|
804
|
+
inputReg.schema,
|
|
805
|
+
enumRegistry,
|
|
806
|
+
inputRegistry,
|
|
807
|
+
inputs,
|
|
808
|
+
enums,
|
|
809
|
+
cache
|
|
810
|
+
);
|
|
811
|
+
}
|
|
812
|
+
let regAst = inputReg.schema.ast;
|
|
813
|
+
while (regAst._tag === "Transformation") {
|
|
814
|
+
regAst = regAst.to;
|
|
815
|
+
if (regAst === valueType) {
|
|
816
|
+
return toGraphQLInputTypeWithRegistry(
|
|
817
|
+
inputReg.schema,
|
|
818
|
+
enumRegistry,
|
|
819
|
+
inputRegistry,
|
|
820
|
+
inputs,
|
|
821
|
+
enums,
|
|
822
|
+
cache
|
|
989
823
|
);
|
|
990
|
-
if (valueField) {
|
|
991
|
-
const valueType = valueField.type;
|
|
992
|
-
const valueInputName = cache?.astToInputName?.get(valueType);
|
|
993
|
-
if (valueInputName) {
|
|
994
|
-
const inputReg = inputs.get(valueInputName);
|
|
995
|
-
if (inputReg) {
|
|
996
|
-
return toGraphQLInputTypeWithRegistry(
|
|
997
|
-
inputReg.schema,
|
|
998
|
-
enumRegistry,
|
|
999
|
-
inputRegistry,
|
|
1000
|
-
inputs,
|
|
1001
|
-
enums,
|
|
1002
|
-
cache
|
|
1003
|
-
);
|
|
1004
|
-
}
|
|
1005
|
-
}
|
|
1006
|
-
for (const [, inputReg] of inputs) {
|
|
1007
|
-
if (inputReg.schema.ast === valueType) {
|
|
1008
|
-
return toGraphQLInputTypeWithRegistry(
|
|
1009
|
-
inputReg.schema,
|
|
1010
|
-
enumRegistry,
|
|
1011
|
-
inputRegistry,
|
|
1012
|
-
inputs,
|
|
1013
|
-
enums,
|
|
1014
|
-
cache
|
|
1015
|
-
);
|
|
1016
|
-
}
|
|
1017
|
-
let regAst = inputReg.schema.ast;
|
|
1018
|
-
while (regAst._tag === "Transformation") {
|
|
1019
|
-
regAst = regAst.to;
|
|
1020
|
-
if (regAst === valueType) {
|
|
1021
|
-
return toGraphQLInputTypeWithRegistry(
|
|
1022
|
-
inputReg.schema,
|
|
1023
|
-
enumRegistry,
|
|
1024
|
-
inputRegistry,
|
|
1025
|
-
inputs,
|
|
1026
|
-
enums,
|
|
1027
|
-
cache
|
|
1028
|
-
);
|
|
1029
|
-
}
|
|
1030
|
-
}
|
|
1031
|
-
if (regAst._tag === "Declaration" && regAst.typeParameters?.[0] === valueType) {
|
|
1032
|
-
return toGraphQLInputTypeWithRegistry(
|
|
1033
|
-
inputReg.schema,
|
|
1034
|
-
enumRegistry,
|
|
1035
|
-
inputRegistry,
|
|
1036
|
-
inputs,
|
|
1037
|
-
enums,
|
|
1038
|
-
cache
|
|
1039
|
-
);
|
|
1040
|
-
}
|
|
1041
|
-
}
|
|
1042
|
-
const innerResult = toGraphQLInputTypeWithRegistry(
|
|
1043
|
-
S2__namespace.make(valueType),
|
|
1044
|
-
enumRegistry,
|
|
1045
|
-
inputRegistry,
|
|
1046
|
-
inputs,
|
|
1047
|
-
enums,
|
|
1048
|
-
cache
|
|
1049
|
-
);
|
|
1050
|
-
if (innerResult) {
|
|
1051
|
-
return innerResult;
|
|
1052
|
-
}
|
|
1053
|
-
}
|
|
1054
824
|
}
|
|
1055
825
|
}
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
}
|
|
826
|
+
if (regAst._tag === "Declaration" && regAst.typeParameters?.[0] === valueType) {
|
|
827
|
+
return toGraphQLInputTypeWithRegistry(
|
|
828
|
+
inputReg.schema,
|
|
829
|
+
enumRegistry,
|
|
830
|
+
inputRegistry,
|
|
831
|
+
inputs,
|
|
832
|
+
enums,
|
|
833
|
+
cache
|
|
834
|
+
);
|
|
1066
835
|
}
|
|
1067
836
|
}
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
837
|
+
const innerResult = toGraphQLInputTypeWithRegistry(
|
|
838
|
+
S2__namespace.make(valueType),
|
|
839
|
+
enumRegistry,
|
|
840
|
+
inputRegistry,
|
|
841
|
+
inputs,
|
|
842
|
+
enums,
|
|
843
|
+
cache
|
|
844
|
+
);
|
|
845
|
+
return innerResult || void 0;
|
|
846
|
+
}
|
|
847
|
+
function handleOptionTransformationForInput(fromAst, toAst, inputs, inputRegistry, enumRegistry, enums, cache) {
|
|
848
|
+
if (!fromAst || fromAst._tag !== "Union") return void 0;
|
|
849
|
+
for (const memberAst of fromAst.types) {
|
|
850
|
+
if (memberAst._tag === "Literal") continue;
|
|
851
|
+
if (memberAst._tag === "UndefinedKeyword") continue;
|
|
852
|
+
const registeredInput = findRegisteredInputForAST(memberAst, inputs, inputRegistry, enumRegistry, enums, cache) || findRegisteredInputForTransformation(memberAst, inputs, inputRegistry, enumRegistry, enums, cache) || findRegisteredInputForOptionSome(memberAst, inputs, inputRegistry, enumRegistry, enums, cache);
|
|
853
|
+
if (registeredInput) return registeredInput;
|
|
854
|
+
}
|
|
855
|
+
return void 0;
|
|
856
|
+
}
|
|
857
|
+
function handleTransformationForInput(ast, inputs, inputRegistry, enumRegistry, enums, cache) {
|
|
858
|
+
const toAst = ast.to;
|
|
859
|
+
const fromAst = ast.from;
|
|
860
|
+
if (isOptionDeclaration2(toAst)) {
|
|
861
|
+
const optionResult = handleOptionTransformationForInput(
|
|
862
|
+
fromAst,
|
|
863
|
+
toAst,
|
|
864
|
+
inputs,
|
|
865
|
+
inputRegistry,
|
|
866
|
+
enumRegistry,
|
|
867
|
+
enums,
|
|
868
|
+
cache
|
|
869
|
+
);
|
|
870
|
+
if (optionResult) return optionResult;
|
|
871
|
+
}
|
|
872
|
+
return toGraphQLInputTypeWithRegistry(
|
|
873
|
+
S2__namespace.make(toAst),
|
|
874
|
+
enumRegistry,
|
|
875
|
+
inputRegistry,
|
|
876
|
+
inputs,
|
|
877
|
+
enums,
|
|
878
|
+
cache
|
|
879
|
+
);
|
|
880
|
+
}
|
|
881
|
+
function findRegisteredInputInUnionMembers(types, inputs, inputRegistry, enumRegistry, enums, cache) {
|
|
882
|
+
for (const memberAst of types) {
|
|
883
|
+
const registeredInput = findRegisteredInputForAST(memberAst, inputs, inputRegistry, enumRegistry, enums, cache) || findRegisteredInputForTransformation(memberAst, inputs, inputRegistry, enumRegistry, enums, cache) || findRegisteredInputForOptionSome(memberAst, inputs, inputRegistry, enumRegistry, enums, cache);
|
|
884
|
+
if (registeredInput) return registeredInput;
|
|
885
|
+
}
|
|
886
|
+
return void 0;
|
|
887
|
+
}
|
|
888
|
+
function handleUnionForInput(ast, inputs, inputRegistry, enumRegistry, enums, cache) {
|
|
889
|
+
const unionAst = ast;
|
|
890
|
+
const nonUndefinedTypes = unionAst.types.filter((t) => t._tag !== "UndefinedKeyword");
|
|
891
|
+
if (nonUndefinedTypes.length === 1) {
|
|
892
|
+
if (nonUndefinedTypes[0]._tag === "Union" || nonUndefinedTypes[0]._tag === "TypeLiteral") {
|
|
893
|
+
return toGraphQLInputTypeWithRegistry(
|
|
894
|
+
S2__namespace.make(nonUndefinedTypes[0]),
|
|
895
|
+
enumRegistry,
|
|
896
|
+
inputRegistry,
|
|
897
|
+
inputs,
|
|
898
|
+
enums,
|
|
899
|
+
cache
|
|
900
|
+
);
|
|
901
|
+
}
|
|
902
|
+
}
|
|
903
|
+
const registeredInput = findRegisteredInputInUnionMembers(
|
|
904
|
+
unionAst.types,
|
|
905
|
+
inputs,
|
|
906
|
+
inputRegistry,
|
|
907
|
+
enumRegistry,
|
|
908
|
+
enums,
|
|
909
|
+
cache
|
|
910
|
+
);
|
|
911
|
+
if (registeredInput) return registeredInput;
|
|
912
|
+
const allLiterals = unionAst.types.every((t) => t._tag === "Literal");
|
|
913
|
+
if (allLiterals) {
|
|
914
|
+
const literalValues = unionAst.types.map((t) => String(t.literal)).sort();
|
|
915
|
+
for (const [enumName] of enums) {
|
|
916
|
+
const enumValues = cache?.enumSortedValues?.get(enumName) ?? [...enums.get(enumName).values].sort();
|
|
917
|
+
if (literalValues.length === enumValues.length && literalValues.every((v, i) => v === enumValues[i])) {
|
|
1073
918
|
const result = enumRegistry.get(enumName);
|
|
1074
919
|
if (result) return result;
|
|
1075
920
|
}
|
|
1076
|
-
}
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
return void 0;
|
|
924
|
+
}
|
|
925
|
+
function handleLiteralForInput(ast, enumRegistry, enums, cache) {
|
|
926
|
+
const literalValue = String(ast.literal);
|
|
927
|
+
if (cache?.literalToEnumName) {
|
|
928
|
+
const enumName = cache.literalToEnumName.get(literalValue);
|
|
929
|
+
if (enumName) {
|
|
930
|
+
return enumRegistry.get(enumName);
|
|
931
|
+
}
|
|
932
|
+
} else {
|
|
933
|
+
for (const [enumName, enumReg] of enums) {
|
|
934
|
+
if (enumReg.values.includes(literalValue)) {
|
|
935
|
+
return enumRegistry.get(enumName);
|
|
1082
936
|
}
|
|
1083
937
|
}
|
|
1084
938
|
}
|
|
939
|
+
return void 0;
|
|
940
|
+
}
|
|
941
|
+
function handleSuspendForInput(ast, inputs, inputRegistry, enumRegistry, enums, cache) {
|
|
942
|
+
const innerAst = ast.f();
|
|
943
|
+
return toGraphQLInputTypeWithRegistry(
|
|
944
|
+
S2__namespace.make(innerAst),
|
|
945
|
+
enumRegistry,
|
|
946
|
+
inputRegistry,
|
|
947
|
+
inputs,
|
|
948
|
+
enums,
|
|
949
|
+
cache
|
|
950
|
+
);
|
|
951
|
+
}
|
|
952
|
+
function toGraphQLInputTypeWithRegistry(schema, enumRegistry, inputRegistry, inputs, enums, cache) {
|
|
953
|
+
const ast = schema.ast;
|
|
954
|
+
const registeredInput = findRegisteredInputType(schema, ast, inputs, inputRegistry, cache);
|
|
955
|
+
if (registeredInput) return registeredInput;
|
|
956
|
+
if (ast._tag === "Transformation") {
|
|
957
|
+
return handleTransformationForInput(ast, inputs, inputRegistry, enumRegistry, enums, cache);
|
|
958
|
+
}
|
|
959
|
+
if (ast._tag === "Union") {
|
|
960
|
+
const unionResult = handleUnionForInput(ast, inputs, inputRegistry, enumRegistry, enums, cache);
|
|
961
|
+
if (unionResult) return unionResult;
|
|
962
|
+
}
|
|
963
|
+
if (ast._tag === "Literal") {
|
|
964
|
+
const literalResult = handleLiteralForInput(ast, enumRegistry, enums, cache);
|
|
965
|
+
if (literalResult) return literalResult;
|
|
966
|
+
}
|
|
1085
967
|
if (ast._tag === "Suspend") {
|
|
1086
|
-
|
|
1087
|
-
return toGraphQLInputTypeWithRegistry(
|
|
1088
|
-
S2__namespace.make(innerAst),
|
|
1089
|
-
enumRegistry,
|
|
1090
|
-
inputRegistry,
|
|
1091
|
-
inputs,
|
|
1092
|
-
enums,
|
|
1093
|
-
cache
|
|
1094
|
-
);
|
|
968
|
+
return handleSuspendForInput(ast, inputs, inputRegistry, enumRegistry, enums, cache);
|
|
1095
969
|
}
|
|
1096
970
|
return toGraphQLInputType(schema);
|
|
1097
971
|
}
|