@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 CHANGED
@@ -33,7 +33,15 @@ var isIntegerType = (ast) => {
33
33
  const annotations = refinement.annotations;
34
34
  if (annotations) {
35
35
  const identifier = AST__namespace.getIdentifierAnnotation(refinement);
36
- if (identifier._tag === "Some" && identifier.value === "Int") {
36
+ if (identifier._tag === "Some") {
37
+ const id = identifier.value;
38
+ if (id === "Int" || id.includes("Int")) {
39
+ return true;
40
+ }
41
+ }
42
+ const JSONSchemaSymbol = /* @__PURE__ */ Symbol.for("effect/annotation/JSONSchema");
43
+ const jsonSchema = annotations[JSONSchemaSymbol];
44
+ if (jsonSchema && jsonSchema.type === "integer") {
37
45
  return true;
38
46
  }
39
47
  }
@@ -41,6 +49,51 @@ var isIntegerType = (ast) => {
41
49
  }
42
50
  return false;
43
51
  };
52
+ function handlePrimitiveAST(ast) {
53
+ if (ast._tag === "StringKeyword") return graphql.GraphQLString;
54
+ if (ast._tag === "NumberKeyword") return graphql.GraphQLFloat;
55
+ if (ast._tag === "BooleanKeyword") return graphql.GraphQLBoolean;
56
+ return void 0;
57
+ }
58
+ function handleRefinementAST(ast, convertFn) {
59
+ if (isIntegerType(ast)) {
60
+ return graphql.GraphQLInt;
61
+ }
62
+ return convertFn(S2__namespace.make(ast.from));
63
+ }
64
+ function handleLiteralAST(ast) {
65
+ if (ast._tag !== "Literal") return void 0;
66
+ if (typeof ast.literal === "string") return graphql.GraphQLString;
67
+ if (typeof ast.literal === "number") {
68
+ return Number.isInteger(ast.literal) ? graphql.GraphQLInt : graphql.GraphQLFloat;
69
+ }
70
+ if (typeof ast.literal === "boolean") return graphql.GraphQLBoolean;
71
+ return void 0;
72
+ }
73
+ function handleTupleTypeAST(ast, convertFn) {
74
+ if (ast._tag !== "TupleType") return void 0;
75
+ const elements = ast.elements;
76
+ if (elements.length > 0) {
77
+ const elementSchema = S2__namespace.make(elements[0].type);
78
+ return new graphql.GraphQLList(convertFn(elementSchema));
79
+ }
80
+ return void 0;
81
+ }
82
+ function buildFieldsFromPropertySignatures(propertySignatures, convertFn, isInput) {
83
+ const fields = {};
84
+ for (const field2 of propertySignatures) {
85
+ const fieldName = String(field2.name);
86
+ if (fieldName === "_tag") continue;
87
+ const fieldSchema = S2__namespace.make(field2.type);
88
+ let fieldType = convertFn(fieldSchema);
89
+ const isOptionField = isOptionTransformation(field2.type) || isOptionDeclaration(field2.type);
90
+ if (!field2.isOptional && !isOptionField) {
91
+ fieldType = new graphql.GraphQLNonNull(fieldType);
92
+ }
93
+ fields[fieldName] = { type: fieldType };
94
+ }
95
+ return fields;
96
+ }
44
97
  var isOptionDeclaration = (ast) => {
45
98
  if (ast._tag === "Declaration") {
46
99
  const annotations = ast.annotations;
@@ -71,41 +124,17 @@ var getOptionInnerType = (ast) => {
71
124
  };
72
125
  var toGraphQLType = (schema) => {
73
126
  const ast = schema.ast;
74
- if (ast._tag === "StringKeyword") return graphql.GraphQLString;
75
- if (ast._tag === "NumberKeyword") return graphql.GraphQLFloat;
76
- if (ast._tag === "BooleanKeyword") return graphql.GraphQLBoolean;
127
+ const primitiveResult = handlePrimitiveAST(ast);
128
+ if (primitiveResult) return primitiveResult;
77
129
  if (ast._tag === "Refinement") {
78
- if (isIntegerType(ast)) {
79
- return graphql.GraphQLInt;
80
- }
81
- return toGraphQLType(S2__namespace.make(ast.from));
82
- }
83
- if (ast._tag === "Literal") {
84
- if (typeof ast.literal === "string") return graphql.GraphQLString;
85
- if (typeof ast.literal === "number") {
86
- return Number.isInteger(ast.literal) ? graphql.GraphQLInt : graphql.GraphQLFloat;
87
- }
88
- if (typeof ast.literal === "boolean") return graphql.GraphQLBoolean;
89
- }
90
- if (ast._tag === "TupleType") {
91
- const elements = ast.elements;
92
- if (elements.length > 0) {
93
- const elementSchema = S2__namespace.make(elements[0].type);
94
- return new graphql.GraphQLList(toGraphQLType(elementSchema));
95
- }
130
+ return handleRefinementAST(ast, toGraphQLType);
96
131
  }
132
+ const literalResult = handleLiteralAST(ast);
133
+ if (literalResult) return literalResult;
134
+ const tupleResult = handleTupleTypeAST(ast, toGraphQLType);
135
+ if (tupleResult) return tupleResult;
97
136
  if (ast._tag === "TypeLiteral") {
98
- const fields = {};
99
- for (const field2 of ast.propertySignatures) {
100
- const fieldName = String(field2.name);
101
- if (fieldName === "_tag") continue;
102
- const fieldSchema = S2__namespace.make(field2.type);
103
- let fieldType = toGraphQLType(fieldSchema);
104
- if (!field2.isOptional) {
105
- fieldType = new graphql.GraphQLNonNull(fieldType);
106
- }
107
- fields[fieldName] = { type: fieldType };
108
- }
137
+ const fields = buildFieldsFromPropertySignatures(ast.propertySignatures, toGraphQLType);
109
138
  const typeName = schema.annotations?.identifier || `Object_${Math.random().toString(36).slice(2, 11)}`;
110
139
  return new graphql.GraphQLObjectType({
111
140
  name: typeName,
@@ -147,41 +176,19 @@ var toGraphQLType = (schema) => {
147
176
  };
148
177
  var toGraphQLInputType = (schema) => {
149
178
  const ast = schema.ast;
150
- if (ast._tag === "StringKeyword") return graphql.GraphQLString;
151
- if (ast._tag === "NumberKeyword") return graphql.GraphQLFloat;
152
- if (ast._tag === "BooleanKeyword") return graphql.GraphQLBoolean;
179
+ const primitiveResult = handlePrimitiveAST(ast);
180
+ if (primitiveResult) return primitiveResult;
153
181
  if (ast._tag === "Refinement") {
154
- if (isIntegerType(ast)) {
155
- return graphql.GraphQLInt;
156
- }
157
- return toGraphQLInputType(S2__namespace.make(ast.from));
158
- }
159
- if (ast._tag === "Literal") {
160
- if (typeof ast.literal === "string") return graphql.GraphQLString;
161
- if (typeof ast.literal === "number") {
162
- return Number.isInteger(ast.literal) ? graphql.GraphQLInt : graphql.GraphQLFloat;
163
- }
164
- if (typeof ast.literal === "boolean") return graphql.GraphQLBoolean;
165
- }
166
- if (ast._tag === "TupleType") {
167
- const elements = ast.elements;
168
- if (elements.length > 0) {
169
- const elementSchema = S2__namespace.make(elements[0].type);
170
- return new graphql.GraphQLList(toGraphQLInputType(elementSchema));
171
- }
182
+ return handleRefinementAST(ast, toGraphQLInputType);
172
183
  }
184
+ const literalResult = handleLiteralAST(ast);
185
+ if (literalResult) return literalResult;
186
+ const tupleResult = handleTupleTypeAST(ast, toGraphQLInputType);
187
+ if (tupleResult) return tupleResult;
173
188
  if (ast._tag === "TypeLiteral") {
174
- const fields = {};
175
- for (const field2 of ast.propertySignatures) {
176
- const fieldName = String(field2.name);
177
- if (fieldName === "_tag") continue;
178
- const fieldSchema = S2__namespace.make(field2.type);
179
- let fieldType = toGraphQLInputType(fieldSchema);
180
- if (!field2.isOptional) {
181
- fieldType = new graphql.GraphQLNonNull(fieldType);
182
- }
183
- fields[fieldName] = { type: fieldType };
184
- }
189
+ const fields = buildFieldsFromPropertySignatures(
190
+ ast.propertySignatures,
191
+ toGraphQLInputType);
185
192
  const typeName = schema.annotations?.identifier || `Input_${Math.random().toString(36).slice(2, 11)}`;
186
193
  return new graphql.GraphQLInputObjectType({
187
194
  name: typeName,
@@ -222,17 +229,7 @@ var toGraphQLInputType = (schema) => {
222
229
  var toGraphQLArgs = (schema) => {
223
230
  const ast = schema.ast;
224
231
  if (ast._tag === "TypeLiteral") {
225
- const args = {};
226
- for (const field2 of ast.propertySignatures) {
227
- const fieldName = String(field2.name);
228
- if (fieldName === "_tag") continue;
229
- const fieldSchema = S2__namespace.make(field2.type);
230
- let fieldType = toGraphQLInputType(fieldSchema);
231
- if (!field2.isOptional) {
232
- fieldType = new graphql.GraphQLNonNull(fieldType);
233
- }
234
- args[fieldName] = { type: fieldType };
235
- }
232
+ const args = buildFieldsFromPropertySignatures(ast.propertySignatures, toGraphQLInputType);
236
233
  return args;
237
234
  }
238
235
  throw new Error(`Schema must be an object type to convert to GraphQL arguments`);
@@ -348,7 +345,7 @@ function toGraphQLTypeWithRegistry(schema, ctx) {
348
345
  if (enumType2) return enumType2;
349
346
  }
350
347
  if (ast._tag === "TupleType") {
351
- return handleTupleTypeAST(ast, ctx);
348
+ return handleTupleTypeAST2(ast, ctx);
352
349
  }
353
350
  if (ast._tag === "Declaration") {
354
351
  if (isOptionDeclaration2(ast)) {
@@ -404,88 +401,112 @@ function getOptionInnerType2(ast) {
404
401
  }
405
402
  return void 0;
406
403
  }
407
- function handleTransformationAST(ast, ctx) {
408
- const toAst = ast.to;
409
- const fromAst = ast.from;
410
- if (isOptionDeclaration2(toAst)) {
411
- if (fromAst && fromAst._tag === "Union") {
412
- for (const memberAst of fromAst.types) {
413
- if (memberAst._tag === "Literal") continue;
414
- if (memberAst._tag === "UndefinedKeyword") continue;
415
- const typeName = ctx.astToTypeName?.get(memberAst);
416
- if (typeName) {
417
- const result = ctx.typeRegistry.get(typeName);
418
- if (result) return result;
419
- }
420
- for (const [regTypeName, typeReg] of ctx.types) {
421
- if (typeReg.schema.ast === memberAst) {
422
- const result = ctx.typeRegistry.get(regTypeName);
423
- if (result) return result;
424
- }
425
- }
426
- if (memberAst._tag === "Transformation") {
427
- const innerToAst = memberAst.to;
428
- const transformedTypeName = ctx.astToTypeName?.get(innerToAst);
429
- if (transformedTypeName) {
430
- const result = ctx.typeRegistry.get(transformedTypeName);
431
- if (result) return result;
432
- }
433
- for (const [regTypeName, typeReg] of ctx.types) {
434
- if (typeReg.schema.ast === innerToAst) {
435
- const result = ctx.typeRegistry.get(regTypeName);
436
- if (result) return result;
437
- }
438
- }
439
- }
440
- if (memberAst._tag === "TypeLiteral") {
441
- const valueField = memberAst.propertySignatures?.find(
442
- (p) => String(p.name) === "value"
443
- );
444
- if (valueField) {
445
- const valueType = valueField.type;
446
- const valueTypeName = ctx.astToTypeName?.get(valueType);
447
- if (valueTypeName) {
448
- const result = ctx.typeRegistry.get(valueTypeName);
449
- if (result) return result;
450
- }
451
- for (const [regTypeName, typeReg] of ctx.types) {
452
- if (typeReg.schema.ast === valueType) {
453
- const result = ctx.typeRegistry.get(regTypeName);
454
- if (result) return result;
455
- }
456
- let regAst = typeReg.schema.ast;
457
- while (regAst._tag === "Transformation") {
458
- regAst = regAst.to;
459
- if (regAst === valueType) {
460
- const result = ctx.typeRegistry.get(regTypeName);
461
- if (result) return result;
462
- }
463
- }
464
- }
465
- const innerResult = toGraphQLTypeWithRegistry(S2__namespace.make(valueType), ctx);
466
- if (innerResult) return innerResult;
467
- }
468
- }
469
- }
404
+ function findRegisteredTypeForAST(memberAst, ctx) {
405
+ const typeName = ctx.astToTypeName?.get(memberAst);
406
+ if (typeName) {
407
+ const result = ctx.typeRegistry.get(typeName);
408
+ if (result) return result;
409
+ }
410
+ for (const [regTypeName, typeReg] of ctx.types) {
411
+ if (typeReg.schema.ast === memberAst) {
412
+ const result = ctx.typeRegistry.get(regTypeName);
413
+ if (result) return result;
414
+ }
415
+ }
416
+ return void 0;
417
+ }
418
+ function findRegisteredTypeForTransformation(memberAst, ctx) {
419
+ if (memberAst._tag !== "Transformation") return void 0;
420
+ const innerToAst = memberAst.to;
421
+ const transformedTypeName = ctx.astToTypeName?.get(innerToAst);
422
+ if (transformedTypeName) {
423
+ const result = ctx.typeRegistry.get(transformedTypeName);
424
+ if (result) return result;
425
+ }
426
+ for (const [regTypeName, typeReg] of ctx.types) {
427
+ if (typeReg.schema.ast === innerToAst) {
428
+ const result = ctx.typeRegistry.get(regTypeName);
429
+ if (result) return result;
430
+ }
431
+ }
432
+ return void 0;
433
+ }
434
+ function findRegisteredTypeForOptionSome(memberAst, ctx) {
435
+ if (memberAst._tag !== "TypeLiteral") return void 0;
436
+ const valueField = memberAst.propertySignatures?.find(
437
+ (p) => String(p.name) === "value"
438
+ );
439
+ if (!valueField) return void 0;
440
+ const valueType = valueField.type;
441
+ const valueTypeName = ctx.astToTypeName?.get(valueType);
442
+ if (valueTypeName) {
443
+ const result = ctx.typeRegistry.get(valueTypeName);
444
+ if (result) return result;
445
+ }
446
+ for (const [regTypeName, typeReg] of ctx.types) {
447
+ if (typeReg.schema.ast === valueType) {
448
+ const result = ctx.typeRegistry.get(regTypeName);
449
+ if (result) return result;
470
450
  }
471
- const innerType = getOptionInnerType2(toAst);
472
- if (innerType) {
473
- return toGraphQLTypeWithRegistry(S2__namespace.make(innerType), ctx);
451
+ let regAst = typeReg.schema.ast;
452
+ while (regAst._tag === "Transformation") {
453
+ regAst = regAst.to;
454
+ if (regAst === valueType) {
455
+ const result = ctx.typeRegistry.get(regTypeName);
456
+ if (result) return result;
457
+ }
474
458
  }
475
459
  }
476
- if (toAst._tag === "TupleType") {
477
- if (toAst.rest && toAst.rest.length > 0) {
478
- const elementSchema = S2__namespace.make(toAst.rest[0].type);
479
- const elementType = toGraphQLTypeWithRegistry(elementSchema, ctx);
480
- return new graphql.GraphQLList(elementType);
481
- } else if (toAst.elements.length > 0) {
482
- const elementSchema = S2__namespace.make(toAst.elements[0].type);
483
- const elementType = toGraphQLTypeWithRegistry(elementSchema, ctx);
484
- return new graphql.GraphQLList(elementType);
460
+ const innerResult = toGraphQLTypeWithRegistry(S2__namespace.make(valueType), ctx);
461
+ return innerResult;
462
+ }
463
+ function handleOptionTransformation(ast, fromAst, toAst, ctx) {
464
+ if (fromAst && fromAst._tag === "Union") {
465
+ for (const memberAst of fromAst.types) {
466
+ if (memberAst._tag === "Literal") continue;
467
+ if (memberAst._tag === "UndefinedKeyword") continue;
468
+ const registeredType = findRegisteredTypeForAST(memberAst, ctx) || findRegisteredTypeForTransformation(memberAst, ctx) || findRegisteredTypeForOptionSome(memberAst, ctx);
469
+ if (registeredType) return registeredType;
485
470
  }
486
471
  }
472
+ const innerType = getOptionInnerType2(toAst);
473
+ if (innerType) {
474
+ return toGraphQLTypeWithRegistry(S2__namespace.make(innerType), ctx);
475
+ }
476
+ return void 0;
477
+ }
478
+ function handleArrayTransformation(toAst, ctx) {
479
+ if (toAst._tag !== "TupleType") return void 0;
480
+ let elementType;
481
+ if (toAst.rest && toAst.rest.length > 0) {
482
+ const elementSchema = S2__namespace.make(toAst.rest[0].type);
483
+ elementType = toGraphQLTypeWithRegistry(elementSchema, ctx);
484
+ } else if (toAst.elements.length > 0) {
485
+ const elementSchema = S2__namespace.make(toAst.elements[0].type);
486
+ elementType = toGraphQLTypeWithRegistry(elementSchema, ctx);
487
+ } else {
488
+ return void 0;
489
+ }
490
+ return new graphql.GraphQLList(elementType);
491
+ }
492
+ function handleTransformationAST(ast, ctx) {
493
+ const toAst = ast.to;
494
+ const fromAst = ast.from;
495
+ if (isOptionDeclaration2(toAst)) {
496
+ const optionResult = handleOptionTransformation(ast, fromAst, toAst, ctx);
497
+ if (optionResult) return optionResult;
498
+ }
499
+ const arrayResult = handleArrayTransformation(toAst, ctx);
500
+ if (arrayResult) return arrayResult;
487
501
  return toGraphQLTypeWithRegistry(S2__namespace.make(ast.to), ctx);
488
502
  }
503
+ function findRegisteredTypeInUnionMembers(types, ctx) {
504
+ for (const memberAst of types) {
505
+ const registeredType = findRegisteredTypeForAST(memberAst, ctx) || findRegisteredTypeForTransformation(memberAst, ctx) || findRegisteredTypeForOptionSome(memberAst, ctx);
506
+ if (registeredType) return registeredType;
507
+ }
508
+ return void 0;
509
+ }
489
510
  function handleUnionAST(ast, ctx) {
490
511
  const allLiterals = ast.types.every((t) => t._tag === "Literal");
491
512
  if (allLiterals) {
@@ -495,64 +516,8 @@ function handleUnionAST(ast, ctx) {
495
516
  const unionType2 = findRegisteredUnion(ast.types, ctx);
496
517
  if (unionType2) return unionType2;
497
518
  }
498
- for (const memberAst of ast.types) {
499
- const typeName = ctx.astToTypeName?.get(memberAst);
500
- if (typeName) {
501
- const result = ctx.typeRegistry.get(typeName);
502
- if (result) return result;
503
- }
504
- for (const [regTypeName, typeReg] of ctx.types) {
505
- if (typeReg.schema.ast === memberAst) {
506
- const result = ctx.typeRegistry.get(regTypeName);
507
- if (result) return result;
508
- }
509
- }
510
- if (memberAst._tag === "Transformation") {
511
- const toAst = memberAst.to;
512
- const transformedTypeName = ctx.astToTypeName?.get(toAst);
513
- if (transformedTypeName) {
514
- const result = ctx.typeRegistry.get(transformedTypeName);
515
- if (result) return result;
516
- }
517
- for (const [regTypeName, typeReg] of ctx.types) {
518
- if (typeReg.schema.ast === toAst) {
519
- const result = ctx.typeRegistry.get(regTypeName);
520
- if (result) return result;
521
- }
522
- }
523
- }
524
- if (memberAst._tag === "TypeLiteral") {
525
- const valueField = memberAst.propertySignatures?.find(
526
- (p) => String(p.name) === "value"
527
- );
528
- if (valueField) {
529
- const valueType = valueField.type;
530
- const valueTypeName = ctx.astToTypeName?.get(valueType);
531
- if (valueTypeName) {
532
- const result = ctx.typeRegistry.get(valueTypeName);
533
- if (result) return result;
534
- }
535
- for (const [regTypeName, typeReg] of ctx.types) {
536
- if (typeReg.schema.ast === valueType) {
537
- const result = ctx.typeRegistry.get(regTypeName);
538
- if (result) return result;
539
- }
540
- let regAst = typeReg.schema.ast;
541
- while (regAst._tag === "Transformation") {
542
- regAst = regAst.to;
543
- if (regAst === valueType) {
544
- const result = ctx.typeRegistry.get(regTypeName);
545
- if (result) return result;
546
- }
547
- }
548
- }
549
- const innerResult = toGraphQLTypeWithRegistry(S2__namespace.make(valueType), ctx);
550
- if (innerResult) {
551
- return innerResult;
552
- }
553
- }
554
- }
555
- }
519
+ const registeredType = findRegisteredTypeInUnionMembers(ast.types, ctx);
520
+ if (registeredType) return registeredType;
556
521
  if (ast.types.length > 0) {
557
522
  return toGraphQLTypeWithRegistry(S2__namespace.make(ast.types[0]), ctx);
558
523
  }
@@ -597,7 +562,7 @@ function findEnumForLiteral(ast, ctx) {
597
562
  }
598
563
  return void 0;
599
564
  }
600
- function handleTupleTypeAST(ast, ctx) {
565
+ function handleTupleTypeAST2(ast, ctx) {
601
566
  if (ast.rest && ast.rest.length > 0) {
602
567
  const elementSchema = S2__namespace.make(ast.rest[0].type);
603
568
  const elementType = toGraphQLTypeWithRegistry(elementSchema, ctx);
@@ -697,170 +662,40 @@ function buildInputTypeLookupCache(inputs, enums) {
697
662
  }
698
663
  return cache;
699
664
  }
700
- function toGraphQLInputTypeWithRegistry(schema, enumRegistry, inputRegistry, inputs, enums, cache) {
701
- const ast = schema.ast;
665
+ function findRegisteredInputType(schema, ast, inputs, inputRegistry, cache) {
702
666
  if (cache?.schemaToInputName || cache?.astToInputName) {
703
667
  const inputName = cache.schemaToInputName?.get(schema) ?? cache.astToInputName?.get(ast);
704
668
  if (inputName) {
705
- const result = inputRegistry.get(inputName);
706
- if (result) return result;
669
+ return inputRegistry.get(inputName);
707
670
  }
708
671
  } else {
709
672
  for (const [inputName, inputReg] of inputs) {
710
673
  if (inputReg.schema.ast === ast || inputReg.schema === schema) {
711
- const result = inputRegistry.get(inputName);
712
- if (result) return result;
674
+ return inputRegistry.get(inputName);
713
675
  }
714
676
  }
715
677
  }
716
- if (ast._tag === "Transformation") {
717
- const toAst = ast.to;
718
- const fromAst = ast.from;
719
- if (isOptionDeclaration2(toAst) && fromAst && fromAst._tag === "Union") {
720
- for (const memberAst of fromAst.types) {
721
- if (memberAst._tag === "Literal") continue;
722
- if (memberAst._tag === "UndefinedKeyword") continue;
723
- const inputName = cache?.astToInputName?.get(memberAst);
724
- if (inputName) {
725
- const inputReg = inputs.get(inputName);
726
- if (inputReg) {
727
- return toGraphQLInputTypeWithRegistry(
728
- inputReg.schema,
729
- enumRegistry,
730
- inputRegistry,
731
- inputs,
732
- enums,
733
- cache
734
- );
735
- }
736
- }
737
- for (const [, inputReg] of inputs) {
738
- if (inputReg.schema.ast === memberAst) {
739
- return toGraphQLInputTypeWithRegistry(
740
- inputReg.schema,
741
- enumRegistry,
742
- inputRegistry,
743
- inputs,
744
- enums,
745
- cache
746
- );
747
- }
748
- }
749
- if (memberAst._tag === "Transformation") {
750
- const innerToAst = memberAst.to;
751
- const transformedInputName = cache?.astToInputName?.get(innerToAst);
752
- if (transformedInputName) {
753
- const inputReg = inputs.get(transformedInputName);
754
- if (inputReg) {
755
- return toGraphQLInputTypeWithRegistry(
756
- inputReg.schema,
757
- enumRegistry,
758
- inputRegistry,
759
- inputs,
760
- enums,
761
- cache
762
- );
763
- }
764
- }
765
- for (const [, inputReg] of inputs) {
766
- if (inputReg.schema.ast === innerToAst) {
767
- return toGraphQLInputTypeWithRegistry(
768
- inputReg.schema,
769
- enumRegistry,
770
- inputRegistry,
771
- inputs,
772
- enums,
773
- cache
774
- );
775
- }
776
- }
777
- }
778
- if (memberAst._tag === "TypeLiteral") {
779
- const valueField = memberAst.propertySignatures?.find(
780
- (p) => String(p.name) === "value"
781
- );
782
- if (valueField) {
783
- const valueType = valueField.type;
784
- const valueInputName = cache?.astToInputName?.get(valueType);
785
- if (valueInputName) {
786
- const inputReg = inputs.get(valueInputName);
787
- if (inputReg) {
788
- return toGraphQLInputTypeWithRegistry(
789
- inputReg.schema,
790
- enumRegistry,
791
- inputRegistry,
792
- inputs,
793
- enums,
794
- cache
795
- );
796
- }
797
- }
798
- for (const [, inputReg] of inputs) {
799
- if (inputReg.schema.ast === valueType) {
800
- return toGraphQLInputTypeWithRegistry(
801
- inputReg.schema,
802
- enumRegistry,
803
- inputRegistry,
804
- inputs,
805
- enums,
806
- cache
807
- );
808
- }
809
- let regAst = inputReg.schema.ast;
810
- while (regAst._tag === "Transformation") {
811
- regAst = regAst.to;
812
- if (regAst === valueType) {
813
- return toGraphQLInputTypeWithRegistry(
814
- inputReg.schema,
815
- enumRegistry,
816
- inputRegistry,
817
- inputs,
818
- enums,
819
- cache
820
- );
821
- }
822
- }
823
- if (regAst._tag === "Declaration" && regAst.typeParameters?.[0] === valueType) {
824
- return toGraphQLInputTypeWithRegistry(
825
- inputReg.schema,
826
- enumRegistry,
827
- inputRegistry,
828
- inputs,
829
- enums,
830
- cache
831
- );
832
- }
833
- }
834
- const innerResult = toGraphQLInputTypeWithRegistry(
835
- S2__namespace.make(valueType),
836
- enumRegistry,
837
- inputRegistry,
838
- inputs,
839
- enums,
840
- cache
841
- );
842
- if (innerResult) {
843
- return innerResult;
844
- }
845
- }
846
- }
847
- }
678
+ return void 0;
679
+ }
680
+ function findRegisteredInputForAST(memberAst, inputs, inputRegistry, enumRegistry, enums, cache) {
681
+ const inputName = cache?.astToInputName?.get(memberAst);
682
+ if (inputName) {
683
+ const inputReg = inputs.get(inputName);
684
+ if (inputReg) {
685
+ return toGraphQLInputTypeWithRegistry(
686
+ inputReg.schema,
687
+ enumRegistry,
688
+ inputRegistry,
689
+ inputs,
690
+ enums,
691
+ cache
692
+ );
848
693
  }
849
- return toGraphQLInputTypeWithRegistry(
850
- S2__namespace.make(toAst),
851
- enumRegistry,
852
- inputRegistry,
853
- inputs,
854
- enums,
855
- cache
856
- );
857
694
  }
858
- if (ast._tag === "Union") {
859
- const unionAst = ast;
860
- const nonUndefinedTypes = unionAst.types.filter((t) => t._tag !== "UndefinedKeyword");
861
- if (nonUndefinedTypes.length === 1 && nonUndefinedTypes[0]._tag === "Union") {
695
+ for (const [, inputReg] of inputs) {
696
+ if (inputReg.schema.ast === memberAst) {
862
697
  return toGraphQLInputTypeWithRegistry(
863
- S2__namespace.make(nonUndefinedTypes[0]),
698
+ inputReg.schema,
864
699
  enumRegistry,
865
700
  inputRegistry,
866
701
  inputs,
@@ -868,9 +703,18 @@ function toGraphQLInputTypeWithRegistry(schema, enumRegistry, inputRegistry, inp
868
703
  cache
869
704
  );
870
705
  }
871
- if (nonUndefinedTypes.length === 1 && nonUndefinedTypes[0]._tag === "TypeLiteral") {
706
+ }
707
+ return void 0;
708
+ }
709
+ function findRegisteredInputForTransformation(memberAst, inputs, inputRegistry, enumRegistry, enums, cache) {
710
+ if (memberAst._tag !== "Transformation") return void 0;
711
+ const innerToAst = memberAst.to;
712
+ const transformedInputName = cache?.astToInputName?.get(innerToAst);
713
+ if (transformedInputName) {
714
+ const inputReg = inputs.get(transformedInputName);
715
+ if (inputReg) {
872
716
  return toGraphQLInputTypeWithRegistry(
873
- S2__namespace.make(nonUndefinedTypes[0]),
717
+ inputReg.schema,
874
718
  enumRegistry,
875
719
  inputRegistry,
876
720
  inputs,
@@ -878,171 +722,210 @@ function toGraphQLInputTypeWithRegistry(schema, enumRegistry, inputRegistry, inp
878
722
  cache
879
723
  );
880
724
  }
881
- for (const memberAst of unionAst.types) {
882
- const inputName = cache?.astToInputName?.get(memberAst);
883
- if (inputName) {
884
- const inputReg = inputs.get(inputName);
885
- if (inputReg) {
886
- return toGraphQLInputTypeWithRegistry(
887
- inputReg.schema,
888
- enumRegistry,
889
- inputRegistry,
890
- inputs,
891
- enums,
892
- cache
893
- );
894
- }
895
- }
896
- for (const [, inputReg] of inputs) {
897
- if (inputReg.schema.ast === memberAst) {
898
- return toGraphQLInputTypeWithRegistry(
899
- inputReg.schema,
900
- enumRegistry,
901
- inputRegistry,
902
- inputs,
903
- enums,
904
- cache
905
- );
906
- }
907
- }
908
- if (memberAst._tag === "Transformation") {
909
- const toAst = memberAst.to;
910
- const transformedInputName = cache?.astToInputName?.get(toAst);
911
- if (transformedInputName) {
912
- const inputReg = inputs.get(transformedInputName);
913
- if (inputReg) {
914
- return toGraphQLInputTypeWithRegistry(
915
- inputReg.schema,
916
- enumRegistry,
917
- inputRegistry,
918
- inputs,
919
- enums,
920
- cache
921
- );
922
- }
923
- }
924
- for (const [, inputReg] of inputs) {
925
- if (inputReg.schema.ast === toAst) {
926
- return toGraphQLInputTypeWithRegistry(
927
- inputReg.schema,
928
- enumRegistry,
929
- inputRegistry,
930
- inputs,
931
- enums,
932
- cache
933
- );
934
- }
935
- }
936
- }
937
- if (memberAst._tag === "TypeLiteral") {
938
- const valueField = memberAst.propertySignatures?.find(
939
- (p) => String(p.name) === "value"
725
+ }
726
+ for (const [, inputReg] of inputs) {
727
+ if (inputReg.schema.ast === innerToAst) {
728
+ return toGraphQLInputTypeWithRegistry(
729
+ inputReg.schema,
730
+ enumRegistry,
731
+ inputRegistry,
732
+ inputs,
733
+ enums,
734
+ cache
735
+ );
736
+ }
737
+ }
738
+ return void 0;
739
+ }
740
+ function findRegisteredInputForOptionSome(memberAst, inputs, inputRegistry, enumRegistry, enums, cache) {
741
+ if (memberAst._tag !== "TypeLiteral") return void 0;
742
+ const valueField = memberAst.propertySignatures?.find(
743
+ (p) => String(p.name) === "value"
744
+ );
745
+ if (!valueField) return void 0;
746
+ const valueType = valueField.type;
747
+ const valueInputName = cache?.astToInputName?.get(valueType);
748
+ if (valueInputName) {
749
+ const inputReg = inputs.get(valueInputName);
750
+ if (inputReg) {
751
+ return toGraphQLInputTypeWithRegistry(
752
+ inputReg.schema,
753
+ enumRegistry,
754
+ inputRegistry,
755
+ inputs,
756
+ enums,
757
+ cache
758
+ );
759
+ }
760
+ }
761
+ for (const [, inputReg] of inputs) {
762
+ if (inputReg.schema.ast === valueType) {
763
+ return toGraphQLInputTypeWithRegistry(
764
+ inputReg.schema,
765
+ enumRegistry,
766
+ inputRegistry,
767
+ inputs,
768
+ enums,
769
+ cache
770
+ );
771
+ }
772
+ let regAst = inputReg.schema.ast;
773
+ while (regAst._tag === "Transformation") {
774
+ regAst = regAst.to;
775
+ if (regAst === valueType) {
776
+ return toGraphQLInputTypeWithRegistry(
777
+ inputReg.schema,
778
+ enumRegistry,
779
+ inputRegistry,
780
+ inputs,
781
+ enums,
782
+ cache
940
783
  );
941
- if (valueField) {
942
- const valueType = valueField.type;
943
- const valueInputName = cache?.astToInputName?.get(valueType);
944
- if (valueInputName) {
945
- const inputReg = inputs.get(valueInputName);
946
- if (inputReg) {
947
- return toGraphQLInputTypeWithRegistry(
948
- inputReg.schema,
949
- enumRegistry,
950
- inputRegistry,
951
- inputs,
952
- enums,
953
- cache
954
- );
955
- }
956
- }
957
- for (const [, inputReg] of inputs) {
958
- if (inputReg.schema.ast === valueType) {
959
- return toGraphQLInputTypeWithRegistry(
960
- inputReg.schema,
961
- enumRegistry,
962
- inputRegistry,
963
- inputs,
964
- enums,
965
- cache
966
- );
967
- }
968
- let regAst = inputReg.schema.ast;
969
- while (regAst._tag === "Transformation") {
970
- regAst = regAst.to;
971
- if (regAst === valueType) {
972
- return toGraphQLInputTypeWithRegistry(
973
- inputReg.schema,
974
- enumRegistry,
975
- inputRegistry,
976
- inputs,
977
- enums,
978
- cache
979
- );
980
- }
981
- }
982
- if (regAst._tag === "Declaration" && regAst.typeParameters?.[0] === valueType) {
983
- return toGraphQLInputTypeWithRegistry(
984
- inputReg.schema,
985
- enumRegistry,
986
- inputRegistry,
987
- inputs,
988
- enums,
989
- cache
990
- );
991
- }
992
- }
993
- const innerResult = toGraphQLInputTypeWithRegistry(
994
- S2__namespace.make(valueType),
995
- enumRegistry,
996
- inputRegistry,
997
- inputs,
998
- enums,
999
- cache
1000
- );
1001
- if (innerResult) {
1002
- return innerResult;
1003
- }
1004
- }
1005
784
  }
1006
785
  }
1007
- const allLiterals = unionAst.types.every((t) => t._tag === "Literal");
1008
- if (allLiterals) {
1009
- const literalValues = unionAst.types.map((t) => String(t.literal)).sort();
1010
- for (const [enumName] of enums) {
1011
- const enumValues = cache?.enumSortedValues?.get(enumName) ?? [...enums.get(enumName).values].sort();
1012
- if (literalValues.length === enumValues.length && literalValues.every((v, i) => v === enumValues[i])) {
1013
- const result = enumRegistry.get(enumName);
1014
- if (result) return result;
1015
- }
1016
- }
786
+ if (regAst._tag === "Declaration" && regAst.typeParameters?.[0] === valueType) {
787
+ return toGraphQLInputTypeWithRegistry(
788
+ inputReg.schema,
789
+ enumRegistry,
790
+ inputRegistry,
791
+ inputs,
792
+ enums,
793
+ cache
794
+ );
1017
795
  }
1018
796
  }
1019
- if (ast._tag === "Literal") {
1020
- const literalValue = String(ast.literal);
1021
- if (cache?.literalToEnumName) {
1022
- const enumName = cache.literalToEnumName.get(literalValue);
1023
- if (enumName) {
797
+ const innerResult = toGraphQLInputTypeWithRegistry(
798
+ S2__namespace.make(valueType),
799
+ enumRegistry,
800
+ inputRegistry,
801
+ inputs,
802
+ enums,
803
+ cache
804
+ );
805
+ return innerResult || void 0;
806
+ }
807
+ function handleOptionTransformationForInput(fromAst, toAst, inputs, inputRegistry, enumRegistry, enums, cache) {
808
+ if (!fromAst || fromAst._tag !== "Union") return void 0;
809
+ for (const memberAst of fromAst.types) {
810
+ if (memberAst._tag === "Literal") continue;
811
+ if (memberAst._tag === "UndefinedKeyword") continue;
812
+ const registeredInput = findRegisteredInputForAST(memberAst, inputs, inputRegistry, enumRegistry, enums, cache) || findRegisteredInputForTransformation(memberAst, inputs, inputRegistry, enumRegistry, enums, cache) || findRegisteredInputForOptionSome(memberAst, inputs, inputRegistry, enumRegistry, enums, cache);
813
+ if (registeredInput) return registeredInput;
814
+ }
815
+ return void 0;
816
+ }
817
+ function handleTransformationForInput(ast, inputs, inputRegistry, enumRegistry, enums, cache) {
818
+ const toAst = ast.to;
819
+ const fromAst = ast.from;
820
+ if (isOptionDeclaration2(toAst)) {
821
+ const optionResult = handleOptionTransformationForInput(
822
+ fromAst,
823
+ toAst,
824
+ inputs,
825
+ inputRegistry,
826
+ enumRegistry,
827
+ enums,
828
+ cache
829
+ );
830
+ if (optionResult) return optionResult;
831
+ }
832
+ return toGraphQLInputTypeWithRegistry(
833
+ S2__namespace.make(toAst),
834
+ enumRegistry,
835
+ inputRegistry,
836
+ inputs,
837
+ enums,
838
+ cache
839
+ );
840
+ }
841
+ function findRegisteredInputInUnionMembers(types, inputs, inputRegistry, enumRegistry, enums, cache) {
842
+ for (const memberAst of types) {
843
+ const registeredInput = findRegisteredInputForAST(memberAst, inputs, inputRegistry, enumRegistry, enums, cache) || findRegisteredInputForTransformation(memberAst, inputs, inputRegistry, enumRegistry, enums, cache) || findRegisteredInputForOptionSome(memberAst, inputs, inputRegistry, enumRegistry, enums, cache);
844
+ if (registeredInput) return registeredInput;
845
+ }
846
+ return void 0;
847
+ }
848
+ function handleUnionForInput(ast, inputs, inputRegistry, enumRegistry, enums, cache) {
849
+ const unionAst = ast;
850
+ const nonUndefinedTypes = unionAst.types.filter((t) => t._tag !== "UndefinedKeyword");
851
+ if (nonUndefinedTypes.length === 1) {
852
+ if (nonUndefinedTypes[0]._tag === "Union" || nonUndefinedTypes[0]._tag === "TypeLiteral") {
853
+ return toGraphQLInputTypeWithRegistry(
854
+ S2__namespace.make(nonUndefinedTypes[0]),
855
+ enumRegistry,
856
+ inputRegistry,
857
+ inputs,
858
+ enums,
859
+ cache
860
+ );
861
+ }
862
+ }
863
+ const registeredInput = findRegisteredInputInUnionMembers(
864
+ unionAst.types,
865
+ inputs,
866
+ inputRegistry,
867
+ enumRegistry,
868
+ enums,
869
+ cache
870
+ );
871
+ if (registeredInput) return registeredInput;
872
+ const allLiterals = unionAst.types.every((t) => t._tag === "Literal");
873
+ if (allLiterals) {
874
+ const literalValues = unionAst.types.map((t) => String(t.literal)).sort();
875
+ for (const [enumName] of enums) {
876
+ const enumValues = cache?.enumSortedValues?.get(enumName) ?? [...enums.get(enumName).values].sort();
877
+ if (literalValues.length === enumValues.length && literalValues.every((v, i) => v === enumValues[i])) {
1024
878
  const result = enumRegistry.get(enumName);
1025
879
  if (result) return result;
1026
880
  }
1027
- } else {
1028
- for (const [enumName, enumReg] of enums) {
1029
- if (enumReg.values.includes(literalValue)) {
1030
- const result = enumRegistry.get(enumName);
1031
- if (result) return result;
1032
- }
881
+ }
882
+ }
883
+ return void 0;
884
+ }
885
+ function handleLiteralForInput(ast, enumRegistry, enums, cache) {
886
+ const literalValue = String(ast.literal);
887
+ if (cache?.literalToEnumName) {
888
+ const enumName = cache.literalToEnumName.get(literalValue);
889
+ if (enumName) {
890
+ return enumRegistry.get(enumName);
891
+ }
892
+ } else {
893
+ for (const [enumName, enumReg] of enums) {
894
+ if (enumReg.values.includes(literalValue)) {
895
+ return enumRegistry.get(enumName);
1033
896
  }
1034
897
  }
1035
898
  }
899
+ return void 0;
900
+ }
901
+ function handleSuspendForInput(ast, inputs, inputRegistry, enumRegistry, enums, cache) {
902
+ const innerAst = ast.f();
903
+ return toGraphQLInputTypeWithRegistry(
904
+ S2__namespace.make(innerAst),
905
+ enumRegistry,
906
+ inputRegistry,
907
+ inputs,
908
+ enums,
909
+ cache
910
+ );
911
+ }
912
+ function toGraphQLInputTypeWithRegistry(schema, enumRegistry, inputRegistry, inputs, enums, cache) {
913
+ const ast = schema.ast;
914
+ const registeredInput = findRegisteredInputType(schema, ast, inputs, inputRegistry, cache);
915
+ if (registeredInput) return registeredInput;
916
+ if (ast._tag === "Transformation") {
917
+ return handleTransformationForInput(ast, inputs, inputRegistry, enumRegistry, enums, cache);
918
+ }
919
+ if (ast._tag === "Union") {
920
+ const unionResult = handleUnionForInput(ast, inputs, inputRegistry, enumRegistry, enums, cache);
921
+ if (unionResult) return unionResult;
922
+ }
923
+ if (ast._tag === "Literal") {
924
+ const literalResult = handleLiteralForInput(ast, enumRegistry, enums, cache);
925
+ if (literalResult) return literalResult;
926
+ }
1036
927
  if (ast._tag === "Suspend") {
1037
- const innerAst = ast.f();
1038
- return toGraphQLInputTypeWithRegistry(
1039
- S2__namespace.make(innerAst),
1040
- enumRegistry,
1041
- inputRegistry,
1042
- inputs,
1043
- enums,
1044
- cache
1045
- );
928
+ return handleSuspendForInput(ast, inputs, inputRegistry, enumRegistry, enums, cache);
1046
929
  }
1047
930
  return toGraphQLInputType(schema);
1048
931
  }