@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.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { GraphQLDirective, GraphQLEnumType, GraphQLInputObjectType, GraphQLInterfaceType, GraphQLObjectType, GraphQLUnionType, GraphQLSchema, GraphQLNonNull, GraphQLString, GraphQLFloat, GraphQLBoolean, GraphQLInt,
|
|
1
|
+
import { GraphQLDirective, GraphQLEnumType, GraphQLInputObjectType, GraphQLInterfaceType, GraphQLObjectType, GraphQLUnionType, GraphQLSchema, GraphQLNonNull, GraphQLString, GraphQLList, GraphQLFloat, GraphQLBoolean, GraphQLInt, parse, GraphQLError, validate, execute as execute$1 } from 'graphql';
|
|
2
2
|
export { DirectiveLocation } from 'graphql';
|
|
3
3
|
import { Pipeable, Context, Runtime, Effect, Queue, Option, Stream, Fiber, Ref } from 'effect';
|
|
4
4
|
import * as S2 from 'effect/Schema';
|
|
@@ -27,6 +27,51 @@ var isIntegerType = (ast) => {
|
|
|
27
27
|
}
|
|
28
28
|
return false;
|
|
29
29
|
};
|
|
30
|
+
function handlePrimitiveAST(ast) {
|
|
31
|
+
if (ast._tag === "StringKeyword") return GraphQLString;
|
|
32
|
+
if (ast._tag === "NumberKeyword") return GraphQLFloat;
|
|
33
|
+
if (ast._tag === "BooleanKeyword") return GraphQLBoolean;
|
|
34
|
+
return void 0;
|
|
35
|
+
}
|
|
36
|
+
function handleRefinementAST(ast, convertFn) {
|
|
37
|
+
if (isIntegerType(ast)) {
|
|
38
|
+
return GraphQLInt;
|
|
39
|
+
}
|
|
40
|
+
return convertFn(S2.make(ast.from));
|
|
41
|
+
}
|
|
42
|
+
function handleLiteralAST(ast) {
|
|
43
|
+
if (ast._tag !== "Literal") return void 0;
|
|
44
|
+
if (typeof ast.literal === "string") return GraphQLString;
|
|
45
|
+
if (typeof ast.literal === "number") {
|
|
46
|
+
return Number.isInteger(ast.literal) ? GraphQLInt : GraphQLFloat;
|
|
47
|
+
}
|
|
48
|
+
if (typeof ast.literal === "boolean") return GraphQLBoolean;
|
|
49
|
+
return void 0;
|
|
50
|
+
}
|
|
51
|
+
function handleTupleTypeAST(ast, convertFn) {
|
|
52
|
+
if (ast._tag !== "TupleType") return void 0;
|
|
53
|
+
const elements = ast.elements;
|
|
54
|
+
if (elements.length > 0) {
|
|
55
|
+
const elementSchema = S2.make(elements[0].type);
|
|
56
|
+
return new GraphQLList(convertFn(elementSchema));
|
|
57
|
+
}
|
|
58
|
+
return void 0;
|
|
59
|
+
}
|
|
60
|
+
function buildFieldsFromPropertySignatures(propertySignatures, convertFn) {
|
|
61
|
+
const fields = {};
|
|
62
|
+
for (const field2 of propertySignatures) {
|
|
63
|
+
const fieldName = String(field2.name);
|
|
64
|
+
if (fieldName === "_tag") continue;
|
|
65
|
+
const fieldSchema = S2.make(field2.type);
|
|
66
|
+
let fieldType = convertFn(fieldSchema);
|
|
67
|
+
const isOptionField = isOptionTransformation(field2.type) || isOptionDeclaration(field2.type);
|
|
68
|
+
if (!field2.isOptional && !isOptionField) {
|
|
69
|
+
fieldType = new GraphQLNonNull(fieldType);
|
|
70
|
+
}
|
|
71
|
+
fields[fieldName] = { type: fieldType };
|
|
72
|
+
}
|
|
73
|
+
return fields;
|
|
74
|
+
}
|
|
30
75
|
var isOptionDeclaration = (ast) => {
|
|
31
76
|
if (ast._tag === "Declaration") {
|
|
32
77
|
const annotations = ast.annotations;
|
|
@@ -57,42 +102,17 @@ var getOptionInnerType = (ast) => {
|
|
|
57
102
|
};
|
|
58
103
|
var toGraphQLType = (schema) => {
|
|
59
104
|
const ast = schema.ast;
|
|
60
|
-
|
|
61
|
-
if (
|
|
62
|
-
if (ast._tag === "BooleanKeyword") return GraphQLBoolean;
|
|
105
|
+
const primitiveResult = handlePrimitiveAST(ast);
|
|
106
|
+
if (primitiveResult) return primitiveResult;
|
|
63
107
|
if (ast._tag === "Refinement") {
|
|
64
|
-
|
|
65
|
-
return GraphQLInt;
|
|
66
|
-
}
|
|
67
|
-
return toGraphQLType(S2.make(ast.from));
|
|
68
|
-
}
|
|
69
|
-
if (ast._tag === "Literal") {
|
|
70
|
-
if (typeof ast.literal === "string") return GraphQLString;
|
|
71
|
-
if (typeof ast.literal === "number") {
|
|
72
|
-
return Number.isInteger(ast.literal) ? GraphQLInt : GraphQLFloat;
|
|
73
|
-
}
|
|
74
|
-
if (typeof ast.literal === "boolean") return GraphQLBoolean;
|
|
75
|
-
}
|
|
76
|
-
if (ast._tag === "TupleType") {
|
|
77
|
-
const elements = ast.elements;
|
|
78
|
-
if (elements.length > 0) {
|
|
79
|
-
const elementSchema = S2.make(elements[0].type);
|
|
80
|
-
return new GraphQLList(toGraphQLType(elementSchema));
|
|
81
|
-
}
|
|
108
|
+
return handleRefinementAST(ast, toGraphQLType);
|
|
82
109
|
}
|
|
110
|
+
const literalResult = handleLiteralAST(ast);
|
|
111
|
+
if (literalResult) return literalResult;
|
|
112
|
+
const tupleResult = handleTupleTypeAST(ast, toGraphQLType);
|
|
113
|
+
if (tupleResult) return tupleResult;
|
|
83
114
|
if (ast._tag === "TypeLiteral") {
|
|
84
|
-
const fields =
|
|
85
|
-
for (const field2 of ast.propertySignatures) {
|
|
86
|
-
const fieldName = String(field2.name);
|
|
87
|
-
if (fieldName === "_tag") continue;
|
|
88
|
-
const fieldSchema = S2.make(field2.type);
|
|
89
|
-
let fieldType = toGraphQLType(fieldSchema);
|
|
90
|
-
const isOptionField = isOptionTransformation(field2.type) || isOptionDeclaration(field2.type);
|
|
91
|
-
if (!field2.isOptional && !isOptionField) {
|
|
92
|
-
fieldType = new GraphQLNonNull(fieldType);
|
|
93
|
-
}
|
|
94
|
-
fields[fieldName] = { type: fieldType };
|
|
95
|
-
}
|
|
115
|
+
const fields = buildFieldsFromPropertySignatures(ast.propertySignatures, toGraphQLType);
|
|
96
116
|
const typeName = schema.annotations?.identifier || `Object_${Math.random().toString(36).slice(2, 11)}`;
|
|
97
117
|
return new GraphQLObjectType({
|
|
98
118
|
name: typeName,
|
|
@@ -134,42 +154,20 @@ var toGraphQLType = (schema) => {
|
|
|
134
154
|
};
|
|
135
155
|
var toGraphQLInputType = (schema) => {
|
|
136
156
|
const ast = schema.ast;
|
|
137
|
-
|
|
138
|
-
if (
|
|
139
|
-
if (ast._tag === "BooleanKeyword") return GraphQLBoolean;
|
|
157
|
+
const primitiveResult = handlePrimitiveAST(ast);
|
|
158
|
+
if (primitiveResult) return primitiveResult;
|
|
140
159
|
if (ast._tag === "Refinement") {
|
|
141
|
-
|
|
142
|
-
return GraphQLInt;
|
|
143
|
-
}
|
|
144
|
-
return toGraphQLInputType(S2.make(ast.from));
|
|
145
|
-
}
|
|
146
|
-
if (ast._tag === "Literal") {
|
|
147
|
-
if (typeof ast.literal === "string") return GraphQLString;
|
|
148
|
-
if (typeof ast.literal === "number") {
|
|
149
|
-
return Number.isInteger(ast.literal) ? GraphQLInt : GraphQLFloat;
|
|
150
|
-
}
|
|
151
|
-
if (typeof ast.literal === "boolean") return GraphQLBoolean;
|
|
152
|
-
}
|
|
153
|
-
if (ast._tag === "TupleType") {
|
|
154
|
-
const elements = ast.elements;
|
|
155
|
-
if (elements.length > 0) {
|
|
156
|
-
const elementSchema = S2.make(elements[0].type);
|
|
157
|
-
return new GraphQLList(toGraphQLInputType(elementSchema));
|
|
158
|
-
}
|
|
160
|
+
return handleRefinementAST(ast, toGraphQLInputType);
|
|
159
161
|
}
|
|
162
|
+
const literalResult = handleLiteralAST(ast);
|
|
163
|
+
if (literalResult) return literalResult;
|
|
164
|
+
const tupleResult = handleTupleTypeAST(ast, toGraphQLInputType);
|
|
165
|
+
if (tupleResult) return tupleResult;
|
|
160
166
|
if (ast._tag === "TypeLiteral") {
|
|
161
|
-
const fields =
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
const fieldSchema = S2.make(field2.type);
|
|
166
|
-
let fieldType = toGraphQLInputType(fieldSchema);
|
|
167
|
-
const isOptionField = isOptionTransformation(field2.type) || isOptionDeclaration(field2.type);
|
|
168
|
-
if (!field2.isOptional && !isOptionField) {
|
|
169
|
-
fieldType = new GraphQLNonNull(fieldType);
|
|
170
|
-
}
|
|
171
|
-
fields[fieldName] = { type: fieldType };
|
|
172
|
-
}
|
|
167
|
+
const fields = buildFieldsFromPropertySignatures(
|
|
168
|
+
ast.propertySignatures,
|
|
169
|
+
toGraphQLInputType
|
|
170
|
+
);
|
|
173
171
|
const typeName = schema.annotations?.identifier || `Input_${Math.random().toString(36).slice(2, 11)}`;
|
|
174
172
|
return new GraphQLInputObjectType({
|
|
175
173
|
name: typeName,
|
|
@@ -210,18 +208,7 @@ var toGraphQLInputType = (schema) => {
|
|
|
210
208
|
var toGraphQLArgs = (schema) => {
|
|
211
209
|
const ast = schema.ast;
|
|
212
210
|
if (ast._tag === "TypeLiteral") {
|
|
213
|
-
const args =
|
|
214
|
-
for (const field2 of ast.propertySignatures) {
|
|
215
|
-
const fieldName = String(field2.name);
|
|
216
|
-
if (fieldName === "_tag") continue;
|
|
217
|
-
const fieldSchema = S2.make(field2.type);
|
|
218
|
-
let fieldType = toGraphQLInputType(fieldSchema);
|
|
219
|
-
const isOptionField = isOptionTransformation(field2.type) || isOptionDeclaration(field2.type);
|
|
220
|
-
if (!field2.isOptional && !isOptionField) {
|
|
221
|
-
fieldType = new GraphQLNonNull(fieldType);
|
|
222
|
-
}
|
|
223
|
-
args[fieldName] = { type: fieldType };
|
|
224
|
-
}
|
|
211
|
+
const args = buildFieldsFromPropertySignatures(ast.propertySignatures, toGraphQLInputType);
|
|
225
212
|
return args;
|
|
226
213
|
}
|
|
227
214
|
throw new Error(`Schema must be an object type to convert to GraphQL arguments`);
|
|
@@ -337,7 +324,7 @@ function toGraphQLTypeWithRegistry(schema, ctx) {
|
|
|
337
324
|
if (enumType2) return enumType2;
|
|
338
325
|
}
|
|
339
326
|
if (ast._tag === "TupleType") {
|
|
340
|
-
return
|
|
327
|
+
return handleTupleTypeAST2(ast, ctx);
|
|
341
328
|
}
|
|
342
329
|
if (ast._tag === "Declaration") {
|
|
343
330
|
if (isOptionDeclaration2(ast)) {
|
|
@@ -393,88 +380,112 @@ function getOptionInnerType2(ast) {
|
|
|
393
380
|
}
|
|
394
381
|
return void 0;
|
|
395
382
|
}
|
|
396
|
-
function
|
|
397
|
-
const
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
if (
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
for (const [regTypeName, typeReg] of ctx.types) {
|
|
423
|
-
if (typeReg.schema.ast === innerToAst) {
|
|
424
|
-
const result = ctx.typeRegistry.get(regTypeName);
|
|
425
|
-
if (result) return result;
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
}
|
|
429
|
-
if (memberAst._tag === "TypeLiteral") {
|
|
430
|
-
const valueField = memberAst.propertySignatures?.find(
|
|
431
|
-
(p) => String(p.name) === "value"
|
|
432
|
-
);
|
|
433
|
-
if (valueField) {
|
|
434
|
-
const valueType = valueField.type;
|
|
435
|
-
const valueTypeName = ctx.astToTypeName?.get(valueType);
|
|
436
|
-
if (valueTypeName) {
|
|
437
|
-
const result = ctx.typeRegistry.get(valueTypeName);
|
|
438
|
-
if (result) return result;
|
|
439
|
-
}
|
|
440
|
-
for (const [regTypeName, typeReg] of ctx.types) {
|
|
441
|
-
if (typeReg.schema.ast === valueType) {
|
|
442
|
-
const result = ctx.typeRegistry.get(regTypeName);
|
|
443
|
-
if (result) return result;
|
|
444
|
-
}
|
|
445
|
-
let regAst = typeReg.schema.ast;
|
|
446
|
-
while (regAst._tag === "Transformation") {
|
|
447
|
-
regAst = regAst.to;
|
|
448
|
-
if (regAst === valueType) {
|
|
449
|
-
const result = ctx.typeRegistry.get(regTypeName);
|
|
450
|
-
if (result) return result;
|
|
451
|
-
}
|
|
452
|
-
}
|
|
453
|
-
}
|
|
454
|
-
const innerResult = toGraphQLTypeWithRegistry(S2.make(valueType), ctx);
|
|
455
|
-
if (innerResult) return innerResult;
|
|
456
|
-
}
|
|
457
|
-
}
|
|
458
|
-
}
|
|
383
|
+
function findRegisteredTypeForAST(memberAst, ctx) {
|
|
384
|
+
const typeName = ctx.astToTypeName?.get(memberAst);
|
|
385
|
+
if (typeName) {
|
|
386
|
+
const result = ctx.typeRegistry.get(typeName);
|
|
387
|
+
if (result) return result;
|
|
388
|
+
}
|
|
389
|
+
for (const [regTypeName, typeReg] of ctx.types) {
|
|
390
|
+
if (typeReg.schema.ast === memberAst) {
|
|
391
|
+
const result = ctx.typeRegistry.get(regTypeName);
|
|
392
|
+
if (result) return result;
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
return void 0;
|
|
396
|
+
}
|
|
397
|
+
function findRegisteredTypeForTransformation(memberAst, ctx) {
|
|
398
|
+
if (memberAst._tag !== "Transformation") return void 0;
|
|
399
|
+
const innerToAst = memberAst.to;
|
|
400
|
+
const transformedTypeName = ctx.astToTypeName?.get(innerToAst);
|
|
401
|
+
if (transformedTypeName) {
|
|
402
|
+
const result = ctx.typeRegistry.get(transformedTypeName);
|
|
403
|
+
if (result) return result;
|
|
404
|
+
}
|
|
405
|
+
for (const [regTypeName, typeReg] of ctx.types) {
|
|
406
|
+
if (typeReg.schema.ast === innerToAst) {
|
|
407
|
+
const result = ctx.typeRegistry.get(regTypeName);
|
|
408
|
+
if (result) return result;
|
|
459
409
|
}
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
410
|
+
}
|
|
411
|
+
return void 0;
|
|
412
|
+
}
|
|
413
|
+
function findRegisteredTypeForOptionSome(memberAst, ctx) {
|
|
414
|
+
if (memberAst._tag !== "TypeLiteral") return void 0;
|
|
415
|
+
const valueField = memberAst.propertySignatures?.find(
|
|
416
|
+
(p) => String(p.name) === "value"
|
|
417
|
+
);
|
|
418
|
+
if (!valueField) return void 0;
|
|
419
|
+
const valueType = valueField.type;
|
|
420
|
+
const valueTypeName = ctx.astToTypeName?.get(valueType);
|
|
421
|
+
if (valueTypeName) {
|
|
422
|
+
const result = ctx.typeRegistry.get(valueTypeName);
|
|
423
|
+
if (result) return result;
|
|
424
|
+
}
|
|
425
|
+
for (const [regTypeName, typeReg] of ctx.types) {
|
|
426
|
+
if (typeReg.schema.ast === valueType) {
|
|
427
|
+
const result = ctx.typeRegistry.get(regTypeName);
|
|
428
|
+
if (result) return result;
|
|
429
|
+
}
|
|
430
|
+
let regAst = typeReg.schema.ast;
|
|
431
|
+
while (regAst._tag === "Transformation") {
|
|
432
|
+
regAst = regAst.to;
|
|
433
|
+
if (regAst === valueType) {
|
|
434
|
+
const result = ctx.typeRegistry.get(regTypeName);
|
|
435
|
+
if (result) return result;
|
|
436
|
+
}
|
|
463
437
|
}
|
|
464
438
|
}
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
439
|
+
const innerResult = toGraphQLTypeWithRegistry(S2.make(valueType), ctx);
|
|
440
|
+
return innerResult;
|
|
441
|
+
}
|
|
442
|
+
function handleOptionTransformation(ast, fromAst, toAst, ctx) {
|
|
443
|
+
if (fromAst && fromAst._tag === "Union") {
|
|
444
|
+
for (const memberAst of fromAst.types) {
|
|
445
|
+
if (memberAst._tag === "Literal") continue;
|
|
446
|
+
if (memberAst._tag === "UndefinedKeyword") continue;
|
|
447
|
+
const registeredType = findRegisteredTypeForAST(memberAst, ctx) || findRegisteredTypeForTransformation(memberAst, ctx) || findRegisteredTypeForOptionSome(memberAst, ctx);
|
|
448
|
+
if (registeredType) return registeredType;
|
|
474
449
|
}
|
|
475
450
|
}
|
|
451
|
+
const innerType = getOptionInnerType2(toAst);
|
|
452
|
+
if (innerType) {
|
|
453
|
+
return toGraphQLTypeWithRegistry(S2.make(innerType), ctx);
|
|
454
|
+
}
|
|
455
|
+
return void 0;
|
|
456
|
+
}
|
|
457
|
+
function handleArrayTransformation(toAst, ctx) {
|
|
458
|
+
if (toAst._tag !== "TupleType") return void 0;
|
|
459
|
+
let elementType;
|
|
460
|
+
if (toAst.rest && toAst.rest.length > 0) {
|
|
461
|
+
const elementSchema = S2.make(toAst.rest[0].type);
|
|
462
|
+
elementType = toGraphQLTypeWithRegistry(elementSchema, ctx);
|
|
463
|
+
} else if (toAst.elements.length > 0) {
|
|
464
|
+
const elementSchema = S2.make(toAst.elements[0].type);
|
|
465
|
+
elementType = toGraphQLTypeWithRegistry(elementSchema, ctx);
|
|
466
|
+
} else {
|
|
467
|
+
return void 0;
|
|
468
|
+
}
|
|
469
|
+
return new GraphQLList(elementType);
|
|
470
|
+
}
|
|
471
|
+
function handleTransformationAST(ast, ctx) {
|
|
472
|
+
const toAst = ast.to;
|
|
473
|
+
const fromAst = ast.from;
|
|
474
|
+
if (isOptionDeclaration2(toAst)) {
|
|
475
|
+
const optionResult = handleOptionTransformation(ast, fromAst, toAst, ctx);
|
|
476
|
+
if (optionResult) return optionResult;
|
|
477
|
+
}
|
|
478
|
+
const arrayResult = handleArrayTransformation(toAst, ctx);
|
|
479
|
+
if (arrayResult) return arrayResult;
|
|
476
480
|
return toGraphQLTypeWithRegistry(S2.make(ast.to), ctx);
|
|
477
481
|
}
|
|
482
|
+
function findRegisteredTypeInUnionMembers(types, ctx) {
|
|
483
|
+
for (const memberAst of types) {
|
|
484
|
+
const registeredType = findRegisteredTypeForAST(memberAst, ctx) || findRegisteredTypeForTransformation(memberAst, ctx) || findRegisteredTypeForOptionSome(memberAst, ctx);
|
|
485
|
+
if (registeredType) return registeredType;
|
|
486
|
+
}
|
|
487
|
+
return void 0;
|
|
488
|
+
}
|
|
478
489
|
function handleUnionAST(ast, ctx) {
|
|
479
490
|
const allLiterals = ast.types.every((t) => t._tag === "Literal");
|
|
480
491
|
if (allLiterals) {
|
|
@@ -484,64 +495,8 @@ function handleUnionAST(ast, ctx) {
|
|
|
484
495
|
const unionType2 = findRegisteredUnion(ast.types, ctx);
|
|
485
496
|
if (unionType2) return unionType2;
|
|
486
497
|
}
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
if (typeName) {
|
|
490
|
-
const result = ctx.typeRegistry.get(typeName);
|
|
491
|
-
if (result) return result;
|
|
492
|
-
}
|
|
493
|
-
for (const [regTypeName, typeReg] of ctx.types) {
|
|
494
|
-
if (typeReg.schema.ast === memberAst) {
|
|
495
|
-
const result = ctx.typeRegistry.get(regTypeName);
|
|
496
|
-
if (result) return result;
|
|
497
|
-
}
|
|
498
|
-
}
|
|
499
|
-
if (memberAst._tag === "Transformation") {
|
|
500
|
-
const toAst = memberAst.to;
|
|
501
|
-
const transformedTypeName = ctx.astToTypeName?.get(toAst);
|
|
502
|
-
if (transformedTypeName) {
|
|
503
|
-
const result = ctx.typeRegistry.get(transformedTypeName);
|
|
504
|
-
if (result) return result;
|
|
505
|
-
}
|
|
506
|
-
for (const [regTypeName, typeReg] of ctx.types) {
|
|
507
|
-
if (typeReg.schema.ast === toAst) {
|
|
508
|
-
const result = ctx.typeRegistry.get(regTypeName);
|
|
509
|
-
if (result) return result;
|
|
510
|
-
}
|
|
511
|
-
}
|
|
512
|
-
}
|
|
513
|
-
if (memberAst._tag === "TypeLiteral") {
|
|
514
|
-
const valueField = memberAst.propertySignatures?.find(
|
|
515
|
-
(p) => String(p.name) === "value"
|
|
516
|
-
);
|
|
517
|
-
if (valueField) {
|
|
518
|
-
const valueType = valueField.type;
|
|
519
|
-
const valueTypeName = ctx.astToTypeName?.get(valueType);
|
|
520
|
-
if (valueTypeName) {
|
|
521
|
-
const result = ctx.typeRegistry.get(valueTypeName);
|
|
522
|
-
if (result) return result;
|
|
523
|
-
}
|
|
524
|
-
for (const [regTypeName, typeReg] of ctx.types) {
|
|
525
|
-
if (typeReg.schema.ast === valueType) {
|
|
526
|
-
const result = ctx.typeRegistry.get(regTypeName);
|
|
527
|
-
if (result) return result;
|
|
528
|
-
}
|
|
529
|
-
let regAst = typeReg.schema.ast;
|
|
530
|
-
while (regAst._tag === "Transformation") {
|
|
531
|
-
regAst = regAst.to;
|
|
532
|
-
if (regAst === valueType) {
|
|
533
|
-
const result = ctx.typeRegistry.get(regTypeName);
|
|
534
|
-
if (result) return result;
|
|
535
|
-
}
|
|
536
|
-
}
|
|
537
|
-
}
|
|
538
|
-
const innerResult = toGraphQLTypeWithRegistry(S2.make(valueType), ctx);
|
|
539
|
-
if (innerResult) {
|
|
540
|
-
return innerResult;
|
|
541
|
-
}
|
|
542
|
-
}
|
|
543
|
-
}
|
|
544
|
-
}
|
|
498
|
+
const registeredType = findRegisteredTypeInUnionMembers(ast.types, ctx);
|
|
499
|
+
if (registeredType) return registeredType;
|
|
545
500
|
if (ast.types.length > 0) {
|
|
546
501
|
return toGraphQLTypeWithRegistry(S2.make(ast.types[0]), ctx);
|
|
547
502
|
}
|
|
@@ -586,7 +541,7 @@ function findEnumForLiteral(ast, ctx) {
|
|
|
586
541
|
}
|
|
587
542
|
return void 0;
|
|
588
543
|
}
|
|
589
|
-
function
|
|
544
|
+
function handleTupleTypeAST2(ast, ctx) {
|
|
590
545
|
if (ast.rest && ast.rest.length > 0) {
|
|
591
546
|
const elementSchema = S2.make(ast.rest[0].type);
|
|
592
547
|
const elementType = toGraphQLTypeWithRegistry(elementSchema, ctx);
|
|
@@ -686,170 +641,40 @@ function buildInputTypeLookupCache(inputs, enums) {
|
|
|
686
641
|
}
|
|
687
642
|
return cache;
|
|
688
643
|
}
|
|
689
|
-
function
|
|
690
|
-
const ast = schema.ast;
|
|
644
|
+
function findRegisteredInputType(schema, ast, inputs, inputRegistry, cache) {
|
|
691
645
|
if (cache?.schemaToInputName || cache?.astToInputName) {
|
|
692
646
|
const inputName = cache.schemaToInputName?.get(schema) ?? cache.astToInputName?.get(ast);
|
|
693
647
|
if (inputName) {
|
|
694
|
-
|
|
695
|
-
if (result) return result;
|
|
648
|
+
return inputRegistry.get(inputName);
|
|
696
649
|
}
|
|
697
650
|
} else {
|
|
698
651
|
for (const [inputName, inputReg] of inputs) {
|
|
699
652
|
if (inputReg.schema.ast === ast || inputReg.schema === schema) {
|
|
700
|
-
|
|
701
|
-
if (result) return result;
|
|
653
|
+
return inputRegistry.get(inputName);
|
|
702
654
|
}
|
|
703
655
|
}
|
|
704
656
|
}
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
inputs,
|
|
721
|
-
enums,
|
|
722
|
-
cache
|
|
723
|
-
);
|
|
724
|
-
}
|
|
725
|
-
}
|
|
726
|
-
for (const [, inputReg] of inputs) {
|
|
727
|
-
if (inputReg.schema.ast === memberAst) {
|
|
728
|
-
return toGraphQLInputTypeWithRegistry(
|
|
729
|
-
inputReg.schema,
|
|
730
|
-
enumRegistry,
|
|
731
|
-
inputRegistry,
|
|
732
|
-
inputs,
|
|
733
|
-
enums,
|
|
734
|
-
cache
|
|
735
|
-
);
|
|
736
|
-
}
|
|
737
|
-
}
|
|
738
|
-
if (memberAst._tag === "Transformation") {
|
|
739
|
-
const innerToAst = memberAst.to;
|
|
740
|
-
const transformedInputName = cache?.astToInputName?.get(innerToAst);
|
|
741
|
-
if (transformedInputName) {
|
|
742
|
-
const inputReg = inputs.get(transformedInputName);
|
|
743
|
-
if (inputReg) {
|
|
744
|
-
return toGraphQLInputTypeWithRegistry(
|
|
745
|
-
inputReg.schema,
|
|
746
|
-
enumRegistry,
|
|
747
|
-
inputRegistry,
|
|
748
|
-
inputs,
|
|
749
|
-
enums,
|
|
750
|
-
cache
|
|
751
|
-
);
|
|
752
|
-
}
|
|
753
|
-
}
|
|
754
|
-
for (const [, inputReg] of inputs) {
|
|
755
|
-
if (inputReg.schema.ast === innerToAst) {
|
|
756
|
-
return toGraphQLInputTypeWithRegistry(
|
|
757
|
-
inputReg.schema,
|
|
758
|
-
enumRegistry,
|
|
759
|
-
inputRegistry,
|
|
760
|
-
inputs,
|
|
761
|
-
enums,
|
|
762
|
-
cache
|
|
763
|
-
);
|
|
764
|
-
}
|
|
765
|
-
}
|
|
766
|
-
}
|
|
767
|
-
if (memberAst._tag === "TypeLiteral") {
|
|
768
|
-
const valueField = memberAst.propertySignatures?.find(
|
|
769
|
-
(p) => String(p.name) === "value"
|
|
770
|
-
);
|
|
771
|
-
if (valueField) {
|
|
772
|
-
const valueType = valueField.type;
|
|
773
|
-
const valueInputName = cache?.astToInputName?.get(valueType);
|
|
774
|
-
if (valueInputName) {
|
|
775
|
-
const inputReg = inputs.get(valueInputName);
|
|
776
|
-
if (inputReg) {
|
|
777
|
-
return toGraphQLInputTypeWithRegistry(
|
|
778
|
-
inputReg.schema,
|
|
779
|
-
enumRegistry,
|
|
780
|
-
inputRegistry,
|
|
781
|
-
inputs,
|
|
782
|
-
enums,
|
|
783
|
-
cache
|
|
784
|
-
);
|
|
785
|
-
}
|
|
786
|
-
}
|
|
787
|
-
for (const [, inputReg] of inputs) {
|
|
788
|
-
if (inputReg.schema.ast === valueType) {
|
|
789
|
-
return toGraphQLInputTypeWithRegistry(
|
|
790
|
-
inputReg.schema,
|
|
791
|
-
enumRegistry,
|
|
792
|
-
inputRegistry,
|
|
793
|
-
inputs,
|
|
794
|
-
enums,
|
|
795
|
-
cache
|
|
796
|
-
);
|
|
797
|
-
}
|
|
798
|
-
let regAst = inputReg.schema.ast;
|
|
799
|
-
while (regAst._tag === "Transformation") {
|
|
800
|
-
regAst = regAst.to;
|
|
801
|
-
if (regAst === valueType) {
|
|
802
|
-
return toGraphQLInputTypeWithRegistry(
|
|
803
|
-
inputReg.schema,
|
|
804
|
-
enumRegistry,
|
|
805
|
-
inputRegistry,
|
|
806
|
-
inputs,
|
|
807
|
-
enums,
|
|
808
|
-
cache
|
|
809
|
-
);
|
|
810
|
-
}
|
|
811
|
-
}
|
|
812
|
-
if (regAst._tag === "Declaration" && regAst.typeParameters?.[0] === valueType) {
|
|
813
|
-
return toGraphQLInputTypeWithRegistry(
|
|
814
|
-
inputReg.schema,
|
|
815
|
-
enumRegistry,
|
|
816
|
-
inputRegistry,
|
|
817
|
-
inputs,
|
|
818
|
-
enums,
|
|
819
|
-
cache
|
|
820
|
-
);
|
|
821
|
-
}
|
|
822
|
-
}
|
|
823
|
-
const innerResult = toGraphQLInputTypeWithRegistry(
|
|
824
|
-
S2.make(valueType),
|
|
825
|
-
enumRegistry,
|
|
826
|
-
inputRegistry,
|
|
827
|
-
inputs,
|
|
828
|
-
enums,
|
|
829
|
-
cache
|
|
830
|
-
);
|
|
831
|
-
if (innerResult) {
|
|
832
|
-
return innerResult;
|
|
833
|
-
}
|
|
834
|
-
}
|
|
835
|
-
}
|
|
836
|
-
}
|
|
657
|
+
return void 0;
|
|
658
|
+
}
|
|
659
|
+
function findRegisteredInputForAST(memberAst, inputs, inputRegistry, enumRegistry, enums, cache) {
|
|
660
|
+
const inputName = cache?.astToInputName?.get(memberAst);
|
|
661
|
+
if (inputName) {
|
|
662
|
+
const inputReg = inputs.get(inputName);
|
|
663
|
+
if (inputReg) {
|
|
664
|
+
return toGraphQLInputTypeWithRegistry(
|
|
665
|
+
inputReg.schema,
|
|
666
|
+
enumRegistry,
|
|
667
|
+
inputRegistry,
|
|
668
|
+
inputs,
|
|
669
|
+
enums,
|
|
670
|
+
cache
|
|
671
|
+
);
|
|
837
672
|
}
|
|
838
|
-
return toGraphQLInputTypeWithRegistry(
|
|
839
|
-
S2.make(toAst),
|
|
840
|
-
enumRegistry,
|
|
841
|
-
inputRegistry,
|
|
842
|
-
inputs,
|
|
843
|
-
enums,
|
|
844
|
-
cache
|
|
845
|
-
);
|
|
846
673
|
}
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
const nonUndefinedTypes = unionAst.types.filter((t) => t._tag !== "UndefinedKeyword");
|
|
850
|
-
if (nonUndefinedTypes.length === 1 && nonUndefinedTypes[0]._tag === "Union") {
|
|
674
|
+
for (const [, inputReg] of inputs) {
|
|
675
|
+
if (inputReg.schema.ast === memberAst) {
|
|
851
676
|
return toGraphQLInputTypeWithRegistry(
|
|
852
|
-
|
|
677
|
+
inputReg.schema,
|
|
853
678
|
enumRegistry,
|
|
854
679
|
inputRegistry,
|
|
855
680
|
inputs,
|
|
@@ -857,9 +682,18 @@ function toGraphQLInputTypeWithRegistry(schema, enumRegistry, inputRegistry, inp
|
|
|
857
682
|
cache
|
|
858
683
|
);
|
|
859
684
|
}
|
|
860
|
-
|
|
685
|
+
}
|
|
686
|
+
return void 0;
|
|
687
|
+
}
|
|
688
|
+
function findRegisteredInputForTransformation(memberAst, inputs, inputRegistry, enumRegistry, enums, cache) {
|
|
689
|
+
if (memberAst._tag !== "Transformation") return void 0;
|
|
690
|
+
const innerToAst = memberAst.to;
|
|
691
|
+
const transformedInputName = cache?.astToInputName?.get(innerToAst);
|
|
692
|
+
if (transformedInputName) {
|
|
693
|
+
const inputReg = inputs.get(transformedInputName);
|
|
694
|
+
if (inputReg) {
|
|
861
695
|
return toGraphQLInputTypeWithRegistry(
|
|
862
|
-
|
|
696
|
+
inputReg.schema,
|
|
863
697
|
enumRegistry,
|
|
864
698
|
inputRegistry,
|
|
865
699
|
inputs,
|
|
@@ -867,171 +701,210 @@ function toGraphQLInputTypeWithRegistry(schema, enumRegistry, inputRegistry, inp
|
|
|
867
701
|
cache
|
|
868
702
|
);
|
|
869
703
|
}
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
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
|
-
(p) => String(p.name) === "value"
|
|
704
|
+
}
|
|
705
|
+
for (const [, inputReg] of inputs) {
|
|
706
|
+
if (inputReg.schema.ast === innerToAst) {
|
|
707
|
+
return toGraphQLInputTypeWithRegistry(
|
|
708
|
+
inputReg.schema,
|
|
709
|
+
enumRegistry,
|
|
710
|
+
inputRegistry,
|
|
711
|
+
inputs,
|
|
712
|
+
enums,
|
|
713
|
+
cache
|
|
714
|
+
);
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
return void 0;
|
|
718
|
+
}
|
|
719
|
+
function findRegisteredInputForOptionSome(memberAst, inputs, inputRegistry, enumRegistry, enums, cache) {
|
|
720
|
+
if (memberAst._tag !== "TypeLiteral") return void 0;
|
|
721
|
+
const valueField = memberAst.propertySignatures?.find(
|
|
722
|
+
(p) => String(p.name) === "value"
|
|
723
|
+
);
|
|
724
|
+
if (!valueField) return void 0;
|
|
725
|
+
const valueType = valueField.type;
|
|
726
|
+
const valueInputName = cache?.astToInputName?.get(valueType);
|
|
727
|
+
if (valueInputName) {
|
|
728
|
+
const inputReg = inputs.get(valueInputName);
|
|
729
|
+
if (inputReg) {
|
|
730
|
+
return toGraphQLInputTypeWithRegistry(
|
|
731
|
+
inputReg.schema,
|
|
732
|
+
enumRegistry,
|
|
733
|
+
inputRegistry,
|
|
734
|
+
inputs,
|
|
735
|
+
enums,
|
|
736
|
+
cache
|
|
737
|
+
);
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
for (const [, inputReg] of inputs) {
|
|
741
|
+
if (inputReg.schema.ast === valueType) {
|
|
742
|
+
return toGraphQLInputTypeWithRegistry(
|
|
743
|
+
inputReg.schema,
|
|
744
|
+
enumRegistry,
|
|
745
|
+
inputRegistry,
|
|
746
|
+
inputs,
|
|
747
|
+
enums,
|
|
748
|
+
cache
|
|
749
|
+
);
|
|
750
|
+
}
|
|
751
|
+
let regAst = inputReg.schema.ast;
|
|
752
|
+
while (regAst._tag === "Transformation") {
|
|
753
|
+
regAst = regAst.to;
|
|
754
|
+
if (regAst === valueType) {
|
|
755
|
+
return toGraphQLInputTypeWithRegistry(
|
|
756
|
+
inputReg.schema,
|
|
757
|
+
enumRegistry,
|
|
758
|
+
inputRegistry,
|
|
759
|
+
inputs,
|
|
760
|
+
enums,
|
|
761
|
+
cache
|
|
929
762
|
);
|
|
930
|
-
if (valueField) {
|
|
931
|
-
const valueType = valueField.type;
|
|
932
|
-
const valueInputName = cache?.astToInputName?.get(valueType);
|
|
933
|
-
if (valueInputName) {
|
|
934
|
-
const inputReg = inputs.get(valueInputName);
|
|
935
|
-
if (inputReg) {
|
|
936
|
-
return toGraphQLInputTypeWithRegistry(
|
|
937
|
-
inputReg.schema,
|
|
938
|
-
enumRegistry,
|
|
939
|
-
inputRegistry,
|
|
940
|
-
inputs,
|
|
941
|
-
enums,
|
|
942
|
-
cache
|
|
943
|
-
);
|
|
944
|
-
}
|
|
945
|
-
}
|
|
946
|
-
for (const [, inputReg] of inputs) {
|
|
947
|
-
if (inputReg.schema.ast === valueType) {
|
|
948
|
-
return toGraphQLInputTypeWithRegistry(
|
|
949
|
-
inputReg.schema,
|
|
950
|
-
enumRegistry,
|
|
951
|
-
inputRegistry,
|
|
952
|
-
inputs,
|
|
953
|
-
enums,
|
|
954
|
-
cache
|
|
955
|
-
);
|
|
956
|
-
}
|
|
957
|
-
let regAst = inputReg.schema.ast;
|
|
958
|
-
while (regAst._tag === "Transformation") {
|
|
959
|
-
regAst = regAst.to;
|
|
960
|
-
if (regAst === valueType) {
|
|
961
|
-
return toGraphQLInputTypeWithRegistry(
|
|
962
|
-
inputReg.schema,
|
|
963
|
-
enumRegistry,
|
|
964
|
-
inputRegistry,
|
|
965
|
-
inputs,
|
|
966
|
-
enums,
|
|
967
|
-
cache
|
|
968
|
-
);
|
|
969
|
-
}
|
|
970
|
-
}
|
|
971
|
-
if (regAst._tag === "Declaration" && regAst.typeParameters?.[0] === valueType) {
|
|
972
|
-
return toGraphQLInputTypeWithRegistry(
|
|
973
|
-
inputReg.schema,
|
|
974
|
-
enumRegistry,
|
|
975
|
-
inputRegistry,
|
|
976
|
-
inputs,
|
|
977
|
-
enums,
|
|
978
|
-
cache
|
|
979
|
-
);
|
|
980
|
-
}
|
|
981
|
-
}
|
|
982
|
-
const innerResult = toGraphQLInputTypeWithRegistry(
|
|
983
|
-
S2.make(valueType),
|
|
984
|
-
enumRegistry,
|
|
985
|
-
inputRegistry,
|
|
986
|
-
inputs,
|
|
987
|
-
enums,
|
|
988
|
-
cache
|
|
989
|
-
);
|
|
990
|
-
if (innerResult) {
|
|
991
|
-
return innerResult;
|
|
992
|
-
}
|
|
993
|
-
}
|
|
994
763
|
}
|
|
995
764
|
}
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
}
|
|
765
|
+
if (regAst._tag === "Declaration" && regAst.typeParameters?.[0] === valueType) {
|
|
766
|
+
return toGraphQLInputTypeWithRegistry(
|
|
767
|
+
inputReg.schema,
|
|
768
|
+
enumRegistry,
|
|
769
|
+
inputRegistry,
|
|
770
|
+
inputs,
|
|
771
|
+
enums,
|
|
772
|
+
cache
|
|
773
|
+
);
|
|
1006
774
|
}
|
|
1007
775
|
}
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
776
|
+
const innerResult = toGraphQLInputTypeWithRegistry(
|
|
777
|
+
S2.make(valueType),
|
|
778
|
+
enumRegistry,
|
|
779
|
+
inputRegistry,
|
|
780
|
+
inputs,
|
|
781
|
+
enums,
|
|
782
|
+
cache
|
|
783
|
+
);
|
|
784
|
+
return innerResult || void 0;
|
|
785
|
+
}
|
|
786
|
+
function handleOptionTransformationForInput(fromAst, toAst, inputs, inputRegistry, enumRegistry, enums, cache) {
|
|
787
|
+
if (!fromAst || fromAst._tag !== "Union") return void 0;
|
|
788
|
+
for (const memberAst of fromAst.types) {
|
|
789
|
+
if (memberAst._tag === "Literal") continue;
|
|
790
|
+
if (memberAst._tag === "UndefinedKeyword") continue;
|
|
791
|
+
const registeredInput = findRegisteredInputForAST(memberAst, inputs, inputRegistry, enumRegistry, enums, cache) || findRegisteredInputForTransformation(memberAst, inputs, inputRegistry, enumRegistry, enums, cache) || findRegisteredInputForOptionSome(memberAst, inputs, inputRegistry, enumRegistry, enums, cache);
|
|
792
|
+
if (registeredInput) return registeredInput;
|
|
793
|
+
}
|
|
794
|
+
return void 0;
|
|
795
|
+
}
|
|
796
|
+
function handleTransformationForInput(ast, inputs, inputRegistry, enumRegistry, enums, cache) {
|
|
797
|
+
const toAst = ast.to;
|
|
798
|
+
const fromAst = ast.from;
|
|
799
|
+
if (isOptionDeclaration2(toAst)) {
|
|
800
|
+
const optionResult = handleOptionTransformationForInput(
|
|
801
|
+
fromAst,
|
|
802
|
+
toAst,
|
|
803
|
+
inputs,
|
|
804
|
+
inputRegistry,
|
|
805
|
+
enumRegistry,
|
|
806
|
+
enums,
|
|
807
|
+
cache
|
|
808
|
+
);
|
|
809
|
+
if (optionResult) return optionResult;
|
|
810
|
+
}
|
|
811
|
+
return toGraphQLInputTypeWithRegistry(
|
|
812
|
+
S2.make(toAst),
|
|
813
|
+
enumRegistry,
|
|
814
|
+
inputRegistry,
|
|
815
|
+
inputs,
|
|
816
|
+
enums,
|
|
817
|
+
cache
|
|
818
|
+
);
|
|
819
|
+
}
|
|
820
|
+
function findRegisteredInputInUnionMembers(types, inputs, inputRegistry, enumRegistry, enums, cache) {
|
|
821
|
+
for (const memberAst of types) {
|
|
822
|
+
const registeredInput = findRegisteredInputForAST(memberAst, inputs, inputRegistry, enumRegistry, enums, cache) || findRegisteredInputForTransformation(memberAst, inputs, inputRegistry, enumRegistry, enums, cache) || findRegisteredInputForOptionSome(memberAst, inputs, inputRegistry, enumRegistry, enums, cache);
|
|
823
|
+
if (registeredInput) return registeredInput;
|
|
824
|
+
}
|
|
825
|
+
return void 0;
|
|
826
|
+
}
|
|
827
|
+
function handleUnionForInput(ast, inputs, inputRegistry, enumRegistry, enums, cache) {
|
|
828
|
+
const unionAst = ast;
|
|
829
|
+
const nonUndefinedTypes = unionAst.types.filter((t) => t._tag !== "UndefinedKeyword");
|
|
830
|
+
if (nonUndefinedTypes.length === 1) {
|
|
831
|
+
if (nonUndefinedTypes[0]._tag === "Union" || nonUndefinedTypes[0]._tag === "TypeLiteral") {
|
|
832
|
+
return toGraphQLInputTypeWithRegistry(
|
|
833
|
+
S2.make(nonUndefinedTypes[0]),
|
|
834
|
+
enumRegistry,
|
|
835
|
+
inputRegistry,
|
|
836
|
+
inputs,
|
|
837
|
+
enums,
|
|
838
|
+
cache
|
|
839
|
+
);
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
const registeredInput = findRegisteredInputInUnionMembers(
|
|
843
|
+
unionAst.types,
|
|
844
|
+
inputs,
|
|
845
|
+
inputRegistry,
|
|
846
|
+
enumRegistry,
|
|
847
|
+
enums,
|
|
848
|
+
cache
|
|
849
|
+
);
|
|
850
|
+
if (registeredInput) return registeredInput;
|
|
851
|
+
const allLiterals = unionAst.types.every((t) => t._tag === "Literal");
|
|
852
|
+
if (allLiterals) {
|
|
853
|
+
const literalValues = unionAst.types.map((t) => String(t.literal)).sort();
|
|
854
|
+
for (const [enumName] of enums) {
|
|
855
|
+
const enumValues = cache?.enumSortedValues?.get(enumName) ?? [...enums.get(enumName).values].sort();
|
|
856
|
+
if (literalValues.length === enumValues.length && literalValues.every((v, i) => v === enumValues[i])) {
|
|
1013
857
|
const result = enumRegistry.get(enumName);
|
|
1014
858
|
if (result) return result;
|
|
1015
859
|
}
|
|
1016
|
-
}
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
return void 0;
|
|
863
|
+
}
|
|
864
|
+
function handleLiteralForInput(ast, enumRegistry, enums, cache) {
|
|
865
|
+
const literalValue = String(ast.literal);
|
|
866
|
+
if (cache?.literalToEnumName) {
|
|
867
|
+
const enumName = cache.literalToEnumName.get(literalValue);
|
|
868
|
+
if (enumName) {
|
|
869
|
+
return enumRegistry.get(enumName);
|
|
870
|
+
}
|
|
871
|
+
} else {
|
|
872
|
+
for (const [enumName, enumReg] of enums) {
|
|
873
|
+
if (enumReg.values.includes(literalValue)) {
|
|
874
|
+
return enumRegistry.get(enumName);
|
|
1022
875
|
}
|
|
1023
876
|
}
|
|
1024
877
|
}
|
|
878
|
+
return void 0;
|
|
879
|
+
}
|
|
880
|
+
function handleSuspendForInput(ast, inputs, inputRegistry, enumRegistry, enums, cache) {
|
|
881
|
+
const innerAst = ast.f();
|
|
882
|
+
return toGraphQLInputTypeWithRegistry(
|
|
883
|
+
S2.make(innerAst),
|
|
884
|
+
enumRegistry,
|
|
885
|
+
inputRegistry,
|
|
886
|
+
inputs,
|
|
887
|
+
enums,
|
|
888
|
+
cache
|
|
889
|
+
);
|
|
890
|
+
}
|
|
891
|
+
function toGraphQLInputTypeWithRegistry(schema, enumRegistry, inputRegistry, inputs, enums, cache) {
|
|
892
|
+
const ast = schema.ast;
|
|
893
|
+
const registeredInput = findRegisteredInputType(schema, ast, inputs, inputRegistry, cache);
|
|
894
|
+
if (registeredInput) return registeredInput;
|
|
895
|
+
if (ast._tag === "Transformation") {
|
|
896
|
+
return handleTransformationForInput(ast, inputs, inputRegistry, enumRegistry, enums, cache);
|
|
897
|
+
}
|
|
898
|
+
if (ast._tag === "Union") {
|
|
899
|
+
const unionResult = handleUnionForInput(ast, inputs, inputRegistry, enumRegistry, enums, cache);
|
|
900
|
+
if (unionResult) return unionResult;
|
|
901
|
+
}
|
|
902
|
+
if (ast._tag === "Literal") {
|
|
903
|
+
const literalResult = handleLiteralForInput(ast, enumRegistry, enums, cache);
|
|
904
|
+
if (literalResult) return literalResult;
|
|
905
|
+
}
|
|
1025
906
|
if (ast._tag === "Suspend") {
|
|
1026
|
-
|
|
1027
|
-
return toGraphQLInputTypeWithRegistry(
|
|
1028
|
-
S2.make(innerAst),
|
|
1029
|
-
enumRegistry,
|
|
1030
|
-
inputRegistry,
|
|
1031
|
-
inputs,
|
|
1032
|
-
enums,
|
|
1033
|
-
cache
|
|
1034
|
-
);
|
|
907
|
+
return handleSuspendForInput(ast, inputs, inputRegistry, enumRegistry, enums, cache);
|
|
1035
908
|
}
|
|
1036
909
|
return toGraphQLInputType(schema);
|
|
1037
910
|
}
|