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