@effect-gql/core 1.4.7 → 1.4.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/builder/index.cjs +400 -517
- package/builder/index.cjs.map +1 -1
- package/builder/index.js +401 -518
- package/builder/index.js.map +1 -1
- package/index.cjs +402 -528
- package/index.cjs.map +1 -1
- package/index.js +403 -529
- package/index.js.map +1 -1
- package/package.json +1 -1
package/index.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';
|
|
@@ -13,7 +13,15 @@ var isIntegerType = (ast) => {
|
|
|
13
13
|
const annotations = refinement.annotations;
|
|
14
14
|
if (annotations) {
|
|
15
15
|
const identifier = AST.getIdentifierAnnotation(refinement);
|
|
16
|
-
if (identifier._tag === "Some"
|
|
16
|
+
if (identifier._tag === "Some") {
|
|
17
|
+
const id = identifier.value;
|
|
18
|
+
if (id === "Int" || id.includes("Int")) {
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
const JSONSchemaSymbol = /* @__PURE__ */ Symbol.for("effect/annotation/JSONSchema");
|
|
23
|
+
const jsonSchema = annotations[JSONSchemaSymbol];
|
|
24
|
+
if (jsonSchema && jsonSchema.type === "integer") {
|
|
17
25
|
return true;
|
|
18
26
|
}
|
|
19
27
|
}
|
|
@@ -21,6 +29,51 @@ var isIntegerType = (ast) => {
|
|
|
21
29
|
}
|
|
22
30
|
return false;
|
|
23
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
|
+
}
|
|
24
77
|
var isOptionDeclaration = (ast) => {
|
|
25
78
|
if (ast._tag === "Declaration") {
|
|
26
79
|
const annotations = ast.annotations;
|
|
@@ -51,41 +104,17 @@ var getOptionInnerType = (ast) => {
|
|
|
51
104
|
};
|
|
52
105
|
var toGraphQLType = (schema) => {
|
|
53
106
|
const ast = schema.ast;
|
|
54
|
-
|
|
55
|
-
if (
|
|
56
|
-
if (ast._tag === "BooleanKeyword") return GraphQLBoolean;
|
|
107
|
+
const primitiveResult = handlePrimitiveAST(ast);
|
|
108
|
+
if (primitiveResult) return primitiveResult;
|
|
57
109
|
if (ast._tag === "Refinement") {
|
|
58
|
-
|
|
59
|
-
return GraphQLInt;
|
|
60
|
-
}
|
|
61
|
-
return toGraphQLType(S2.make(ast.from));
|
|
62
|
-
}
|
|
63
|
-
if (ast._tag === "Literal") {
|
|
64
|
-
if (typeof ast.literal === "string") return GraphQLString;
|
|
65
|
-
if (typeof ast.literal === "number") {
|
|
66
|
-
return Number.isInteger(ast.literal) ? GraphQLInt : GraphQLFloat;
|
|
67
|
-
}
|
|
68
|
-
if (typeof ast.literal === "boolean") return GraphQLBoolean;
|
|
69
|
-
}
|
|
70
|
-
if (ast._tag === "TupleType") {
|
|
71
|
-
const elements = ast.elements;
|
|
72
|
-
if (elements.length > 0) {
|
|
73
|
-
const elementSchema = S2.make(elements[0].type);
|
|
74
|
-
return new GraphQLList(toGraphQLType(elementSchema));
|
|
75
|
-
}
|
|
110
|
+
return handleRefinementAST(ast, toGraphQLType);
|
|
76
111
|
}
|
|
112
|
+
const literalResult = handleLiteralAST(ast);
|
|
113
|
+
if (literalResult) return literalResult;
|
|
114
|
+
const tupleResult = handleTupleTypeAST(ast, toGraphQLType);
|
|
115
|
+
if (tupleResult) return tupleResult;
|
|
77
116
|
if (ast._tag === "TypeLiteral") {
|
|
78
|
-
const fields =
|
|
79
|
-
for (const field2 of ast.propertySignatures) {
|
|
80
|
-
const fieldName = String(field2.name);
|
|
81
|
-
if (fieldName === "_tag") continue;
|
|
82
|
-
const fieldSchema = S2.make(field2.type);
|
|
83
|
-
let fieldType = toGraphQLType(fieldSchema);
|
|
84
|
-
if (!field2.isOptional) {
|
|
85
|
-
fieldType = new GraphQLNonNull(fieldType);
|
|
86
|
-
}
|
|
87
|
-
fields[fieldName] = { type: fieldType };
|
|
88
|
-
}
|
|
117
|
+
const fields = buildFieldsFromPropertySignatures(ast.propertySignatures, toGraphQLType);
|
|
89
118
|
const typeName = schema.annotations?.identifier || `Object_${Math.random().toString(36).slice(2, 11)}`;
|
|
90
119
|
return new GraphQLObjectType({
|
|
91
120
|
name: typeName,
|
|
@@ -127,41 +156,19 @@ var toGraphQLType = (schema) => {
|
|
|
127
156
|
};
|
|
128
157
|
var toGraphQLInputType = (schema) => {
|
|
129
158
|
const ast = schema.ast;
|
|
130
|
-
|
|
131
|
-
if (
|
|
132
|
-
if (ast._tag === "BooleanKeyword") return GraphQLBoolean;
|
|
159
|
+
const primitiveResult = handlePrimitiveAST(ast);
|
|
160
|
+
if (primitiveResult) return primitiveResult;
|
|
133
161
|
if (ast._tag === "Refinement") {
|
|
134
|
-
|
|
135
|
-
return GraphQLInt;
|
|
136
|
-
}
|
|
137
|
-
return toGraphQLInputType(S2.make(ast.from));
|
|
138
|
-
}
|
|
139
|
-
if (ast._tag === "Literal") {
|
|
140
|
-
if (typeof ast.literal === "string") return GraphQLString;
|
|
141
|
-
if (typeof ast.literal === "number") {
|
|
142
|
-
return Number.isInteger(ast.literal) ? GraphQLInt : GraphQLFloat;
|
|
143
|
-
}
|
|
144
|
-
if (typeof ast.literal === "boolean") return GraphQLBoolean;
|
|
145
|
-
}
|
|
146
|
-
if (ast._tag === "TupleType") {
|
|
147
|
-
const elements = ast.elements;
|
|
148
|
-
if (elements.length > 0) {
|
|
149
|
-
const elementSchema = S2.make(elements[0].type);
|
|
150
|
-
return new GraphQLList(toGraphQLInputType(elementSchema));
|
|
151
|
-
}
|
|
162
|
+
return handleRefinementAST(ast, toGraphQLInputType);
|
|
152
163
|
}
|
|
164
|
+
const literalResult = handleLiteralAST(ast);
|
|
165
|
+
if (literalResult) return literalResult;
|
|
166
|
+
const tupleResult = handleTupleTypeAST(ast, toGraphQLInputType);
|
|
167
|
+
if (tupleResult) return tupleResult;
|
|
153
168
|
if (ast._tag === "TypeLiteral") {
|
|
154
|
-
const fields =
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
if (fieldName === "_tag") continue;
|
|
158
|
-
const fieldSchema = S2.make(field2.type);
|
|
159
|
-
let fieldType = toGraphQLInputType(fieldSchema);
|
|
160
|
-
if (!field2.isOptional) {
|
|
161
|
-
fieldType = new GraphQLNonNull(fieldType);
|
|
162
|
-
}
|
|
163
|
-
fields[fieldName] = { type: fieldType };
|
|
164
|
-
}
|
|
169
|
+
const fields = buildFieldsFromPropertySignatures(
|
|
170
|
+
ast.propertySignatures,
|
|
171
|
+
toGraphQLInputType);
|
|
165
172
|
const typeName = schema.annotations?.identifier || `Input_${Math.random().toString(36).slice(2, 11)}`;
|
|
166
173
|
return new GraphQLInputObjectType({
|
|
167
174
|
name: typeName,
|
|
@@ -214,17 +221,8 @@ var toGraphQLObjectType = (name, schema, additionalFields) => {
|
|
|
214
221
|
}
|
|
215
222
|
}
|
|
216
223
|
if (ast._tag === "TypeLiteral") {
|
|
217
|
-
const
|
|
218
|
-
|
|
219
|
-
const fieldName = String(field2.name);
|
|
220
|
-
if (fieldName === "_tag") continue;
|
|
221
|
-
const fieldSchema = S2.make(field2.type);
|
|
222
|
-
let fieldType = toGraphQLType(fieldSchema);
|
|
223
|
-
if (!field2.isOptional) {
|
|
224
|
-
fieldType = new GraphQLNonNull(fieldType);
|
|
225
|
-
}
|
|
226
|
-
fields[fieldName] = { type: fieldType };
|
|
227
|
-
}
|
|
224
|
+
const baseFields = buildFieldsFromPropertySignatures(ast.propertySignatures, toGraphQLType);
|
|
225
|
+
const fields = { ...baseFields };
|
|
228
226
|
if (additionalFields) {
|
|
229
227
|
for (const [fieldName, fieldConfig] of Object.entries(additionalFields)) {
|
|
230
228
|
fields[fieldName] = {
|
|
@@ -246,17 +244,7 @@ var toGraphQLObjectType = (name, schema, additionalFields) => {
|
|
|
246
244
|
var toGraphQLArgs = (schema) => {
|
|
247
245
|
const ast = schema.ast;
|
|
248
246
|
if (ast._tag === "TypeLiteral") {
|
|
249
|
-
const args =
|
|
250
|
-
for (const field2 of ast.propertySignatures) {
|
|
251
|
-
const fieldName = String(field2.name);
|
|
252
|
-
if (fieldName === "_tag") continue;
|
|
253
|
-
const fieldSchema = S2.make(field2.type);
|
|
254
|
-
let fieldType = toGraphQLInputType(fieldSchema);
|
|
255
|
-
if (!field2.isOptional) {
|
|
256
|
-
fieldType = new GraphQLNonNull(fieldType);
|
|
257
|
-
}
|
|
258
|
-
args[fieldName] = { type: fieldType };
|
|
259
|
-
}
|
|
247
|
+
const args = buildFieldsFromPropertySignatures(ast.propertySignatures, toGraphQLInputType);
|
|
260
248
|
return args;
|
|
261
249
|
}
|
|
262
250
|
throw new Error(`Schema must be an object type to convert to GraphQL arguments`);
|
|
@@ -372,7 +360,7 @@ function toGraphQLTypeWithRegistry(schema, ctx) {
|
|
|
372
360
|
if (enumType2) return enumType2;
|
|
373
361
|
}
|
|
374
362
|
if (ast._tag === "TupleType") {
|
|
375
|
-
return
|
|
363
|
+
return handleTupleTypeAST2(ast, ctx);
|
|
376
364
|
}
|
|
377
365
|
if (ast._tag === "Declaration") {
|
|
378
366
|
if (isOptionDeclaration2(ast)) {
|
|
@@ -428,88 +416,112 @@ function getOptionInnerType2(ast) {
|
|
|
428
416
|
}
|
|
429
417
|
return void 0;
|
|
430
418
|
}
|
|
431
|
-
function
|
|
432
|
-
const
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
if (
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
const result = ctx.typeRegistry.get(regTypeName);
|
|
478
|
-
if (result) return result;
|
|
479
|
-
}
|
|
480
|
-
let regAst = typeReg.schema.ast;
|
|
481
|
-
while (regAst._tag === "Transformation") {
|
|
482
|
-
regAst = regAst.to;
|
|
483
|
-
if (regAst === valueType) {
|
|
484
|
-
const result = ctx.typeRegistry.get(regTypeName);
|
|
485
|
-
if (result) return result;
|
|
486
|
-
}
|
|
487
|
-
}
|
|
488
|
-
}
|
|
489
|
-
const innerResult = toGraphQLTypeWithRegistry(S2.make(valueType), ctx);
|
|
490
|
-
if (innerResult) return innerResult;
|
|
491
|
-
}
|
|
492
|
-
}
|
|
493
|
-
}
|
|
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;
|
|
429
|
+
}
|
|
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;
|
|
445
|
+
}
|
|
446
|
+
}
|
|
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;
|
|
494
465
|
}
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
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
|
+
}
|
|
498
473
|
}
|
|
499
474
|
}
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
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;
|
|
509
485
|
}
|
|
510
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;
|
|
511
516
|
return toGraphQLTypeWithRegistry(S2.make(ast.to), ctx);
|
|
512
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
|
+
}
|
|
513
525
|
function handleUnionAST(ast, ctx) {
|
|
514
526
|
const allLiterals = ast.types.every((t) => t._tag === "Literal");
|
|
515
527
|
if (allLiterals) {
|
|
@@ -519,64 +531,8 @@ function handleUnionAST(ast, ctx) {
|
|
|
519
531
|
const unionType2 = findRegisteredUnion(ast.types, ctx);
|
|
520
532
|
if (unionType2) return unionType2;
|
|
521
533
|
}
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
if (typeName) {
|
|
525
|
-
const result = ctx.typeRegistry.get(typeName);
|
|
526
|
-
if (result) return result;
|
|
527
|
-
}
|
|
528
|
-
for (const [regTypeName, typeReg] of ctx.types) {
|
|
529
|
-
if (typeReg.schema.ast === memberAst) {
|
|
530
|
-
const result = ctx.typeRegistry.get(regTypeName);
|
|
531
|
-
if (result) return result;
|
|
532
|
-
}
|
|
533
|
-
}
|
|
534
|
-
if (memberAst._tag === "Transformation") {
|
|
535
|
-
const toAst = memberAst.to;
|
|
536
|
-
const transformedTypeName = ctx.astToTypeName?.get(toAst);
|
|
537
|
-
if (transformedTypeName) {
|
|
538
|
-
const result = ctx.typeRegistry.get(transformedTypeName);
|
|
539
|
-
if (result) return result;
|
|
540
|
-
}
|
|
541
|
-
for (const [regTypeName, typeReg] of ctx.types) {
|
|
542
|
-
if (typeReg.schema.ast === toAst) {
|
|
543
|
-
const result = ctx.typeRegistry.get(regTypeName);
|
|
544
|
-
if (result) return result;
|
|
545
|
-
}
|
|
546
|
-
}
|
|
547
|
-
}
|
|
548
|
-
if (memberAst._tag === "TypeLiteral") {
|
|
549
|
-
const valueField = memberAst.propertySignatures?.find(
|
|
550
|
-
(p) => String(p.name) === "value"
|
|
551
|
-
);
|
|
552
|
-
if (valueField) {
|
|
553
|
-
const valueType = valueField.type;
|
|
554
|
-
const valueTypeName = ctx.astToTypeName?.get(valueType);
|
|
555
|
-
if (valueTypeName) {
|
|
556
|
-
const result = ctx.typeRegistry.get(valueTypeName);
|
|
557
|
-
if (result) return result;
|
|
558
|
-
}
|
|
559
|
-
for (const [regTypeName, typeReg] of ctx.types) {
|
|
560
|
-
if (typeReg.schema.ast === valueType) {
|
|
561
|
-
const result = ctx.typeRegistry.get(regTypeName);
|
|
562
|
-
if (result) return result;
|
|
563
|
-
}
|
|
564
|
-
let regAst = typeReg.schema.ast;
|
|
565
|
-
while (regAst._tag === "Transformation") {
|
|
566
|
-
regAst = regAst.to;
|
|
567
|
-
if (regAst === valueType) {
|
|
568
|
-
const result = ctx.typeRegistry.get(regTypeName);
|
|
569
|
-
if (result) return result;
|
|
570
|
-
}
|
|
571
|
-
}
|
|
572
|
-
}
|
|
573
|
-
const innerResult = toGraphQLTypeWithRegistry(S2.make(valueType), ctx);
|
|
574
|
-
if (innerResult) {
|
|
575
|
-
return innerResult;
|
|
576
|
-
}
|
|
577
|
-
}
|
|
578
|
-
}
|
|
579
|
-
}
|
|
534
|
+
const registeredType = findRegisteredTypeInUnionMembers(ast.types, ctx);
|
|
535
|
+
if (registeredType) return registeredType;
|
|
580
536
|
if (ast.types.length > 0) {
|
|
581
537
|
return toGraphQLTypeWithRegistry(S2.make(ast.types[0]), ctx);
|
|
582
538
|
}
|
|
@@ -621,7 +577,7 @@ function findEnumForLiteral(ast, ctx) {
|
|
|
621
577
|
}
|
|
622
578
|
return void 0;
|
|
623
579
|
}
|
|
624
|
-
function
|
|
580
|
+
function handleTupleTypeAST2(ast, ctx) {
|
|
625
581
|
if (ast.rest && ast.rest.length > 0) {
|
|
626
582
|
const elementSchema = S2.make(ast.rest[0].type);
|
|
627
583
|
const elementType = toGraphQLTypeWithRegistry(elementSchema, ctx);
|
|
@@ -721,170 +677,40 @@ function buildInputTypeLookupCache(inputs, enums) {
|
|
|
721
677
|
}
|
|
722
678
|
return cache;
|
|
723
679
|
}
|
|
724
|
-
function
|
|
725
|
-
const ast = schema.ast;
|
|
680
|
+
function findRegisteredInputType(schema, ast, inputs, inputRegistry, cache) {
|
|
726
681
|
if (cache?.schemaToInputName || cache?.astToInputName) {
|
|
727
682
|
const inputName = cache.schemaToInputName?.get(schema) ?? cache.astToInputName?.get(ast);
|
|
728
683
|
if (inputName) {
|
|
729
|
-
|
|
730
|
-
if (result) return result;
|
|
684
|
+
return inputRegistry.get(inputName);
|
|
731
685
|
}
|
|
732
686
|
} else {
|
|
733
687
|
for (const [inputName, inputReg] of inputs) {
|
|
734
688
|
if (inputReg.schema.ast === ast || inputReg.schema === schema) {
|
|
735
|
-
|
|
736
|
-
if (result) return result;
|
|
689
|
+
return inputRegistry.get(inputName);
|
|
737
690
|
}
|
|
738
691
|
}
|
|
739
692
|
}
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
inputs,
|
|
756
|
-
enums,
|
|
757
|
-
cache
|
|
758
|
-
);
|
|
759
|
-
}
|
|
760
|
-
}
|
|
761
|
-
for (const [, inputReg] of inputs) {
|
|
762
|
-
if (inputReg.schema.ast === memberAst) {
|
|
763
|
-
return toGraphQLInputTypeWithRegistry(
|
|
764
|
-
inputReg.schema,
|
|
765
|
-
enumRegistry,
|
|
766
|
-
inputRegistry,
|
|
767
|
-
inputs,
|
|
768
|
-
enums,
|
|
769
|
-
cache
|
|
770
|
-
);
|
|
771
|
-
}
|
|
772
|
-
}
|
|
773
|
-
if (memberAst._tag === "Transformation") {
|
|
774
|
-
const innerToAst = memberAst.to;
|
|
775
|
-
const transformedInputName = cache?.astToInputName?.get(innerToAst);
|
|
776
|
-
if (transformedInputName) {
|
|
777
|
-
const inputReg = inputs.get(transformedInputName);
|
|
778
|
-
if (inputReg) {
|
|
779
|
-
return toGraphQLInputTypeWithRegistry(
|
|
780
|
-
inputReg.schema,
|
|
781
|
-
enumRegistry,
|
|
782
|
-
inputRegistry,
|
|
783
|
-
inputs,
|
|
784
|
-
enums,
|
|
785
|
-
cache
|
|
786
|
-
);
|
|
787
|
-
}
|
|
788
|
-
}
|
|
789
|
-
for (const [, inputReg] of inputs) {
|
|
790
|
-
if (inputReg.schema.ast === innerToAst) {
|
|
791
|
-
return toGraphQLInputTypeWithRegistry(
|
|
792
|
-
inputReg.schema,
|
|
793
|
-
enumRegistry,
|
|
794
|
-
inputRegistry,
|
|
795
|
-
inputs,
|
|
796
|
-
enums,
|
|
797
|
-
cache
|
|
798
|
-
);
|
|
799
|
-
}
|
|
800
|
-
}
|
|
801
|
-
}
|
|
802
|
-
if (memberAst._tag === "TypeLiteral") {
|
|
803
|
-
const valueField = memberAst.propertySignatures?.find(
|
|
804
|
-
(p) => String(p.name) === "value"
|
|
805
|
-
);
|
|
806
|
-
if (valueField) {
|
|
807
|
-
const valueType = valueField.type;
|
|
808
|
-
const valueInputName = cache?.astToInputName?.get(valueType);
|
|
809
|
-
if (valueInputName) {
|
|
810
|
-
const inputReg = inputs.get(valueInputName);
|
|
811
|
-
if (inputReg) {
|
|
812
|
-
return toGraphQLInputTypeWithRegistry(
|
|
813
|
-
inputReg.schema,
|
|
814
|
-
enumRegistry,
|
|
815
|
-
inputRegistry,
|
|
816
|
-
inputs,
|
|
817
|
-
enums,
|
|
818
|
-
cache
|
|
819
|
-
);
|
|
820
|
-
}
|
|
821
|
-
}
|
|
822
|
-
for (const [, inputReg] of inputs) {
|
|
823
|
-
if (inputReg.schema.ast === valueType) {
|
|
824
|
-
return toGraphQLInputTypeWithRegistry(
|
|
825
|
-
inputReg.schema,
|
|
826
|
-
enumRegistry,
|
|
827
|
-
inputRegistry,
|
|
828
|
-
inputs,
|
|
829
|
-
enums,
|
|
830
|
-
cache
|
|
831
|
-
);
|
|
832
|
-
}
|
|
833
|
-
let regAst = inputReg.schema.ast;
|
|
834
|
-
while (regAst._tag === "Transformation") {
|
|
835
|
-
regAst = regAst.to;
|
|
836
|
-
if (regAst === valueType) {
|
|
837
|
-
return toGraphQLInputTypeWithRegistry(
|
|
838
|
-
inputReg.schema,
|
|
839
|
-
enumRegistry,
|
|
840
|
-
inputRegistry,
|
|
841
|
-
inputs,
|
|
842
|
-
enums,
|
|
843
|
-
cache
|
|
844
|
-
);
|
|
845
|
-
}
|
|
846
|
-
}
|
|
847
|
-
if (regAst._tag === "Declaration" && regAst.typeParameters?.[0] === valueType) {
|
|
848
|
-
return toGraphQLInputTypeWithRegistry(
|
|
849
|
-
inputReg.schema,
|
|
850
|
-
enumRegistry,
|
|
851
|
-
inputRegistry,
|
|
852
|
-
inputs,
|
|
853
|
-
enums,
|
|
854
|
-
cache
|
|
855
|
-
);
|
|
856
|
-
}
|
|
857
|
-
}
|
|
858
|
-
const innerResult = toGraphQLInputTypeWithRegistry(
|
|
859
|
-
S2.make(valueType),
|
|
860
|
-
enumRegistry,
|
|
861
|
-
inputRegistry,
|
|
862
|
-
inputs,
|
|
863
|
-
enums,
|
|
864
|
-
cache
|
|
865
|
-
);
|
|
866
|
-
if (innerResult) {
|
|
867
|
-
return innerResult;
|
|
868
|
-
}
|
|
869
|
-
}
|
|
870
|
-
}
|
|
871
|
-
}
|
|
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
|
+
);
|
|
872
708
|
}
|
|
873
|
-
return toGraphQLInputTypeWithRegistry(
|
|
874
|
-
S2.make(toAst),
|
|
875
|
-
enumRegistry,
|
|
876
|
-
inputRegistry,
|
|
877
|
-
inputs,
|
|
878
|
-
enums,
|
|
879
|
-
cache
|
|
880
|
-
);
|
|
881
709
|
}
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
const nonUndefinedTypes = unionAst.types.filter((t) => t._tag !== "UndefinedKeyword");
|
|
885
|
-
if (nonUndefinedTypes.length === 1 && nonUndefinedTypes[0]._tag === "Union") {
|
|
710
|
+
for (const [, inputReg] of inputs) {
|
|
711
|
+
if (inputReg.schema.ast === memberAst) {
|
|
886
712
|
return toGraphQLInputTypeWithRegistry(
|
|
887
|
-
|
|
713
|
+
inputReg.schema,
|
|
888
714
|
enumRegistry,
|
|
889
715
|
inputRegistry,
|
|
890
716
|
inputs,
|
|
@@ -892,9 +718,18 @@ function toGraphQLInputTypeWithRegistry(schema, enumRegistry, inputRegistry, inp
|
|
|
892
718
|
cache
|
|
893
719
|
);
|
|
894
720
|
}
|
|
895
|
-
|
|
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) {
|
|
896
731
|
return toGraphQLInputTypeWithRegistry(
|
|
897
|
-
|
|
732
|
+
inputReg.schema,
|
|
898
733
|
enumRegistry,
|
|
899
734
|
inputRegistry,
|
|
900
735
|
inputs,
|
|
@@ -902,171 +737,210 @@ function toGraphQLInputTypeWithRegistry(schema, enumRegistry, inputRegistry, inp
|
|
|
902
737
|
cache
|
|
903
738
|
);
|
|
904
739
|
}
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
(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
|
|
964
798
|
);
|
|
965
|
-
if (valueField) {
|
|
966
|
-
const valueType = valueField.type;
|
|
967
|
-
const valueInputName = cache?.astToInputName?.get(valueType);
|
|
968
|
-
if (valueInputName) {
|
|
969
|
-
const inputReg = inputs.get(valueInputName);
|
|
970
|
-
if (inputReg) {
|
|
971
|
-
return toGraphQLInputTypeWithRegistry(
|
|
972
|
-
inputReg.schema,
|
|
973
|
-
enumRegistry,
|
|
974
|
-
inputRegistry,
|
|
975
|
-
inputs,
|
|
976
|
-
enums,
|
|
977
|
-
cache
|
|
978
|
-
);
|
|
979
|
-
}
|
|
980
|
-
}
|
|
981
|
-
for (const [, inputReg] of inputs) {
|
|
982
|
-
if (inputReg.schema.ast === valueType) {
|
|
983
|
-
return toGraphQLInputTypeWithRegistry(
|
|
984
|
-
inputReg.schema,
|
|
985
|
-
enumRegistry,
|
|
986
|
-
inputRegistry,
|
|
987
|
-
inputs,
|
|
988
|
-
enums,
|
|
989
|
-
cache
|
|
990
|
-
);
|
|
991
|
-
}
|
|
992
|
-
let regAst = inputReg.schema.ast;
|
|
993
|
-
while (regAst._tag === "Transformation") {
|
|
994
|
-
regAst = regAst.to;
|
|
995
|
-
if (regAst === valueType) {
|
|
996
|
-
return toGraphQLInputTypeWithRegistry(
|
|
997
|
-
inputReg.schema,
|
|
998
|
-
enumRegistry,
|
|
999
|
-
inputRegistry,
|
|
1000
|
-
inputs,
|
|
1001
|
-
enums,
|
|
1002
|
-
cache
|
|
1003
|
-
);
|
|
1004
|
-
}
|
|
1005
|
-
}
|
|
1006
|
-
if (regAst._tag === "Declaration" && regAst.typeParameters?.[0] === valueType) {
|
|
1007
|
-
return toGraphQLInputTypeWithRegistry(
|
|
1008
|
-
inputReg.schema,
|
|
1009
|
-
enumRegistry,
|
|
1010
|
-
inputRegistry,
|
|
1011
|
-
inputs,
|
|
1012
|
-
enums,
|
|
1013
|
-
cache
|
|
1014
|
-
);
|
|
1015
|
-
}
|
|
1016
|
-
}
|
|
1017
|
-
const innerResult = toGraphQLInputTypeWithRegistry(
|
|
1018
|
-
S2.make(valueType),
|
|
1019
|
-
enumRegistry,
|
|
1020
|
-
inputRegistry,
|
|
1021
|
-
inputs,
|
|
1022
|
-
enums,
|
|
1023
|
-
cache
|
|
1024
|
-
);
|
|
1025
|
-
if (innerResult) {
|
|
1026
|
-
return innerResult;
|
|
1027
|
-
}
|
|
1028
|
-
}
|
|
1029
799
|
}
|
|
1030
800
|
}
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
}
|
|
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
|
+
);
|
|
1041
810
|
}
|
|
1042
811
|
}
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
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])) {
|
|
1048
893
|
const result = enumRegistry.get(enumName);
|
|
1049
894
|
if (result) return result;
|
|
1050
895
|
}
|
|
1051
|
-
}
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
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);
|
|
1057
911
|
}
|
|
1058
912
|
}
|
|
1059
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
|
+
}
|
|
1060
942
|
if (ast._tag === "Suspend") {
|
|
1061
|
-
|
|
1062
|
-
return toGraphQLInputTypeWithRegistry(
|
|
1063
|
-
S2.make(innerAst),
|
|
1064
|
-
enumRegistry,
|
|
1065
|
-
inputRegistry,
|
|
1066
|
-
inputs,
|
|
1067
|
-
enums,
|
|
1068
|
-
cache
|
|
1069
|
-
);
|
|
943
|
+
return handleSuspendForInput(ast, inputs, inputRegistry, enumRegistry, enums, cache);
|
|
1070
944
|
}
|
|
1071
945
|
return toGraphQLInputType(schema);
|
|
1072
946
|
}
|