@effect-gql/core 1.4.8 → 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 +391 -519
- package/builder/index.cjs.map +1 -1
- package/builder/index.js +392 -520
- package/builder/index.js.map +1 -1
- package/index.cjs +393 -531
- package/index.cjs.map +1 -1
- package/index.js +394 -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, isInput) {
|
|
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,19 @@ 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
|
-
if (fieldName === "_tag") continue;
|
|
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);
|
|
175
172
|
const typeName = schema.annotations?.identifier || `Input_${Math.random().toString(36).slice(2, 11)}`;
|
|
176
173
|
return new GraphQLInputObjectType({
|
|
177
174
|
name: typeName,
|
|
@@ -224,18 +221,8 @@ var toGraphQLObjectType = (name, schema, additionalFields) => {
|
|
|
224
221
|
}
|
|
225
222
|
}
|
|
226
223
|
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
|
-
}
|
|
224
|
+
const baseFields = buildFieldsFromPropertySignatures(ast.propertySignatures, toGraphQLType);
|
|
225
|
+
const fields = { ...baseFields };
|
|
239
226
|
if (additionalFields) {
|
|
240
227
|
for (const [fieldName, fieldConfig] of Object.entries(additionalFields)) {
|
|
241
228
|
fields[fieldName] = {
|
|
@@ -257,18 +244,7 @@ var toGraphQLObjectType = (name, schema, additionalFields) => {
|
|
|
257
244
|
var toGraphQLArgs = (schema) => {
|
|
258
245
|
const ast = schema.ast;
|
|
259
246
|
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
|
-
}
|
|
247
|
+
const args = buildFieldsFromPropertySignatures(ast.propertySignatures, toGraphQLInputType);
|
|
272
248
|
return args;
|
|
273
249
|
}
|
|
274
250
|
throw new Error(`Schema must be an object type to convert to GraphQL arguments`);
|
|
@@ -384,7 +360,7 @@ function toGraphQLTypeWithRegistry(schema, ctx) {
|
|
|
384
360
|
if (enumType2) return enumType2;
|
|
385
361
|
}
|
|
386
362
|
if (ast._tag === "TupleType") {
|
|
387
|
-
return
|
|
363
|
+
return handleTupleTypeAST2(ast, ctx);
|
|
388
364
|
}
|
|
389
365
|
if (ast._tag === "Declaration") {
|
|
390
366
|
if (isOptionDeclaration2(ast)) {
|
|
@@ -440,88 +416,112 @@ function getOptionInnerType2(ast) {
|
|
|
440
416
|
}
|
|
441
417
|
return void 0;
|
|
442
418
|
}
|
|
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
|
-
}
|
|
419
|
+
function findRegisteredTypeForAST(memberAst, ctx) {
|
|
420
|
+
const typeName = ctx.astToTypeName?.get(memberAst);
|
|
421
|
+
if (typeName) {
|
|
422
|
+
const result = ctx.typeRegistry.get(typeName);
|
|
423
|
+
if (result) return result;
|
|
424
|
+
}
|
|
425
|
+
for (const [regTypeName, typeReg] of ctx.types) {
|
|
426
|
+
if (typeReg.schema.ast === memberAst) {
|
|
427
|
+
const result = ctx.typeRegistry.get(regTypeName);
|
|
428
|
+
if (result) return result;
|
|
506
429
|
}
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
430
|
+
}
|
|
431
|
+
return void 0;
|
|
432
|
+
}
|
|
433
|
+
function findRegisteredTypeForTransformation(memberAst, ctx) {
|
|
434
|
+
if (memberAst._tag !== "Transformation") return void 0;
|
|
435
|
+
const innerToAst = memberAst.to;
|
|
436
|
+
const transformedTypeName = ctx.astToTypeName?.get(innerToAst);
|
|
437
|
+
if (transformedTypeName) {
|
|
438
|
+
const result = ctx.typeRegistry.get(transformedTypeName);
|
|
439
|
+
if (result) return result;
|
|
440
|
+
}
|
|
441
|
+
for (const [regTypeName, typeReg] of ctx.types) {
|
|
442
|
+
if (typeReg.schema.ast === innerToAst) {
|
|
443
|
+
const result = ctx.typeRegistry.get(regTypeName);
|
|
444
|
+
if (result) return result;
|
|
510
445
|
}
|
|
511
446
|
}
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
447
|
+
return void 0;
|
|
448
|
+
}
|
|
449
|
+
function findRegisteredTypeForOptionSome(memberAst, ctx) {
|
|
450
|
+
if (memberAst._tag !== "TypeLiteral") return void 0;
|
|
451
|
+
const valueField = memberAst.propertySignatures?.find(
|
|
452
|
+
(p) => String(p.name) === "value"
|
|
453
|
+
);
|
|
454
|
+
if (!valueField) return void 0;
|
|
455
|
+
const valueType = valueField.type;
|
|
456
|
+
const valueTypeName = ctx.astToTypeName?.get(valueType);
|
|
457
|
+
if (valueTypeName) {
|
|
458
|
+
const result = ctx.typeRegistry.get(valueTypeName);
|
|
459
|
+
if (result) return result;
|
|
460
|
+
}
|
|
461
|
+
for (const [regTypeName, typeReg] of ctx.types) {
|
|
462
|
+
if (typeReg.schema.ast === valueType) {
|
|
463
|
+
const result = ctx.typeRegistry.get(regTypeName);
|
|
464
|
+
if (result) return result;
|
|
465
|
+
}
|
|
466
|
+
let regAst = typeReg.schema.ast;
|
|
467
|
+
while (regAst._tag === "Transformation") {
|
|
468
|
+
regAst = regAst.to;
|
|
469
|
+
if (regAst === valueType) {
|
|
470
|
+
const result = ctx.typeRegistry.get(regTypeName);
|
|
471
|
+
if (result) return result;
|
|
472
|
+
}
|
|
521
473
|
}
|
|
522
474
|
}
|
|
475
|
+
const innerResult = toGraphQLTypeWithRegistry(S2.make(valueType), ctx);
|
|
476
|
+
return innerResult;
|
|
477
|
+
}
|
|
478
|
+
function handleOptionTransformation(ast, fromAst, toAst, ctx) {
|
|
479
|
+
if (fromAst && fromAst._tag === "Union") {
|
|
480
|
+
for (const memberAst of fromAst.types) {
|
|
481
|
+
if (memberAst._tag === "Literal") continue;
|
|
482
|
+
if (memberAst._tag === "UndefinedKeyword") continue;
|
|
483
|
+
const registeredType = findRegisteredTypeForAST(memberAst, ctx) || findRegisteredTypeForTransformation(memberAst, ctx) || findRegisteredTypeForOptionSome(memberAst, ctx);
|
|
484
|
+
if (registeredType) return registeredType;
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
const innerType = getOptionInnerType2(toAst);
|
|
488
|
+
if (innerType) {
|
|
489
|
+
return toGraphQLTypeWithRegistry(S2.make(innerType), ctx);
|
|
490
|
+
}
|
|
491
|
+
return void 0;
|
|
492
|
+
}
|
|
493
|
+
function handleArrayTransformation(toAst, ctx) {
|
|
494
|
+
if (toAst._tag !== "TupleType") return void 0;
|
|
495
|
+
let elementType;
|
|
496
|
+
if (toAst.rest && toAst.rest.length > 0) {
|
|
497
|
+
const elementSchema = S2.make(toAst.rest[0].type);
|
|
498
|
+
elementType = toGraphQLTypeWithRegistry(elementSchema, ctx);
|
|
499
|
+
} else if (toAst.elements.length > 0) {
|
|
500
|
+
const elementSchema = S2.make(toAst.elements[0].type);
|
|
501
|
+
elementType = toGraphQLTypeWithRegistry(elementSchema, ctx);
|
|
502
|
+
} else {
|
|
503
|
+
return void 0;
|
|
504
|
+
}
|
|
505
|
+
return new GraphQLList(elementType);
|
|
506
|
+
}
|
|
507
|
+
function handleTransformationAST(ast, ctx) {
|
|
508
|
+
const toAst = ast.to;
|
|
509
|
+
const fromAst = ast.from;
|
|
510
|
+
if (isOptionDeclaration2(toAst)) {
|
|
511
|
+
const optionResult = handleOptionTransformation(ast, fromAst, toAst, ctx);
|
|
512
|
+
if (optionResult) return optionResult;
|
|
513
|
+
}
|
|
514
|
+
const arrayResult = handleArrayTransformation(toAst, ctx);
|
|
515
|
+
if (arrayResult) return arrayResult;
|
|
523
516
|
return toGraphQLTypeWithRegistry(S2.make(ast.to), ctx);
|
|
524
517
|
}
|
|
518
|
+
function findRegisteredTypeInUnionMembers(types, ctx) {
|
|
519
|
+
for (const memberAst of types) {
|
|
520
|
+
const registeredType = findRegisteredTypeForAST(memberAst, ctx) || findRegisteredTypeForTransformation(memberAst, ctx) || findRegisteredTypeForOptionSome(memberAst, ctx);
|
|
521
|
+
if (registeredType) return registeredType;
|
|
522
|
+
}
|
|
523
|
+
return void 0;
|
|
524
|
+
}
|
|
525
525
|
function handleUnionAST(ast, ctx) {
|
|
526
526
|
const allLiterals = ast.types.every((t) => t._tag === "Literal");
|
|
527
527
|
if (allLiterals) {
|
|
@@ -531,64 +531,8 @@ function handleUnionAST(ast, ctx) {
|
|
|
531
531
|
const unionType2 = findRegisteredUnion(ast.types, ctx);
|
|
532
532
|
if (unionType2) return unionType2;
|
|
533
533
|
}
|
|
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
|
-
}
|
|
534
|
+
const registeredType = findRegisteredTypeInUnionMembers(ast.types, ctx);
|
|
535
|
+
if (registeredType) return registeredType;
|
|
592
536
|
if (ast.types.length > 0) {
|
|
593
537
|
return toGraphQLTypeWithRegistry(S2.make(ast.types[0]), ctx);
|
|
594
538
|
}
|
|
@@ -633,7 +577,7 @@ function findEnumForLiteral(ast, ctx) {
|
|
|
633
577
|
}
|
|
634
578
|
return void 0;
|
|
635
579
|
}
|
|
636
|
-
function
|
|
580
|
+
function handleTupleTypeAST2(ast, ctx) {
|
|
637
581
|
if (ast.rest && ast.rest.length > 0) {
|
|
638
582
|
const elementSchema = S2.make(ast.rest[0].type);
|
|
639
583
|
const elementType = toGraphQLTypeWithRegistry(elementSchema, ctx);
|
|
@@ -733,170 +677,40 @@ function buildInputTypeLookupCache(inputs, enums) {
|
|
|
733
677
|
}
|
|
734
678
|
return cache;
|
|
735
679
|
}
|
|
736
|
-
function
|
|
737
|
-
const ast = schema.ast;
|
|
680
|
+
function findRegisteredInputType(schema, ast, inputs, inputRegistry, cache) {
|
|
738
681
|
if (cache?.schemaToInputName || cache?.astToInputName) {
|
|
739
682
|
const inputName = cache.schemaToInputName?.get(schema) ?? cache.astToInputName?.get(ast);
|
|
740
683
|
if (inputName) {
|
|
741
|
-
|
|
742
|
-
if (result) return result;
|
|
684
|
+
return inputRegistry.get(inputName);
|
|
743
685
|
}
|
|
744
686
|
} else {
|
|
745
687
|
for (const [inputName, inputReg] of inputs) {
|
|
746
688
|
if (inputReg.schema.ast === ast || inputReg.schema === schema) {
|
|
747
|
-
|
|
748
|
-
if (result) return result;
|
|
689
|
+
return inputRegistry.get(inputName);
|
|
749
690
|
}
|
|
750
691
|
}
|
|
751
692
|
}
|
|
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
|
-
}
|
|
693
|
+
return void 0;
|
|
694
|
+
}
|
|
695
|
+
function findRegisteredInputForAST(memberAst, inputs, inputRegistry, enumRegistry, enums, cache) {
|
|
696
|
+
const inputName = cache?.astToInputName?.get(memberAst);
|
|
697
|
+
if (inputName) {
|
|
698
|
+
const inputReg = inputs.get(inputName);
|
|
699
|
+
if (inputReg) {
|
|
700
|
+
return toGraphQLInputTypeWithRegistry(
|
|
701
|
+
inputReg.schema,
|
|
702
|
+
enumRegistry,
|
|
703
|
+
inputRegistry,
|
|
704
|
+
inputs,
|
|
705
|
+
enums,
|
|
706
|
+
cache
|
|
707
|
+
);
|
|
884
708
|
}
|
|
885
|
-
return toGraphQLInputTypeWithRegistry(
|
|
886
|
-
S2.make(toAst),
|
|
887
|
-
enumRegistry,
|
|
888
|
-
inputRegistry,
|
|
889
|
-
inputs,
|
|
890
|
-
enums,
|
|
891
|
-
cache
|
|
892
|
-
);
|
|
893
709
|
}
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
const nonUndefinedTypes = unionAst.types.filter((t) => t._tag !== "UndefinedKeyword");
|
|
897
|
-
if (nonUndefinedTypes.length === 1 && nonUndefinedTypes[0]._tag === "Union") {
|
|
710
|
+
for (const [, inputReg] of inputs) {
|
|
711
|
+
if (inputReg.schema.ast === memberAst) {
|
|
898
712
|
return toGraphQLInputTypeWithRegistry(
|
|
899
|
-
|
|
713
|
+
inputReg.schema,
|
|
900
714
|
enumRegistry,
|
|
901
715
|
inputRegistry,
|
|
902
716
|
inputs,
|
|
@@ -904,9 +718,18 @@ function toGraphQLInputTypeWithRegistry(schema, enumRegistry, inputRegistry, inp
|
|
|
904
718
|
cache
|
|
905
719
|
);
|
|
906
720
|
}
|
|
907
|
-
|
|
721
|
+
}
|
|
722
|
+
return void 0;
|
|
723
|
+
}
|
|
724
|
+
function findRegisteredInputForTransformation(memberAst, inputs, inputRegistry, enumRegistry, enums, cache) {
|
|
725
|
+
if (memberAst._tag !== "Transformation") return void 0;
|
|
726
|
+
const innerToAst = memberAst.to;
|
|
727
|
+
const transformedInputName = cache?.astToInputName?.get(innerToAst);
|
|
728
|
+
if (transformedInputName) {
|
|
729
|
+
const inputReg = inputs.get(transformedInputName);
|
|
730
|
+
if (inputReg) {
|
|
908
731
|
return toGraphQLInputTypeWithRegistry(
|
|
909
|
-
|
|
732
|
+
inputReg.schema,
|
|
910
733
|
enumRegistry,
|
|
911
734
|
inputRegistry,
|
|
912
735
|
inputs,
|
|
@@ -914,171 +737,210 @@ function toGraphQLInputTypeWithRegistry(schema, enumRegistry, inputRegistry, inp
|
|
|
914
737
|
cache
|
|
915
738
|
);
|
|
916
739
|
}
|
|
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"
|
|
740
|
+
}
|
|
741
|
+
for (const [, inputReg] of inputs) {
|
|
742
|
+
if (inputReg.schema.ast === innerToAst) {
|
|
743
|
+
return toGraphQLInputTypeWithRegistry(
|
|
744
|
+
inputReg.schema,
|
|
745
|
+
enumRegistry,
|
|
746
|
+
inputRegistry,
|
|
747
|
+
inputs,
|
|
748
|
+
enums,
|
|
749
|
+
cache
|
|
750
|
+
);
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
return void 0;
|
|
754
|
+
}
|
|
755
|
+
function findRegisteredInputForOptionSome(memberAst, inputs, inputRegistry, enumRegistry, enums, cache) {
|
|
756
|
+
if (memberAst._tag !== "TypeLiteral") return void 0;
|
|
757
|
+
const valueField = memberAst.propertySignatures?.find(
|
|
758
|
+
(p) => String(p.name) === "value"
|
|
759
|
+
);
|
|
760
|
+
if (!valueField) return void 0;
|
|
761
|
+
const valueType = valueField.type;
|
|
762
|
+
const valueInputName = cache?.astToInputName?.get(valueType);
|
|
763
|
+
if (valueInputName) {
|
|
764
|
+
const inputReg = inputs.get(valueInputName);
|
|
765
|
+
if (inputReg) {
|
|
766
|
+
return toGraphQLInputTypeWithRegistry(
|
|
767
|
+
inputReg.schema,
|
|
768
|
+
enumRegistry,
|
|
769
|
+
inputRegistry,
|
|
770
|
+
inputs,
|
|
771
|
+
enums,
|
|
772
|
+
cache
|
|
773
|
+
);
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
for (const [, inputReg] of inputs) {
|
|
777
|
+
if (inputReg.schema.ast === valueType) {
|
|
778
|
+
return toGraphQLInputTypeWithRegistry(
|
|
779
|
+
inputReg.schema,
|
|
780
|
+
enumRegistry,
|
|
781
|
+
inputRegistry,
|
|
782
|
+
inputs,
|
|
783
|
+
enums,
|
|
784
|
+
cache
|
|
785
|
+
);
|
|
786
|
+
}
|
|
787
|
+
let regAst = inputReg.schema.ast;
|
|
788
|
+
while (regAst._tag === "Transformation") {
|
|
789
|
+
regAst = regAst.to;
|
|
790
|
+
if (regAst === valueType) {
|
|
791
|
+
return toGraphQLInputTypeWithRegistry(
|
|
792
|
+
inputReg.schema,
|
|
793
|
+
enumRegistry,
|
|
794
|
+
inputRegistry,
|
|
795
|
+
inputs,
|
|
796
|
+
enums,
|
|
797
|
+
cache
|
|
976
798
|
);
|
|
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
799
|
}
|
|
1042
800
|
}
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
}
|
|
801
|
+
if (regAst._tag === "Declaration" && regAst.typeParameters?.[0] === valueType) {
|
|
802
|
+
return toGraphQLInputTypeWithRegistry(
|
|
803
|
+
inputReg.schema,
|
|
804
|
+
enumRegistry,
|
|
805
|
+
inputRegistry,
|
|
806
|
+
inputs,
|
|
807
|
+
enums,
|
|
808
|
+
cache
|
|
809
|
+
);
|
|
1053
810
|
}
|
|
1054
811
|
}
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
812
|
+
const innerResult = toGraphQLInputTypeWithRegistry(
|
|
813
|
+
S2.make(valueType),
|
|
814
|
+
enumRegistry,
|
|
815
|
+
inputRegistry,
|
|
816
|
+
inputs,
|
|
817
|
+
enums,
|
|
818
|
+
cache
|
|
819
|
+
);
|
|
820
|
+
return innerResult || void 0;
|
|
821
|
+
}
|
|
822
|
+
function handleOptionTransformationForInput(fromAst, toAst, inputs, inputRegistry, enumRegistry, enums, cache) {
|
|
823
|
+
if (!fromAst || fromAst._tag !== "Union") return void 0;
|
|
824
|
+
for (const memberAst of fromAst.types) {
|
|
825
|
+
if (memberAst._tag === "Literal") continue;
|
|
826
|
+
if (memberAst._tag === "UndefinedKeyword") continue;
|
|
827
|
+
const registeredInput = findRegisteredInputForAST(memberAst, inputs, inputRegistry, enumRegistry, enums, cache) || findRegisteredInputForTransformation(memberAst, inputs, inputRegistry, enumRegistry, enums, cache) || findRegisteredInputForOptionSome(memberAst, inputs, inputRegistry, enumRegistry, enums, cache);
|
|
828
|
+
if (registeredInput) return registeredInput;
|
|
829
|
+
}
|
|
830
|
+
return void 0;
|
|
831
|
+
}
|
|
832
|
+
function handleTransformationForInput(ast, inputs, inputRegistry, enumRegistry, enums, cache) {
|
|
833
|
+
const toAst = ast.to;
|
|
834
|
+
const fromAst = ast.from;
|
|
835
|
+
if (isOptionDeclaration2(toAst)) {
|
|
836
|
+
const optionResult = handleOptionTransformationForInput(
|
|
837
|
+
fromAst,
|
|
838
|
+
toAst,
|
|
839
|
+
inputs,
|
|
840
|
+
inputRegistry,
|
|
841
|
+
enumRegistry,
|
|
842
|
+
enums,
|
|
843
|
+
cache
|
|
844
|
+
);
|
|
845
|
+
if (optionResult) return optionResult;
|
|
846
|
+
}
|
|
847
|
+
return toGraphQLInputTypeWithRegistry(
|
|
848
|
+
S2.make(toAst),
|
|
849
|
+
enumRegistry,
|
|
850
|
+
inputRegistry,
|
|
851
|
+
inputs,
|
|
852
|
+
enums,
|
|
853
|
+
cache
|
|
854
|
+
);
|
|
855
|
+
}
|
|
856
|
+
function findRegisteredInputInUnionMembers(types, inputs, inputRegistry, enumRegistry, enums, cache) {
|
|
857
|
+
for (const memberAst of types) {
|
|
858
|
+
const registeredInput = findRegisteredInputForAST(memberAst, inputs, inputRegistry, enumRegistry, enums, cache) || findRegisteredInputForTransformation(memberAst, inputs, inputRegistry, enumRegistry, enums, cache) || findRegisteredInputForOptionSome(memberAst, inputs, inputRegistry, enumRegistry, enums, cache);
|
|
859
|
+
if (registeredInput) return registeredInput;
|
|
860
|
+
}
|
|
861
|
+
return void 0;
|
|
862
|
+
}
|
|
863
|
+
function handleUnionForInput(ast, inputs, inputRegistry, enumRegistry, enums, cache) {
|
|
864
|
+
const unionAst = ast;
|
|
865
|
+
const nonUndefinedTypes = unionAst.types.filter((t) => t._tag !== "UndefinedKeyword");
|
|
866
|
+
if (nonUndefinedTypes.length === 1) {
|
|
867
|
+
if (nonUndefinedTypes[0]._tag === "Union" || nonUndefinedTypes[0]._tag === "TypeLiteral") {
|
|
868
|
+
return toGraphQLInputTypeWithRegistry(
|
|
869
|
+
S2.make(nonUndefinedTypes[0]),
|
|
870
|
+
enumRegistry,
|
|
871
|
+
inputRegistry,
|
|
872
|
+
inputs,
|
|
873
|
+
enums,
|
|
874
|
+
cache
|
|
875
|
+
);
|
|
876
|
+
}
|
|
877
|
+
}
|
|
878
|
+
const registeredInput = findRegisteredInputInUnionMembers(
|
|
879
|
+
unionAst.types,
|
|
880
|
+
inputs,
|
|
881
|
+
inputRegistry,
|
|
882
|
+
enumRegistry,
|
|
883
|
+
enums,
|
|
884
|
+
cache
|
|
885
|
+
);
|
|
886
|
+
if (registeredInput) return registeredInput;
|
|
887
|
+
const allLiterals = unionAst.types.every((t) => t._tag === "Literal");
|
|
888
|
+
if (allLiterals) {
|
|
889
|
+
const literalValues = unionAst.types.map((t) => String(t.literal)).sort();
|
|
890
|
+
for (const [enumName] of enums) {
|
|
891
|
+
const enumValues = cache?.enumSortedValues?.get(enumName) ?? [...enums.get(enumName).values].sort();
|
|
892
|
+
if (literalValues.length === enumValues.length && literalValues.every((v, i) => v === enumValues[i])) {
|
|
1060
893
|
const result = enumRegistry.get(enumName);
|
|
1061
894
|
if (result) return result;
|
|
1062
895
|
}
|
|
1063
|
-
}
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
896
|
+
}
|
|
897
|
+
}
|
|
898
|
+
return void 0;
|
|
899
|
+
}
|
|
900
|
+
function handleLiteralForInput(ast, enumRegistry, enums, cache) {
|
|
901
|
+
const literalValue = String(ast.literal);
|
|
902
|
+
if (cache?.literalToEnumName) {
|
|
903
|
+
const enumName = cache.literalToEnumName.get(literalValue);
|
|
904
|
+
if (enumName) {
|
|
905
|
+
return enumRegistry.get(enumName);
|
|
906
|
+
}
|
|
907
|
+
} else {
|
|
908
|
+
for (const [enumName, enumReg] of enums) {
|
|
909
|
+
if (enumReg.values.includes(literalValue)) {
|
|
910
|
+
return enumRegistry.get(enumName);
|
|
1069
911
|
}
|
|
1070
912
|
}
|
|
1071
913
|
}
|
|
914
|
+
return void 0;
|
|
915
|
+
}
|
|
916
|
+
function handleSuspendForInput(ast, inputs, inputRegistry, enumRegistry, enums, cache) {
|
|
917
|
+
const innerAst = ast.f();
|
|
918
|
+
return toGraphQLInputTypeWithRegistry(
|
|
919
|
+
S2.make(innerAst),
|
|
920
|
+
enumRegistry,
|
|
921
|
+
inputRegistry,
|
|
922
|
+
inputs,
|
|
923
|
+
enums,
|
|
924
|
+
cache
|
|
925
|
+
);
|
|
926
|
+
}
|
|
927
|
+
function toGraphQLInputTypeWithRegistry(schema, enumRegistry, inputRegistry, inputs, enums, cache) {
|
|
928
|
+
const ast = schema.ast;
|
|
929
|
+
const registeredInput = findRegisteredInputType(schema, ast, inputs, inputRegistry, cache);
|
|
930
|
+
if (registeredInput) return registeredInput;
|
|
931
|
+
if (ast._tag === "Transformation") {
|
|
932
|
+
return handleTransformationForInput(ast, inputs, inputRegistry, enumRegistry, enums, cache);
|
|
933
|
+
}
|
|
934
|
+
if (ast._tag === "Union") {
|
|
935
|
+
const unionResult = handleUnionForInput(ast, inputs, inputRegistry, enumRegistry, enums, cache);
|
|
936
|
+
if (unionResult) return unionResult;
|
|
937
|
+
}
|
|
938
|
+
if (ast._tag === "Literal") {
|
|
939
|
+
const literalResult = handleLiteralForInput(ast, enumRegistry, enums, cache);
|
|
940
|
+
if (literalResult) return literalResult;
|
|
941
|
+
}
|
|
1072
942
|
if (ast._tag === "Suspend") {
|
|
1073
|
-
|
|
1074
|
-
return toGraphQLInputTypeWithRegistry(
|
|
1075
|
-
S2.make(innerAst),
|
|
1076
|
-
enumRegistry,
|
|
1077
|
-
inputRegistry,
|
|
1078
|
-
inputs,
|
|
1079
|
-
enums,
|
|
1080
|
-
cache
|
|
1081
|
-
);
|
|
943
|
+
return handleSuspendForInput(ast, inputs, inputRegistry, enumRegistry, enums, cache);
|
|
1082
944
|
}
|
|
1083
945
|
return toGraphQLInputType(schema);
|
|
1084
946
|
}
|