@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/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, Kind, specifiedRules, NoSchemaIntrospectionCustomRule, subscribe, GraphQLScalarType } from 'graphql';
|
|
2
2
|
export { DirectiveLocation, GraphQLBoolean, GraphQLEnumType, GraphQLFloat, GraphQLID, GraphQLInputObjectType, GraphQLInt, GraphQLInterfaceType, GraphQLList, GraphQLNonNull, GraphQLObjectType, GraphQLScalarType, GraphQLSchema, GraphQLString, GraphQLUnionType, Kind, graphql, lexicographicSortSchema, printSchema } from 'graphql';
|
|
3
3
|
import { Pipeable, Context, Data, Layer, Effect, Ref, HashMap, Config, Option, Schema, Runtime, Queue, Stream, Fiber, Deferred } from 'effect';
|
|
4
4
|
import * as S2 from 'effect/Schema';
|
|
@@ -29,6 +29,51 @@ var isIntegerType = (ast) => {
|
|
|
29
29
|
}
|
|
30
30
|
return false;
|
|
31
31
|
};
|
|
32
|
+
function handlePrimitiveAST(ast) {
|
|
33
|
+
if (ast._tag === "StringKeyword") return GraphQLString;
|
|
34
|
+
if (ast._tag === "NumberKeyword") return GraphQLFloat;
|
|
35
|
+
if (ast._tag === "BooleanKeyword") return GraphQLBoolean;
|
|
36
|
+
return void 0;
|
|
37
|
+
}
|
|
38
|
+
function handleRefinementAST(ast, convertFn) {
|
|
39
|
+
if (isIntegerType(ast)) {
|
|
40
|
+
return GraphQLInt;
|
|
41
|
+
}
|
|
42
|
+
return convertFn(S2.make(ast.from));
|
|
43
|
+
}
|
|
44
|
+
function handleLiteralAST(ast) {
|
|
45
|
+
if (ast._tag !== "Literal") return void 0;
|
|
46
|
+
if (typeof ast.literal === "string") return GraphQLString;
|
|
47
|
+
if (typeof ast.literal === "number") {
|
|
48
|
+
return Number.isInteger(ast.literal) ? GraphQLInt : GraphQLFloat;
|
|
49
|
+
}
|
|
50
|
+
if (typeof ast.literal === "boolean") return GraphQLBoolean;
|
|
51
|
+
return void 0;
|
|
52
|
+
}
|
|
53
|
+
function handleTupleTypeAST(ast, convertFn) {
|
|
54
|
+
if (ast._tag !== "TupleType") return void 0;
|
|
55
|
+
const elements = ast.elements;
|
|
56
|
+
if (elements.length > 0) {
|
|
57
|
+
const elementSchema = S2.make(elements[0].type);
|
|
58
|
+
return new GraphQLList(convertFn(elementSchema));
|
|
59
|
+
}
|
|
60
|
+
return void 0;
|
|
61
|
+
}
|
|
62
|
+
function buildFieldsFromPropertySignatures(propertySignatures, convertFn) {
|
|
63
|
+
const fields = {};
|
|
64
|
+
for (const field2 of propertySignatures) {
|
|
65
|
+
const fieldName = String(field2.name);
|
|
66
|
+
if (fieldName === "_tag") continue;
|
|
67
|
+
const fieldSchema = S2.make(field2.type);
|
|
68
|
+
let fieldType = convertFn(fieldSchema);
|
|
69
|
+
const isOptionField = isOptionTransformation(field2.type) || isOptionDeclaration(field2.type);
|
|
70
|
+
if (!field2.isOptional && !isOptionField) {
|
|
71
|
+
fieldType = new GraphQLNonNull(fieldType);
|
|
72
|
+
}
|
|
73
|
+
fields[fieldName] = { type: fieldType };
|
|
74
|
+
}
|
|
75
|
+
return fields;
|
|
76
|
+
}
|
|
32
77
|
var isOptionDeclaration = (ast) => {
|
|
33
78
|
if (ast._tag === "Declaration") {
|
|
34
79
|
const annotations = ast.annotations;
|
|
@@ -59,42 +104,17 @@ var getOptionInnerType = (ast) => {
|
|
|
59
104
|
};
|
|
60
105
|
var toGraphQLType = (schema) => {
|
|
61
106
|
const ast = schema.ast;
|
|
62
|
-
|
|
63
|
-
if (
|
|
64
|
-
if (ast._tag === "BooleanKeyword") return GraphQLBoolean;
|
|
107
|
+
const primitiveResult = handlePrimitiveAST(ast);
|
|
108
|
+
if (primitiveResult) return primitiveResult;
|
|
65
109
|
if (ast._tag === "Refinement") {
|
|
66
|
-
|
|
67
|
-
return GraphQLInt;
|
|
68
|
-
}
|
|
69
|
-
return toGraphQLType(S2.make(ast.from));
|
|
70
|
-
}
|
|
71
|
-
if (ast._tag === "Literal") {
|
|
72
|
-
if (typeof ast.literal === "string") return GraphQLString;
|
|
73
|
-
if (typeof ast.literal === "number") {
|
|
74
|
-
return Number.isInteger(ast.literal) ? GraphQLInt : GraphQLFloat;
|
|
75
|
-
}
|
|
76
|
-
if (typeof ast.literal === "boolean") return GraphQLBoolean;
|
|
77
|
-
}
|
|
78
|
-
if (ast._tag === "TupleType") {
|
|
79
|
-
const elements = ast.elements;
|
|
80
|
-
if (elements.length > 0) {
|
|
81
|
-
const elementSchema = S2.make(elements[0].type);
|
|
82
|
-
return new GraphQLList(toGraphQLType(elementSchema));
|
|
83
|
-
}
|
|
110
|
+
return handleRefinementAST(ast, toGraphQLType);
|
|
84
111
|
}
|
|
112
|
+
const literalResult = handleLiteralAST(ast);
|
|
113
|
+
if (literalResult) return literalResult;
|
|
114
|
+
const tupleResult = handleTupleTypeAST(ast, toGraphQLType);
|
|
115
|
+
if (tupleResult) return tupleResult;
|
|
85
116
|
if (ast._tag === "TypeLiteral") {
|
|
86
|
-
const fields =
|
|
87
|
-
for (const field2 of ast.propertySignatures) {
|
|
88
|
-
const fieldName = String(field2.name);
|
|
89
|
-
if (fieldName === "_tag") continue;
|
|
90
|
-
const fieldSchema = S2.make(field2.type);
|
|
91
|
-
let fieldType = toGraphQLType(fieldSchema);
|
|
92
|
-
const isOptionField = isOptionTransformation(field2.type) || isOptionDeclaration(field2.type);
|
|
93
|
-
if (!field2.isOptional && !isOptionField) {
|
|
94
|
-
fieldType = new GraphQLNonNull(fieldType);
|
|
95
|
-
}
|
|
96
|
-
fields[fieldName] = { type: fieldType };
|
|
97
|
-
}
|
|
117
|
+
const fields = buildFieldsFromPropertySignatures(ast.propertySignatures, toGraphQLType);
|
|
98
118
|
const typeName = schema.annotations?.identifier || `Object_${Math.random().toString(36).slice(2, 11)}`;
|
|
99
119
|
return new GraphQLObjectType({
|
|
100
120
|
name: typeName,
|
|
@@ -136,42 +156,20 @@ var toGraphQLType = (schema) => {
|
|
|
136
156
|
};
|
|
137
157
|
var toGraphQLInputType = (schema) => {
|
|
138
158
|
const ast = schema.ast;
|
|
139
|
-
|
|
140
|
-
if (
|
|
141
|
-
if (ast._tag === "BooleanKeyword") return GraphQLBoolean;
|
|
159
|
+
const primitiveResult = handlePrimitiveAST(ast);
|
|
160
|
+
if (primitiveResult) return primitiveResult;
|
|
142
161
|
if (ast._tag === "Refinement") {
|
|
143
|
-
|
|
144
|
-
return GraphQLInt;
|
|
145
|
-
}
|
|
146
|
-
return toGraphQLInputType(S2.make(ast.from));
|
|
147
|
-
}
|
|
148
|
-
if (ast._tag === "Literal") {
|
|
149
|
-
if (typeof ast.literal === "string") return GraphQLString;
|
|
150
|
-
if (typeof ast.literal === "number") {
|
|
151
|
-
return Number.isInteger(ast.literal) ? GraphQLInt : GraphQLFloat;
|
|
152
|
-
}
|
|
153
|
-
if (typeof ast.literal === "boolean") return GraphQLBoolean;
|
|
154
|
-
}
|
|
155
|
-
if (ast._tag === "TupleType") {
|
|
156
|
-
const elements = ast.elements;
|
|
157
|
-
if (elements.length > 0) {
|
|
158
|
-
const elementSchema = S2.make(elements[0].type);
|
|
159
|
-
return new GraphQLList(toGraphQLInputType(elementSchema));
|
|
160
|
-
}
|
|
162
|
+
return handleRefinementAST(ast, toGraphQLInputType);
|
|
161
163
|
}
|
|
164
|
+
const literalResult = handleLiteralAST(ast);
|
|
165
|
+
if (literalResult) return literalResult;
|
|
166
|
+
const tupleResult = handleTupleTypeAST(ast, toGraphQLInputType);
|
|
167
|
+
if (tupleResult) return tupleResult;
|
|
162
168
|
if (ast._tag === "TypeLiteral") {
|
|
163
|
-
const fields =
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
const fieldSchema = S2.make(field2.type);
|
|
168
|
-
let fieldType = toGraphQLInputType(fieldSchema);
|
|
169
|
-
const isOptionField = isOptionTransformation(field2.type) || isOptionDeclaration(field2.type);
|
|
170
|
-
if (!field2.isOptional && !isOptionField) {
|
|
171
|
-
fieldType = new GraphQLNonNull(fieldType);
|
|
172
|
-
}
|
|
173
|
-
fields[fieldName] = { type: fieldType };
|
|
174
|
-
}
|
|
169
|
+
const fields = buildFieldsFromPropertySignatures(
|
|
170
|
+
ast.propertySignatures,
|
|
171
|
+
toGraphQLInputType
|
|
172
|
+
);
|
|
175
173
|
const typeName = schema.annotations?.identifier || `Input_${Math.random().toString(36).slice(2, 11)}`;
|
|
176
174
|
return new GraphQLInputObjectType({
|
|
177
175
|
name: typeName,
|
|
@@ -224,18 +222,8 @@ var toGraphQLObjectType = (name, schema, additionalFields) => {
|
|
|
224
222
|
}
|
|
225
223
|
}
|
|
226
224
|
if (ast._tag === "TypeLiteral") {
|
|
227
|
-
const
|
|
228
|
-
|
|
229
|
-
const fieldName = String(field2.name);
|
|
230
|
-
if (fieldName === "_tag") continue;
|
|
231
|
-
const fieldSchema = S2.make(field2.type);
|
|
232
|
-
let fieldType = toGraphQLType(fieldSchema);
|
|
233
|
-
const isOptionField = isOptionTransformation(field2.type) || isOptionDeclaration(field2.type);
|
|
234
|
-
if (!field2.isOptional && !isOptionField) {
|
|
235
|
-
fieldType = new GraphQLNonNull(fieldType);
|
|
236
|
-
}
|
|
237
|
-
fields[fieldName] = { type: fieldType };
|
|
238
|
-
}
|
|
225
|
+
const baseFields = buildFieldsFromPropertySignatures(ast.propertySignatures, toGraphQLType);
|
|
226
|
+
const fields = { ...baseFields };
|
|
239
227
|
if (additionalFields) {
|
|
240
228
|
for (const [fieldName, fieldConfig] of Object.entries(additionalFields)) {
|
|
241
229
|
fields[fieldName] = {
|
|
@@ -257,18 +245,7 @@ var toGraphQLObjectType = (name, schema, additionalFields) => {
|
|
|
257
245
|
var toGraphQLArgs = (schema) => {
|
|
258
246
|
const ast = schema.ast;
|
|
259
247
|
if (ast._tag === "TypeLiteral") {
|
|
260
|
-
const args =
|
|
261
|
-
for (const field2 of ast.propertySignatures) {
|
|
262
|
-
const fieldName = String(field2.name);
|
|
263
|
-
if (fieldName === "_tag") continue;
|
|
264
|
-
const fieldSchema = S2.make(field2.type);
|
|
265
|
-
let fieldType = toGraphQLInputType(fieldSchema);
|
|
266
|
-
const isOptionField = isOptionTransformation(field2.type) || isOptionDeclaration(field2.type);
|
|
267
|
-
if (!field2.isOptional && !isOptionField) {
|
|
268
|
-
fieldType = new GraphQLNonNull(fieldType);
|
|
269
|
-
}
|
|
270
|
-
args[fieldName] = { type: fieldType };
|
|
271
|
-
}
|
|
248
|
+
const args = buildFieldsFromPropertySignatures(ast.propertySignatures, toGraphQLInputType);
|
|
272
249
|
return args;
|
|
273
250
|
}
|
|
274
251
|
throw new Error(`Schema must be an object type to convert to GraphQL arguments`);
|
|
@@ -384,7 +361,7 @@ function toGraphQLTypeWithRegistry(schema, ctx) {
|
|
|
384
361
|
if (enumType2) return enumType2;
|
|
385
362
|
}
|
|
386
363
|
if (ast._tag === "TupleType") {
|
|
387
|
-
return
|
|
364
|
+
return handleTupleTypeAST2(ast, ctx);
|
|
388
365
|
}
|
|
389
366
|
if (ast._tag === "Declaration") {
|
|
390
367
|
if (isOptionDeclaration2(ast)) {
|
|
@@ -440,88 +417,112 @@ function getOptionInnerType2(ast) {
|
|
|
440
417
|
}
|
|
441
418
|
return void 0;
|
|
442
419
|
}
|
|
443
|
-
function
|
|
444
|
-
const
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
if (
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
const result = ctx.typeRegistry.get(typeName);
|
|
454
|
-
if (result) return result;
|
|
455
|
-
}
|
|
456
|
-
for (const [regTypeName, typeReg] of ctx.types) {
|
|
457
|
-
if (typeReg.schema.ast === memberAst) {
|
|
458
|
-
const result = ctx.typeRegistry.get(regTypeName);
|
|
459
|
-
if (result) return result;
|
|
460
|
-
}
|
|
461
|
-
}
|
|
462
|
-
if (memberAst._tag === "Transformation") {
|
|
463
|
-
const innerToAst = memberAst.to;
|
|
464
|
-
const transformedTypeName = ctx.astToTypeName?.get(innerToAst);
|
|
465
|
-
if (transformedTypeName) {
|
|
466
|
-
const result = ctx.typeRegistry.get(transformedTypeName);
|
|
467
|
-
if (result) return result;
|
|
468
|
-
}
|
|
469
|
-
for (const [regTypeName, typeReg] of ctx.types) {
|
|
470
|
-
if (typeReg.schema.ast === innerToAst) {
|
|
471
|
-
const result = ctx.typeRegistry.get(regTypeName);
|
|
472
|
-
if (result) return result;
|
|
473
|
-
}
|
|
474
|
-
}
|
|
475
|
-
}
|
|
476
|
-
if (memberAst._tag === "TypeLiteral") {
|
|
477
|
-
const valueField = memberAst.propertySignatures?.find(
|
|
478
|
-
(p) => String(p.name) === "value"
|
|
479
|
-
);
|
|
480
|
-
if (valueField) {
|
|
481
|
-
const valueType = valueField.type;
|
|
482
|
-
const valueTypeName = ctx.astToTypeName?.get(valueType);
|
|
483
|
-
if (valueTypeName) {
|
|
484
|
-
const result = ctx.typeRegistry.get(valueTypeName);
|
|
485
|
-
if (result) return result;
|
|
486
|
-
}
|
|
487
|
-
for (const [regTypeName, typeReg] of ctx.types) {
|
|
488
|
-
if (typeReg.schema.ast === valueType) {
|
|
489
|
-
const result = ctx.typeRegistry.get(regTypeName);
|
|
490
|
-
if (result) return result;
|
|
491
|
-
}
|
|
492
|
-
let regAst = typeReg.schema.ast;
|
|
493
|
-
while (regAst._tag === "Transformation") {
|
|
494
|
-
regAst = regAst.to;
|
|
495
|
-
if (regAst === valueType) {
|
|
496
|
-
const result = ctx.typeRegistry.get(regTypeName);
|
|
497
|
-
if (result) return result;
|
|
498
|
-
}
|
|
499
|
-
}
|
|
500
|
-
}
|
|
501
|
-
const innerResult = toGraphQLTypeWithRegistry(S2.make(valueType), ctx);
|
|
502
|
-
if (innerResult) return innerResult;
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
}
|
|
420
|
+
function findRegisteredTypeForAST(memberAst, ctx) {
|
|
421
|
+
const typeName = ctx.astToTypeName?.get(memberAst);
|
|
422
|
+
if (typeName) {
|
|
423
|
+
const result = ctx.typeRegistry.get(typeName);
|
|
424
|
+
if (result) return result;
|
|
425
|
+
}
|
|
426
|
+
for (const [regTypeName, typeReg] of ctx.types) {
|
|
427
|
+
if (typeReg.schema.ast === memberAst) {
|
|
428
|
+
const result = ctx.typeRegistry.get(regTypeName);
|
|
429
|
+
if (result) return result;
|
|
506
430
|
}
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
431
|
+
}
|
|
432
|
+
return void 0;
|
|
433
|
+
}
|
|
434
|
+
function findRegisteredTypeForTransformation(memberAst, ctx) {
|
|
435
|
+
if (memberAst._tag !== "Transformation") return void 0;
|
|
436
|
+
const innerToAst = memberAst.to;
|
|
437
|
+
const transformedTypeName = ctx.astToTypeName?.get(innerToAst);
|
|
438
|
+
if (transformedTypeName) {
|
|
439
|
+
const result = ctx.typeRegistry.get(transformedTypeName);
|
|
440
|
+
if (result) return result;
|
|
441
|
+
}
|
|
442
|
+
for (const [regTypeName, typeReg] of ctx.types) {
|
|
443
|
+
if (typeReg.schema.ast === innerToAst) {
|
|
444
|
+
const result = ctx.typeRegistry.get(regTypeName);
|
|
445
|
+
if (result) return result;
|
|
510
446
|
}
|
|
511
447
|
}
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
448
|
+
return void 0;
|
|
449
|
+
}
|
|
450
|
+
function findRegisteredTypeForOptionSome(memberAst, ctx) {
|
|
451
|
+
if (memberAst._tag !== "TypeLiteral") return void 0;
|
|
452
|
+
const valueField = memberAst.propertySignatures?.find(
|
|
453
|
+
(p) => String(p.name) === "value"
|
|
454
|
+
);
|
|
455
|
+
if (!valueField) return void 0;
|
|
456
|
+
const valueType = valueField.type;
|
|
457
|
+
const valueTypeName = ctx.astToTypeName?.get(valueType);
|
|
458
|
+
if (valueTypeName) {
|
|
459
|
+
const result = ctx.typeRegistry.get(valueTypeName);
|
|
460
|
+
if (result) return result;
|
|
461
|
+
}
|
|
462
|
+
for (const [regTypeName, typeReg] of ctx.types) {
|
|
463
|
+
if (typeReg.schema.ast === valueType) {
|
|
464
|
+
const result = ctx.typeRegistry.get(regTypeName);
|
|
465
|
+
if (result) return result;
|
|
466
|
+
}
|
|
467
|
+
let regAst = typeReg.schema.ast;
|
|
468
|
+
while (regAst._tag === "Transformation") {
|
|
469
|
+
regAst = regAst.to;
|
|
470
|
+
if (regAst === valueType) {
|
|
471
|
+
const result = ctx.typeRegistry.get(regTypeName);
|
|
472
|
+
if (result) return result;
|
|
473
|
+
}
|
|
521
474
|
}
|
|
522
475
|
}
|
|
476
|
+
const innerResult = toGraphQLTypeWithRegistry(S2.make(valueType), ctx);
|
|
477
|
+
return innerResult;
|
|
478
|
+
}
|
|
479
|
+
function handleOptionTransformation(ast, fromAst, toAst, ctx) {
|
|
480
|
+
if (fromAst && fromAst._tag === "Union") {
|
|
481
|
+
for (const memberAst of fromAst.types) {
|
|
482
|
+
if (memberAst._tag === "Literal") continue;
|
|
483
|
+
if (memberAst._tag === "UndefinedKeyword") continue;
|
|
484
|
+
const registeredType = findRegisteredTypeForAST(memberAst, ctx) || findRegisteredTypeForTransformation(memberAst, ctx) || findRegisteredTypeForOptionSome(memberAst, ctx);
|
|
485
|
+
if (registeredType) return registeredType;
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
const innerType = getOptionInnerType2(toAst);
|
|
489
|
+
if (innerType) {
|
|
490
|
+
return toGraphQLTypeWithRegistry(S2.make(innerType), ctx);
|
|
491
|
+
}
|
|
492
|
+
return void 0;
|
|
493
|
+
}
|
|
494
|
+
function handleArrayTransformation(toAst, ctx) {
|
|
495
|
+
if (toAst._tag !== "TupleType") return void 0;
|
|
496
|
+
let elementType;
|
|
497
|
+
if (toAst.rest && toAst.rest.length > 0) {
|
|
498
|
+
const elementSchema = S2.make(toAst.rest[0].type);
|
|
499
|
+
elementType = toGraphQLTypeWithRegistry(elementSchema, ctx);
|
|
500
|
+
} else if (toAst.elements.length > 0) {
|
|
501
|
+
const elementSchema = S2.make(toAst.elements[0].type);
|
|
502
|
+
elementType = toGraphQLTypeWithRegistry(elementSchema, ctx);
|
|
503
|
+
} else {
|
|
504
|
+
return void 0;
|
|
505
|
+
}
|
|
506
|
+
return new GraphQLList(elementType);
|
|
507
|
+
}
|
|
508
|
+
function handleTransformationAST(ast, ctx) {
|
|
509
|
+
const toAst = ast.to;
|
|
510
|
+
const fromAst = ast.from;
|
|
511
|
+
if (isOptionDeclaration2(toAst)) {
|
|
512
|
+
const optionResult = handleOptionTransformation(ast, fromAst, toAst, ctx);
|
|
513
|
+
if (optionResult) return optionResult;
|
|
514
|
+
}
|
|
515
|
+
const arrayResult = handleArrayTransformation(toAst, ctx);
|
|
516
|
+
if (arrayResult) return arrayResult;
|
|
523
517
|
return toGraphQLTypeWithRegistry(S2.make(ast.to), ctx);
|
|
524
518
|
}
|
|
519
|
+
function findRegisteredTypeInUnionMembers(types, ctx) {
|
|
520
|
+
for (const memberAst of types) {
|
|
521
|
+
const registeredType = findRegisteredTypeForAST(memberAst, ctx) || findRegisteredTypeForTransformation(memberAst, ctx) || findRegisteredTypeForOptionSome(memberAst, ctx);
|
|
522
|
+
if (registeredType) return registeredType;
|
|
523
|
+
}
|
|
524
|
+
return void 0;
|
|
525
|
+
}
|
|
525
526
|
function handleUnionAST(ast, ctx) {
|
|
526
527
|
const allLiterals = ast.types.every((t) => t._tag === "Literal");
|
|
527
528
|
if (allLiterals) {
|
|
@@ -531,64 +532,8 @@ function handleUnionAST(ast, ctx) {
|
|
|
531
532
|
const unionType2 = findRegisteredUnion(ast.types, ctx);
|
|
532
533
|
if (unionType2) return unionType2;
|
|
533
534
|
}
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
if (typeName) {
|
|
537
|
-
const result = ctx.typeRegistry.get(typeName);
|
|
538
|
-
if (result) return result;
|
|
539
|
-
}
|
|
540
|
-
for (const [regTypeName, typeReg] of ctx.types) {
|
|
541
|
-
if (typeReg.schema.ast === memberAst) {
|
|
542
|
-
const result = ctx.typeRegistry.get(regTypeName);
|
|
543
|
-
if (result) return result;
|
|
544
|
-
}
|
|
545
|
-
}
|
|
546
|
-
if (memberAst._tag === "Transformation") {
|
|
547
|
-
const toAst = memberAst.to;
|
|
548
|
-
const transformedTypeName = ctx.astToTypeName?.get(toAst);
|
|
549
|
-
if (transformedTypeName) {
|
|
550
|
-
const result = ctx.typeRegistry.get(transformedTypeName);
|
|
551
|
-
if (result) return result;
|
|
552
|
-
}
|
|
553
|
-
for (const [regTypeName, typeReg] of ctx.types) {
|
|
554
|
-
if (typeReg.schema.ast === toAst) {
|
|
555
|
-
const result = ctx.typeRegistry.get(regTypeName);
|
|
556
|
-
if (result) return result;
|
|
557
|
-
}
|
|
558
|
-
}
|
|
559
|
-
}
|
|
560
|
-
if (memberAst._tag === "TypeLiteral") {
|
|
561
|
-
const valueField = memberAst.propertySignatures?.find(
|
|
562
|
-
(p) => String(p.name) === "value"
|
|
563
|
-
);
|
|
564
|
-
if (valueField) {
|
|
565
|
-
const valueType = valueField.type;
|
|
566
|
-
const valueTypeName = ctx.astToTypeName?.get(valueType);
|
|
567
|
-
if (valueTypeName) {
|
|
568
|
-
const result = ctx.typeRegistry.get(valueTypeName);
|
|
569
|
-
if (result) return result;
|
|
570
|
-
}
|
|
571
|
-
for (const [regTypeName, typeReg] of ctx.types) {
|
|
572
|
-
if (typeReg.schema.ast === valueType) {
|
|
573
|
-
const result = ctx.typeRegistry.get(regTypeName);
|
|
574
|
-
if (result) return result;
|
|
575
|
-
}
|
|
576
|
-
let regAst = typeReg.schema.ast;
|
|
577
|
-
while (regAst._tag === "Transformation") {
|
|
578
|
-
regAst = regAst.to;
|
|
579
|
-
if (regAst === valueType) {
|
|
580
|
-
const result = ctx.typeRegistry.get(regTypeName);
|
|
581
|
-
if (result) return result;
|
|
582
|
-
}
|
|
583
|
-
}
|
|
584
|
-
}
|
|
585
|
-
const innerResult = toGraphQLTypeWithRegistry(S2.make(valueType), ctx);
|
|
586
|
-
if (innerResult) {
|
|
587
|
-
return innerResult;
|
|
588
|
-
}
|
|
589
|
-
}
|
|
590
|
-
}
|
|
591
|
-
}
|
|
535
|
+
const registeredType = findRegisteredTypeInUnionMembers(ast.types, ctx);
|
|
536
|
+
if (registeredType) return registeredType;
|
|
592
537
|
if (ast.types.length > 0) {
|
|
593
538
|
return toGraphQLTypeWithRegistry(S2.make(ast.types[0]), ctx);
|
|
594
539
|
}
|
|
@@ -633,7 +578,7 @@ function findEnumForLiteral(ast, ctx) {
|
|
|
633
578
|
}
|
|
634
579
|
return void 0;
|
|
635
580
|
}
|
|
636
|
-
function
|
|
581
|
+
function handleTupleTypeAST2(ast, ctx) {
|
|
637
582
|
if (ast.rest && ast.rest.length > 0) {
|
|
638
583
|
const elementSchema = S2.make(ast.rest[0].type);
|
|
639
584
|
const elementType = toGraphQLTypeWithRegistry(elementSchema, ctx);
|
|
@@ -733,170 +678,40 @@ function buildInputTypeLookupCache(inputs, enums) {
|
|
|
733
678
|
}
|
|
734
679
|
return cache;
|
|
735
680
|
}
|
|
736
|
-
function
|
|
737
|
-
const ast = schema.ast;
|
|
681
|
+
function findRegisteredInputType(schema, ast, inputs, inputRegistry, cache) {
|
|
738
682
|
if (cache?.schemaToInputName || cache?.astToInputName) {
|
|
739
683
|
const inputName = cache.schemaToInputName?.get(schema) ?? cache.astToInputName?.get(ast);
|
|
740
684
|
if (inputName) {
|
|
741
|
-
|
|
742
|
-
if (result) return result;
|
|
685
|
+
return inputRegistry.get(inputName);
|
|
743
686
|
}
|
|
744
687
|
} else {
|
|
745
688
|
for (const [inputName, inputReg] of inputs) {
|
|
746
689
|
if (inputReg.schema.ast === ast || inputReg.schema === schema) {
|
|
747
|
-
|
|
748
|
-
if (result) return result;
|
|
690
|
+
return inputRegistry.get(inputName);
|
|
749
691
|
}
|
|
750
692
|
}
|
|
751
693
|
}
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
inputs,
|
|
768
|
-
enums,
|
|
769
|
-
cache
|
|
770
|
-
);
|
|
771
|
-
}
|
|
772
|
-
}
|
|
773
|
-
for (const [, inputReg] of inputs) {
|
|
774
|
-
if (inputReg.schema.ast === memberAst) {
|
|
775
|
-
return toGraphQLInputTypeWithRegistry(
|
|
776
|
-
inputReg.schema,
|
|
777
|
-
enumRegistry,
|
|
778
|
-
inputRegistry,
|
|
779
|
-
inputs,
|
|
780
|
-
enums,
|
|
781
|
-
cache
|
|
782
|
-
);
|
|
783
|
-
}
|
|
784
|
-
}
|
|
785
|
-
if (memberAst._tag === "Transformation") {
|
|
786
|
-
const innerToAst = memberAst.to;
|
|
787
|
-
const transformedInputName = cache?.astToInputName?.get(innerToAst);
|
|
788
|
-
if (transformedInputName) {
|
|
789
|
-
const inputReg = inputs.get(transformedInputName);
|
|
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 === innerToAst) {
|
|
803
|
-
return toGraphQLInputTypeWithRegistry(
|
|
804
|
-
inputReg.schema,
|
|
805
|
-
enumRegistry,
|
|
806
|
-
inputRegistry,
|
|
807
|
-
inputs,
|
|
808
|
-
enums,
|
|
809
|
-
cache
|
|
810
|
-
);
|
|
811
|
-
}
|
|
812
|
-
}
|
|
813
|
-
}
|
|
814
|
-
if (memberAst._tag === "TypeLiteral") {
|
|
815
|
-
const valueField = memberAst.propertySignatures?.find(
|
|
816
|
-
(p) => String(p.name) === "value"
|
|
817
|
-
);
|
|
818
|
-
if (valueField) {
|
|
819
|
-
const valueType = valueField.type;
|
|
820
|
-
const valueInputName = cache?.astToInputName?.get(valueType);
|
|
821
|
-
if (valueInputName) {
|
|
822
|
-
const inputReg = inputs.get(valueInputName);
|
|
823
|
-
if (inputReg) {
|
|
824
|
-
return toGraphQLInputTypeWithRegistry(
|
|
825
|
-
inputReg.schema,
|
|
826
|
-
enumRegistry,
|
|
827
|
-
inputRegistry,
|
|
828
|
-
inputs,
|
|
829
|
-
enums,
|
|
830
|
-
cache
|
|
831
|
-
);
|
|
832
|
-
}
|
|
833
|
-
}
|
|
834
|
-
for (const [, inputReg] of inputs) {
|
|
835
|
-
if (inputReg.schema.ast === valueType) {
|
|
836
|
-
return toGraphQLInputTypeWithRegistry(
|
|
837
|
-
inputReg.schema,
|
|
838
|
-
enumRegistry,
|
|
839
|
-
inputRegistry,
|
|
840
|
-
inputs,
|
|
841
|
-
enums,
|
|
842
|
-
cache
|
|
843
|
-
);
|
|
844
|
-
}
|
|
845
|
-
let regAst = inputReg.schema.ast;
|
|
846
|
-
while (regAst._tag === "Transformation") {
|
|
847
|
-
regAst = regAst.to;
|
|
848
|
-
if (regAst === valueType) {
|
|
849
|
-
return toGraphQLInputTypeWithRegistry(
|
|
850
|
-
inputReg.schema,
|
|
851
|
-
enumRegistry,
|
|
852
|
-
inputRegistry,
|
|
853
|
-
inputs,
|
|
854
|
-
enums,
|
|
855
|
-
cache
|
|
856
|
-
);
|
|
857
|
-
}
|
|
858
|
-
}
|
|
859
|
-
if (regAst._tag === "Declaration" && regAst.typeParameters?.[0] === valueType) {
|
|
860
|
-
return toGraphQLInputTypeWithRegistry(
|
|
861
|
-
inputReg.schema,
|
|
862
|
-
enumRegistry,
|
|
863
|
-
inputRegistry,
|
|
864
|
-
inputs,
|
|
865
|
-
enums,
|
|
866
|
-
cache
|
|
867
|
-
);
|
|
868
|
-
}
|
|
869
|
-
}
|
|
870
|
-
const innerResult = toGraphQLInputTypeWithRegistry(
|
|
871
|
-
S2.make(valueType),
|
|
872
|
-
enumRegistry,
|
|
873
|
-
inputRegistry,
|
|
874
|
-
inputs,
|
|
875
|
-
enums,
|
|
876
|
-
cache
|
|
877
|
-
);
|
|
878
|
-
if (innerResult) {
|
|
879
|
-
return innerResult;
|
|
880
|
-
}
|
|
881
|
-
}
|
|
882
|
-
}
|
|
883
|
-
}
|
|
694
|
+
return void 0;
|
|
695
|
+
}
|
|
696
|
+
function findRegisteredInputForAST(memberAst, inputs, inputRegistry, enumRegistry, enums, cache) {
|
|
697
|
+
const inputName = cache?.astToInputName?.get(memberAst);
|
|
698
|
+
if (inputName) {
|
|
699
|
+
const inputReg = inputs.get(inputName);
|
|
700
|
+
if (inputReg) {
|
|
701
|
+
return toGraphQLInputTypeWithRegistry(
|
|
702
|
+
inputReg.schema,
|
|
703
|
+
enumRegistry,
|
|
704
|
+
inputRegistry,
|
|
705
|
+
inputs,
|
|
706
|
+
enums,
|
|
707
|
+
cache
|
|
708
|
+
);
|
|
884
709
|
}
|
|
885
|
-
return toGraphQLInputTypeWithRegistry(
|
|
886
|
-
S2.make(toAst),
|
|
887
|
-
enumRegistry,
|
|
888
|
-
inputRegistry,
|
|
889
|
-
inputs,
|
|
890
|
-
enums,
|
|
891
|
-
cache
|
|
892
|
-
);
|
|
893
710
|
}
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
const nonUndefinedTypes = unionAst.types.filter((t) => t._tag !== "UndefinedKeyword");
|
|
897
|
-
if (nonUndefinedTypes.length === 1 && nonUndefinedTypes[0]._tag === "Union") {
|
|
711
|
+
for (const [, inputReg] of inputs) {
|
|
712
|
+
if (inputReg.schema.ast === memberAst) {
|
|
898
713
|
return toGraphQLInputTypeWithRegistry(
|
|
899
|
-
|
|
714
|
+
inputReg.schema,
|
|
900
715
|
enumRegistry,
|
|
901
716
|
inputRegistry,
|
|
902
717
|
inputs,
|
|
@@ -904,9 +719,18 @@ function toGraphQLInputTypeWithRegistry(schema, enumRegistry, inputRegistry, inp
|
|
|
904
719
|
cache
|
|
905
720
|
);
|
|
906
721
|
}
|
|
907
|
-
|
|
722
|
+
}
|
|
723
|
+
return void 0;
|
|
724
|
+
}
|
|
725
|
+
function findRegisteredInputForTransformation(memberAst, inputs, inputRegistry, enumRegistry, enums, cache) {
|
|
726
|
+
if (memberAst._tag !== "Transformation") return void 0;
|
|
727
|
+
const innerToAst = memberAst.to;
|
|
728
|
+
const transformedInputName = cache?.astToInputName?.get(innerToAst);
|
|
729
|
+
if (transformedInputName) {
|
|
730
|
+
const inputReg = inputs.get(transformedInputName);
|
|
731
|
+
if (inputReg) {
|
|
908
732
|
return toGraphQLInputTypeWithRegistry(
|
|
909
|
-
|
|
733
|
+
inputReg.schema,
|
|
910
734
|
enumRegistry,
|
|
911
735
|
inputRegistry,
|
|
912
736
|
inputs,
|
|
@@ -914,171 +738,210 @@ function toGraphQLInputTypeWithRegistry(schema, enumRegistry, inputRegistry, inp
|
|
|
914
738
|
cache
|
|
915
739
|
);
|
|
916
740
|
}
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
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
|
-
(p) => String(p.name) === "value"
|
|
741
|
+
}
|
|
742
|
+
for (const [, inputReg] of inputs) {
|
|
743
|
+
if (inputReg.schema.ast === innerToAst) {
|
|
744
|
+
return toGraphQLInputTypeWithRegistry(
|
|
745
|
+
inputReg.schema,
|
|
746
|
+
enumRegistry,
|
|
747
|
+
inputRegistry,
|
|
748
|
+
inputs,
|
|
749
|
+
enums,
|
|
750
|
+
cache
|
|
751
|
+
);
|
|
752
|
+
}
|
|
753
|
+
}
|
|
754
|
+
return void 0;
|
|
755
|
+
}
|
|
756
|
+
function findRegisteredInputForOptionSome(memberAst, inputs, inputRegistry, enumRegistry, enums, cache) {
|
|
757
|
+
if (memberAst._tag !== "TypeLiteral") return void 0;
|
|
758
|
+
const valueField = memberAst.propertySignatures?.find(
|
|
759
|
+
(p) => String(p.name) === "value"
|
|
760
|
+
);
|
|
761
|
+
if (!valueField) return void 0;
|
|
762
|
+
const valueType = valueField.type;
|
|
763
|
+
const valueInputName = cache?.astToInputName?.get(valueType);
|
|
764
|
+
if (valueInputName) {
|
|
765
|
+
const inputReg = inputs.get(valueInputName);
|
|
766
|
+
if (inputReg) {
|
|
767
|
+
return toGraphQLInputTypeWithRegistry(
|
|
768
|
+
inputReg.schema,
|
|
769
|
+
enumRegistry,
|
|
770
|
+
inputRegistry,
|
|
771
|
+
inputs,
|
|
772
|
+
enums,
|
|
773
|
+
cache
|
|
774
|
+
);
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
for (const [, inputReg] of inputs) {
|
|
778
|
+
if (inputReg.schema.ast === valueType) {
|
|
779
|
+
return toGraphQLInputTypeWithRegistry(
|
|
780
|
+
inputReg.schema,
|
|
781
|
+
enumRegistry,
|
|
782
|
+
inputRegistry,
|
|
783
|
+
inputs,
|
|
784
|
+
enums,
|
|
785
|
+
cache
|
|
786
|
+
);
|
|
787
|
+
}
|
|
788
|
+
let regAst = inputReg.schema.ast;
|
|
789
|
+
while (regAst._tag === "Transformation") {
|
|
790
|
+
regAst = regAst.to;
|
|
791
|
+
if (regAst === valueType) {
|
|
792
|
+
return toGraphQLInputTypeWithRegistry(
|
|
793
|
+
inputReg.schema,
|
|
794
|
+
enumRegistry,
|
|
795
|
+
inputRegistry,
|
|
796
|
+
inputs,
|
|
797
|
+
enums,
|
|
798
|
+
cache
|
|
976
799
|
);
|
|
977
|
-
if (valueField) {
|
|
978
|
-
const valueType = valueField.type;
|
|
979
|
-
const valueInputName = cache?.astToInputName?.get(valueType);
|
|
980
|
-
if (valueInputName) {
|
|
981
|
-
const inputReg = inputs.get(valueInputName);
|
|
982
|
-
if (inputReg) {
|
|
983
|
-
return toGraphQLInputTypeWithRegistry(
|
|
984
|
-
inputReg.schema,
|
|
985
|
-
enumRegistry,
|
|
986
|
-
inputRegistry,
|
|
987
|
-
inputs,
|
|
988
|
-
enums,
|
|
989
|
-
cache
|
|
990
|
-
);
|
|
991
|
-
}
|
|
992
|
-
}
|
|
993
|
-
for (const [, inputReg] of inputs) {
|
|
994
|
-
if (inputReg.schema.ast === valueType) {
|
|
995
|
-
return toGraphQLInputTypeWithRegistry(
|
|
996
|
-
inputReg.schema,
|
|
997
|
-
enumRegistry,
|
|
998
|
-
inputRegistry,
|
|
999
|
-
inputs,
|
|
1000
|
-
enums,
|
|
1001
|
-
cache
|
|
1002
|
-
);
|
|
1003
|
-
}
|
|
1004
|
-
let regAst = inputReg.schema.ast;
|
|
1005
|
-
while (regAst._tag === "Transformation") {
|
|
1006
|
-
regAst = regAst.to;
|
|
1007
|
-
if (regAst === valueType) {
|
|
1008
|
-
return toGraphQLInputTypeWithRegistry(
|
|
1009
|
-
inputReg.schema,
|
|
1010
|
-
enumRegistry,
|
|
1011
|
-
inputRegistry,
|
|
1012
|
-
inputs,
|
|
1013
|
-
enums,
|
|
1014
|
-
cache
|
|
1015
|
-
);
|
|
1016
|
-
}
|
|
1017
|
-
}
|
|
1018
|
-
if (regAst._tag === "Declaration" && regAst.typeParameters?.[0] === valueType) {
|
|
1019
|
-
return toGraphQLInputTypeWithRegistry(
|
|
1020
|
-
inputReg.schema,
|
|
1021
|
-
enumRegistry,
|
|
1022
|
-
inputRegistry,
|
|
1023
|
-
inputs,
|
|
1024
|
-
enums,
|
|
1025
|
-
cache
|
|
1026
|
-
);
|
|
1027
|
-
}
|
|
1028
|
-
}
|
|
1029
|
-
const innerResult = toGraphQLInputTypeWithRegistry(
|
|
1030
|
-
S2.make(valueType),
|
|
1031
|
-
enumRegistry,
|
|
1032
|
-
inputRegistry,
|
|
1033
|
-
inputs,
|
|
1034
|
-
enums,
|
|
1035
|
-
cache
|
|
1036
|
-
);
|
|
1037
|
-
if (innerResult) {
|
|
1038
|
-
return innerResult;
|
|
1039
|
-
}
|
|
1040
|
-
}
|
|
1041
800
|
}
|
|
1042
801
|
}
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
}
|
|
802
|
+
if (regAst._tag === "Declaration" && regAst.typeParameters?.[0] === valueType) {
|
|
803
|
+
return toGraphQLInputTypeWithRegistry(
|
|
804
|
+
inputReg.schema,
|
|
805
|
+
enumRegistry,
|
|
806
|
+
inputRegistry,
|
|
807
|
+
inputs,
|
|
808
|
+
enums,
|
|
809
|
+
cache
|
|
810
|
+
);
|
|
1053
811
|
}
|
|
1054
812
|
}
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
813
|
+
const innerResult = toGraphQLInputTypeWithRegistry(
|
|
814
|
+
S2.make(valueType),
|
|
815
|
+
enumRegistry,
|
|
816
|
+
inputRegistry,
|
|
817
|
+
inputs,
|
|
818
|
+
enums,
|
|
819
|
+
cache
|
|
820
|
+
);
|
|
821
|
+
return innerResult || void 0;
|
|
822
|
+
}
|
|
823
|
+
function handleOptionTransformationForInput(fromAst, toAst, inputs, inputRegistry, enumRegistry, enums, cache) {
|
|
824
|
+
if (!fromAst || fromAst._tag !== "Union") return void 0;
|
|
825
|
+
for (const memberAst of fromAst.types) {
|
|
826
|
+
if (memberAst._tag === "Literal") continue;
|
|
827
|
+
if (memberAst._tag === "UndefinedKeyword") continue;
|
|
828
|
+
const registeredInput = findRegisteredInputForAST(memberAst, inputs, inputRegistry, enumRegistry, enums, cache) || findRegisteredInputForTransformation(memberAst, inputs, inputRegistry, enumRegistry, enums, cache) || findRegisteredInputForOptionSome(memberAst, inputs, inputRegistry, enumRegistry, enums, cache);
|
|
829
|
+
if (registeredInput) return registeredInput;
|
|
830
|
+
}
|
|
831
|
+
return void 0;
|
|
832
|
+
}
|
|
833
|
+
function handleTransformationForInput(ast, inputs, inputRegistry, enumRegistry, enums, cache) {
|
|
834
|
+
const toAst = ast.to;
|
|
835
|
+
const fromAst = ast.from;
|
|
836
|
+
if (isOptionDeclaration2(toAst)) {
|
|
837
|
+
const optionResult = handleOptionTransformationForInput(
|
|
838
|
+
fromAst,
|
|
839
|
+
toAst,
|
|
840
|
+
inputs,
|
|
841
|
+
inputRegistry,
|
|
842
|
+
enumRegistry,
|
|
843
|
+
enums,
|
|
844
|
+
cache
|
|
845
|
+
);
|
|
846
|
+
if (optionResult) return optionResult;
|
|
847
|
+
}
|
|
848
|
+
return toGraphQLInputTypeWithRegistry(
|
|
849
|
+
S2.make(toAst),
|
|
850
|
+
enumRegistry,
|
|
851
|
+
inputRegistry,
|
|
852
|
+
inputs,
|
|
853
|
+
enums,
|
|
854
|
+
cache
|
|
855
|
+
);
|
|
856
|
+
}
|
|
857
|
+
function findRegisteredInputInUnionMembers(types, inputs, inputRegistry, enumRegistry, enums, cache) {
|
|
858
|
+
for (const memberAst of types) {
|
|
859
|
+
const registeredInput = findRegisteredInputForAST(memberAst, inputs, inputRegistry, enumRegistry, enums, cache) || findRegisteredInputForTransformation(memberAst, inputs, inputRegistry, enumRegistry, enums, cache) || findRegisteredInputForOptionSome(memberAst, inputs, inputRegistry, enumRegistry, enums, cache);
|
|
860
|
+
if (registeredInput) return registeredInput;
|
|
861
|
+
}
|
|
862
|
+
return void 0;
|
|
863
|
+
}
|
|
864
|
+
function handleUnionForInput(ast, inputs, inputRegistry, enumRegistry, enums, cache) {
|
|
865
|
+
const unionAst = ast;
|
|
866
|
+
const nonUndefinedTypes = unionAst.types.filter((t) => t._tag !== "UndefinedKeyword");
|
|
867
|
+
if (nonUndefinedTypes.length === 1) {
|
|
868
|
+
if (nonUndefinedTypes[0]._tag === "Union" || nonUndefinedTypes[0]._tag === "TypeLiteral") {
|
|
869
|
+
return toGraphQLInputTypeWithRegistry(
|
|
870
|
+
S2.make(nonUndefinedTypes[0]),
|
|
871
|
+
enumRegistry,
|
|
872
|
+
inputRegistry,
|
|
873
|
+
inputs,
|
|
874
|
+
enums,
|
|
875
|
+
cache
|
|
876
|
+
);
|
|
877
|
+
}
|
|
878
|
+
}
|
|
879
|
+
const registeredInput = findRegisteredInputInUnionMembers(
|
|
880
|
+
unionAst.types,
|
|
881
|
+
inputs,
|
|
882
|
+
inputRegistry,
|
|
883
|
+
enumRegistry,
|
|
884
|
+
enums,
|
|
885
|
+
cache
|
|
886
|
+
);
|
|
887
|
+
if (registeredInput) return registeredInput;
|
|
888
|
+
const allLiterals = unionAst.types.every((t) => t._tag === "Literal");
|
|
889
|
+
if (allLiterals) {
|
|
890
|
+
const literalValues = unionAst.types.map((t) => String(t.literal)).sort();
|
|
891
|
+
for (const [enumName] of enums) {
|
|
892
|
+
const enumValues = cache?.enumSortedValues?.get(enumName) ?? [...enums.get(enumName).values].sort();
|
|
893
|
+
if (literalValues.length === enumValues.length && literalValues.every((v, i) => v === enumValues[i])) {
|
|
1060
894
|
const result = enumRegistry.get(enumName);
|
|
1061
895
|
if (result) return result;
|
|
1062
896
|
}
|
|
1063
|
-
}
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
897
|
+
}
|
|
898
|
+
}
|
|
899
|
+
return void 0;
|
|
900
|
+
}
|
|
901
|
+
function handleLiteralForInput(ast, enumRegistry, enums, cache) {
|
|
902
|
+
const literalValue = String(ast.literal);
|
|
903
|
+
if (cache?.literalToEnumName) {
|
|
904
|
+
const enumName = cache.literalToEnumName.get(literalValue);
|
|
905
|
+
if (enumName) {
|
|
906
|
+
return enumRegistry.get(enumName);
|
|
907
|
+
}
|
|
908
|
+
} else {
|
|
909
|
+
for (const [enumName, enumReg] of enums) {
|
|
910
|
+
if (enumReg.values.includes(literalValue)) {
|
|
911
|
+
return enumRegistry.get(enumName);
|
|
1069
912
|
}
|
|
1070
913
|
}
|
|
1071
914
|
}
|
|
915
|
+
return void 0;
|
|
916
|
+
}
|
|
917
|
+
function handleSuspendForInput(ast, inputs, inputRegistry, enumRegistry, enums, cache) {
|
|
918
|
+
const innerAst = ast.f();
|
|
919
|
+
return toGraphQLInputTypeWithRegistry(
|
|
920
|
+
S2.make(innerAst),
|
|
921
|
+
enumRegistry,
|
|
922
|
+
inputRegistry,
|
|
923
|
+
inputs,
|
|
924
|
+
enums,
|
|
925
|
+
cache
|
|
926
|
+
);
|
|
927
|
+
}
|
|
928
|
+
function toGraphQLInputTypeWithRegistry(schema, enumRegistry, inputRegistry, inputs, enums, cache) {
|
|
929
|
+
const ast = schema.ast;
|
|
930
|
+
const registeredInput = findRegisteredInputType(schema, ast, inputs, inputRegistry, cache);
|
|
931
|
+
if (registeredInput) return registeredInput;
|
|
932
|
+
if (ast._tag === "Transformation") {
|
|
933
|
+
return handleTransformationForInput(ast, inputs, inputRegistry, enumRegistry, enums, cache);
|
|
934
|
+
}
|
|
935
|
+
if (ast._tag === "Union") {
|
|
936
|
+
const unionResult = handleUnionForInput(ast, inputs, inputRegistry, enumRegistry, enums, cache);
|
|
937
|
+
if (unionResult) return unionResult;
|
|
938
|
+
}
|
|
939
|
+
if (ast._tag === "Literal") {
|
|
940
|
+
const literalResult = handleLiteralForInput(ast, enumRegistry, enums, cache);
|
|
941
|
+
if (literalResult) return literalResult;
|
|
942
|
+
}
|
|
1072
943
|
if (ast._tag === "Suspend") {
|
|
1073
|
-
|
|
1074
|
-
return toGraphQLInputTypeWithRegistry(
|
|
1075
|
-
S2.make(innerAst),
|
|
1076
|
-
enumRegistry,
|
|
1077
|
-
inputRegistry,
|
|
1078
|
-
inputs,
|
|
1079
|
-
enums,
|
|
1080
|
-
cache
|
|
1081
|
-
);
|
|
944
|
+
return handleSuspendForInput(ast, inputs, inputRegistry, enumRegistry, enums, cache);
|
|
1082
945
|
}
|
|
1083
946
|
return toGraphQLInputType(schema);
|
|
1084
947
|
}
|