@effect-gql/core 1.4.8 → 1.4.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/builder/index.cjs CHANGED
@@ -49,6 +49,51 @@ var isIntegerType = (ast) => {
49
49
  }
50
50
  return false;
51
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
+ }
52
97
  var isOptionDeclaration = (ast) => {
53
98
  if (ast._tag === "Declaration") {
54
99
  const annotations = ast.annotations;
@@ -79,42 +124,17 @@ var getOptionInnerType = (ast) => {
79
124
  };
80
125
  var toGraphQLType = (schema) => {
81
126
  const ast = schema.ast;
82
- if (ast._tag === "StringKeyword") return graphql.GraphQLString;
83
- if (ast._tag === "NumberKeyword") return graphql.GraphQLFloat;
84
- if (ast._tag === "BooleanKeyword") return graphql.GraphQLBoolean;
127
+ const primitiveResult = handlePrimitiveAST(ast);
128
+ if (primitiveResult) return primitiveResult;
85
129
  if (ast._tag === "Refinement") {
86
- if (isIntegerType(ast)) {
87
- return graphql.GraphQLInt;
88
- }
89
- return toGraphQLType(S2__namespace.make(ast.from));
90
- }
91
- if (ast._tag === "Literal") {
92
- if (typeof ast.literal === "string") return graphql.GraphQLString;
93
- if (typeof ast.literal === "number") {
94
- return Number.isInteger(ast.literal) ? graphql.GraphQLInt : graphql.GraphQLFloat;
95
- }
96
- if (typeof ast.literal === "boolean") return graphql.GraphQLBoolean;
97
- }
98
- if (ast._tag === "TupleType") {
99
- const elements = ast.elements;
100
- if (elements.length > 0) {
101
- const elementSchema = S2__namespace.make(elements[0].type);
102
- return new graphql.GraphQLList(toGraphQLType(elementSchema));
103
- }
130
+ return handleRefinementAST(ast, toGraphQLType);
104
131
  }
132
+ const literalResult = handleLiteralAST(ast);
133
+ if (literalResult) return literalResult;
134
+ const tupleResult = handleTupleTypeAST(ast, toGraphQLType);
135
+ if (tupleResult) return tupleResult;
105
136
  if (ast._tag === "TypeLiteral") {
106
- const fields = {};
107
- for (const field2 of ast.propertySignatures) {
108
- const fieldName = String(field2.name);
109
- if (fieldName === "_tag") continue;
110
- const fieldSchema = S2__namespace.make(field2.type);
111
- let fieldType = toGraphQLType(fieldSchema);
112
- const isOptionField = isOptionTransformation(field2.type) || isOptionDeclaration(field2.type);
113
- if (!field2.isOptional && !isOptionField) {
114
- fieldType = new graphql.GraphQLNonNull(fieldType);
115
- }
116
- fields[fieldName] = { type: fieldType };
117
- }
137
+ const fields = buildFieldsFromPropertySignatures(ast.propertySignatures, toGraphQLType);
118
138
  const typeName = schema.annotations?.identifier || `Object_${Math.random().toString(36).slice(2, 11)}`;
119
139
  return new graphql.GraphQLObjectType({
120
140
  name: typeName,
@@ -156,42 +176,19 @@ var toGraphQLType = (schema) => {
156
176
  };
157
177
  var toGraphQLInputType = (schema) => {
158
178
  const ast = schema.ast;
159
- if (ast._tag === "StringKeyword") return graphql.GraphQLString;
160
- if (ast._tag === "NumberKeyword") return graphql.GraphQLFloat;
161
- if (ast._tag === "BooleanKeyword") return graphql.GraphQLBoolean;
179
+ const primitiveResult = handlePrimitiveAST(ast);
180
+ if (primitiveResult) return primitiveResult;
162
181
  if (ast._tag === "Refinement") {
163
- if (isIntegerType(ast)) {
164
- return graphql.GraphQLInt;
165
- }
166
- return toGraphQLInputType(S2__namespace.make(ast.from));
167
- }
168
- if (ast._tag === "Literal") {
169
- if (typeof ast.literal === "string") return graphql.GraphQLString;
170
- if (typeof ast.literal === "number") {
171
- return Number.isInteger(ast.literal) ? graphql.GraphQLInt : graphql.GraphQLFloat;
172
- }
173
- if (typeof ast.literal === "boolean") return graphql.GraphQLBoolean;
174
- }
175
- if (ast._tag === "TupleType") {
176
- const elements = ast.elements;
177
- if (elements.length > 0) {
178
- const elementSchema = S2__namespace.make(elements[0].type);
179
- return new graphql.GraphQLList(toGraphQLInputType(elementSchema));
180
- }
182
+ return handleRefinementAST(ast, toGraphQLInputType);
181
183
  }
184
+ const literalResult = handleLiteralAST(ast);
185
+ if (literalResult) return literalResult;
186
+ const tupleResult = handleTupleTypeAST(ast, toGraphQLInputType);
187
+ if (tupleResult) return tupleResult;
182
188
  if (ast._tag === "TypeLiteral") {
183
- const fields = {};
184
- for (const field2 of ast.propertySignatures) {
185
- const fieldName = String(field2.name);
186
- if (fieldName === "_tag") continue;
187
- const fieldSchema = S2__namespace.make(field2.type);
188
- let fieldType = toGraphQLInputType(fieldSchema);
189
- const isOptionField = isOptionTransformation(field2.type) || isOptionDeclaration(field2.type);
190
- if (!field2.isOptional && !isOptionField) {
191
- fieldType = new graphql.GraphQLNonNull(fieldType);
192
- }
193
- fields[fieldName] = { type: fieldType };
194
- }
189
+ const fields = buildFieldsFromPropertySignatures(
190
+ ast.propertySignatures,
191
+ toGraphQLInputType);
195
192
  const typeName = schema.annotations?.identifier || `Input_${Math.random().toString(36).slice(2, 11)}`;
196
193
  return new graphql.GraphQLInputObjectType({
197
194
  name: typeName,
@@ -232,18 +229,7 @@ var toGraphQLInputType = (schema) => {
232
229
  var toGraphQLArgs = (schema) => {
233
230
  const ast = schema.ast;
234
231
  if (ast._tag === "TypeLiteral") {
235
- const args = {};
236
- for (const field2 of ast.propertySignatures) {
237
- const fieldName = String(field2.name);
238
- if (fieldName === "_tag") continue;
239
- const fieldSchema = S2__namespace.make(field2.type);
240
- let fieldType = toGraphQLInputType(fieldSchema);
241
- const isOptionField = isOptionTransformation(field2.type) || isOptionDeclaration(field2.type);
242
- if (!field2.isOptional && !isOptionField) {
243
- fieldType = new graphql.GraphQLNonNull(fieldType);
244
- }
245
- args[fieldName] = { type: fieldType };
246
- }
232
+ const args = buildFieldsFromPropertySignatures(ast.propertySignatures, toGraphQLInputType);
247
233
  return args;
248
234
  }
249
235
  throw new Error(`Schema must be an object type to convert to GraphQL arguments`);
@@ -359,7 +345,7 @@ function toGraphQLTypeWithRegistry(schema, ctx) {
359
345
  if (enumType2) return enumType2;
360
346
  }
361
347
  if (ast._tag === "TupleType") {
362
- return handleTupleTypeAST(ast, ctx);
348
+ return handleTupleTypeAST2(ast, ctx);
363
349
  }
364
350
  if (ast._tag === "Declaration") {
365
351
  if (isOptionDeclaration2(ast)) {
@@ -415,88 +401,112 @@ function getOptionInnerType2(ast) {
415
401
  }
416
402
  return void 0;
417
403
  }
418
- function handleTransformationAST(ast, ctx) {
419
- const toAst = ast.to;
420
- const fromAst = ast.from;
421
- if (isOptionDeclaration2(toAst)) {
422
- if (fromAst && fromAst._tag === "Union") {
423
- for (const memberAst of fromAst.types) {
424
- if (memberAst._tag === "Literal") continue;
425
- if (memberAst._tag === "UndefinedKeyword") continue;
426
- const typeName = ctx.astToTypeName?.get(memberAst);
427
- if (typeName) {
428
- const result = ctx.typeRegistry.get(typeName);
429
- if (result) return result;
430
- }
431
- for (const [regTypeName, typeReg] of ctx.types) {
432
- if (typeReg.schema.ast === memberAst) {
433
- const result = ctx.typeRegistry.get(regTypeName);
434
- if (result) return result;
435
- }
436
- }
437
- if (memberAst._tag === "Transformation") {
438
- const innerToAst = memberAst.to;
439
- const transformedTypeName = ctx.astToTypeName?.get(innerToAst);
440
- if (transformedTypeName) {
441
- const result = ctx.typeRegistry.get(transformedTypeName);
442
- if (result) return result;
443
- }
444
- for (const [regTypeName, typeReg] of ctx.types) {
445
- if (typeReg.schema.ast === innerToAst) {
446
- const result = ctx.typeRegistry.get(regTypeName);
447
- if (result) return result;
448
- }
449
- }
450
- }
451
- if (memberAst._tag === "TypeLiteral") {
452
- const valueField = memberAst.propertySignatures?.find(
453
- (p) => String(p.name) === "value"
454
- );
455
- if (valueField) {
456
- const valueType = valueField.type;
457
- const valueTypeName = ctx.astToTypeName?.get(valueType);
458
- if (valueTypeName) {
459
- const result = ctx.typeRegistry.get(valueTypeName);
460
- if (result) return result;
461
- }
462
- for (const [regTypeName, typeReg] of ctx.types) {
463
- if (typeReg.schema.ast === valueType) {
464
- const result = ctx.typeRegistry.get(regTypeName);
465
- if (result) return result;
466
- }
467
- let regAst = typeReg.schema.ast;
468
- while (regAst._tag === "Transformation") {
469
- regAst = regAst.to;
470
- if (regAst === valueType) {
471
- const result = ctx.typeRegistry.get(regTypeName);
472
- if (result) return result;
473
- }
474
- }
475
- }
476
- const innerResult = toGraphQLTypeWithRegistry(S2__namespace.make(valueType), ctx);
477
- if (innerResult) return innerResult;
478
- }
479
- }
480
- }
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;
481
414
  }
482
- const innerType = getOptionInnerType2(toAst);
483
- if (innerType) {
484
- return toGraphQLTypeWithRegistry(S2__namespace.make(innerType), ctx);
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;
485
430
  }
486
431
  }
487
- if (toAst._tag === "TupleType") {
488
- if (toAst.rest && toAst.rest.length > 0) {
489
- const elementSchema = S2__namespace.make(toAst.rest[0].type);
490
- const elementType = toGraphQLTypeWithRegistry(elementSchema, ctx);
491
- return new graphql.GraphQLList(elementType);
492
- } else if (toAst.elements.length > 0) {
493
- const elementSchema = S2__namespace.make(toAst.elements[0].type);
494
- const elementType = toGraphQLTypeWithRegistry(elementSchema, ctx);
495
- return new graphql.GraphQLList(elementType);
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;
450
+ }
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
+ }
458
+ }
459
+ }
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;
496
470
  }
497
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;
498
501
  return toGraphQLTypeWithRegistry(S2__namespace.make(ast.to), ctx);
499
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
+ }
500
510
  function handleUnionAST(ast, ctx) {
501
511
  const allLiterals = ast.types.every((t) => t._tag === "Literal");
502
512
  if (allLiterals) {
@@ -506,64 +516,8 @@ function handleUnionAST(ast, ctx) {
506
516
  const unionType2 = findRegisteredUnion(ast.types, ctx);
507
517
  if (unionType2) return unionType2;
508
518
  }
509
- for (const memberAst of ast.types) {
510
- const typeName = ctx.astToTypeName?.get(memberAst);
511
- if (typeName) {
512
- const result = ctx.typeRegistry.get(typeName);
513
- if (result) return result;
514
- }
515
- for (const [regTypeName, typeReg] of ctx.types) {
516
- if (typeReg.schema.ast === memberAst) {
517
- const result = ctx.typeRegistry.get(regTypeName);
518
- if (result) return result;
519
- }
520
- }
521
- if (memberAst._tag === "Transformation") {
522
- const toAst = memberAst.to;
523
- const transformedTypeName = ctx.astToTypeName?.get(toAst);
524
- if (transformedTypeName) {
525
- const result = ctx.typeRegistry.get(transformedTypeName);
526
- if (result) return result;
527
- }
528
- for (const [regTypeName, typeReg] of ctx.types) {
529
- if (typeReg.schema.ast === toAst) {
530
- const result = ctx.typeRegistry.get(regTypeName);
531
- if (result) return result;
532
- }
533
- }
534
- }
535
- if (memberAst._tag === "TypeLiteral") {
536
- const valueField = memberAst.propertySignatures?.find(
537
- (p) => String(p.name) === "value"
538
- );
539
- if (valueField) {
540
- const valueType = valueField.type;
541
- const valueTypeName = ctx.astToTypeName?.get(valueType);
542
- if (valueTypeName) {
543
- const result = ctx.typeRegistry.get(valueTypeName);
544
- if (result) return result;
545
- }
546
- for (const [regTypeName, typeReg] of ctx.types) {
547
- if (typeReg.schema.ast === valueType) {
548
- const result = ctx.typeRegistry.get(regTypeName);
549
- if (result) return result;
550
- }
551
- let regAst = typeReg.schema.ast;
552
- while (regAst._tag === "Transformation") {
553
- regAst = regAst.to;
554
- if (regAst === valueType) {
555
- const result = ctx.typeRegistry.get(regTypeName);
556
- if (result) return result;
557
- }
558
- }
559
- }
560
- const innerResult = toGraphQLTypeWithRegistry(S2__namespace.make(valueType), ctx);
561
- if (innerResult) {
562
- return innerResult;
563
- }
564
- }
565
- }
566
- }
519
+ const registeredType = findRegisteredTypeInUnionMembers(ast.types, ctx);
520
+ if (registeredType) return registeredType;
567
521
  if (ast.types.length > 0) {
568
522
  return toGraphQLTypeWithRegistry(S2__namespace.make(ast.types[0]), ctx);
569
523
  }
@@ -608,7 +562,7 @@ function findEnumForLiteral(ast, ctx) {
608
562
  }
609
563
  return void 0;
610
564
  }
611
- function handleTupleTypeAST(ast, ctx) {
565
+ function handleTupleTypeAST2(ast, ctx) {
612
566
  if (ast.rest && ast.rest.length > 0) {
613
567
  const elementSchema = S2__namespace.make(ast.rest[0].type);
614
568
  const elementType = toGraphQLTypeWithRegistry(elementSchema, ctx);
@@ -708,170 +662,40 @@ function buildInputTypeLookupCache(inputs, enums) {
708
662
  }
709
663
  return cache;
710
664
  }
711
- function toGraphQLInputTypeWithRegistry(schema, enumRegistry, inputRegistry, inputs, enums, cache) {
712
- const ast = schema.ast;
665
+ function findRegisteredInputType(schema, ast, inputs, inputRegistry, cache) {
713
666
  if (cache?.schemaToInputName || cache?.astToInputName) {
714
667
  const inputName = cache.schemaToInputName?.get(schema) ?? cache.astToInputName?.get(ast);
715
668
  if (inputName) {
716
- const result = inputRegistry.get(inputName);
717
- if (result) return result;
669
+ return inputRegistry.get(inputName);
718
670
  }
719
671
  } else {
720
672
  for (const [inputName, inputReg] of inputs) {
721
673
  if (inputReg.schema.ast === ast || inputReg.schema === schema) {
722
- const result = inputRegistry.get(inputName);
723
- if (result) return result;
674
+ return inputRegistry.get(inputName);
724
675
  }
725
676
  }
726
677
  }
727
- if (ast._tag === "Transformation") {
728
- const toAst = ast.to;
729
- const fromAst = ast.from;
730
- if (isOptionDeclaration2(toAst) && fromAst && fromAst._tag === "Union") {
731
- for (const memberAst of fromAst.types) {
732
- if (memberAst._tag === "Literal") continue;
733
- if (memberAst._tag === "UndefinedKeyword") continue;
734
- const inputName = cache?.astToInputName?.get(memberAst);
735
- if (inputName) {
736
- const inputReg = inputs.get(inputName);
737
- if (inputReg) {
738
- return toGraphQLInputTypeWithRegistry(
739
- inputReg.schema,
740
- enumRegistry,
741
- inputRegistry,
742
- inputs,
743
- enums,
744
- cache
745
- );
746
- }
747
- }
748
- for (const [, inputReg] of inputs) {
749
- if (inputReg.schema.ast === memberAst) {
750
- return toGraphQLInputTypeWithRegistry(
751
- inputReg.schema,
752
- enumRegistry,
753
- inputRegistry,
754
- inputs,
755
- enums,
756
- cache
757
- );
758
- }
759
- }
760
- if (memberAst._tag === "Transformation") {
761
- const innerToAst = memberAst.to;
762
- const transformedInputName = cache?.astToInputName?.get(innerToAst);
763
- if (transformedInputName) {
764
- const inputReg = inputs.get(transformedInputName);
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 === innerToAst) {
778
- return toGraphQLInputTypeWithRegistry(
779
- inputReg.schema,
780
- enumRegistry,
781
- inputRegistry,
782
- inputs,
783
- enums,
784
- cache
785
- );
786
- }
787
- }
788
- }
789
- if (memberAst._tag === "TypeLiteral") {
790
- const valueField = memberAst.propertySignatures?.find(
791
- (p) => String(p.name) === "value"
792
- );
793
- if (valueField) {
794
- const valueType = valueField.type;
795
- const valueInputName = cache?.astToInputName?.get(valueType);
796
- if (valueInputName) {
797
- const inputReg = inputs.get(valueInputName);
798
- if (inputReg) {
799
- return toGraphQLInputTypeWithRegistry(
800
- inputReg.schema,
801
- enumRegistry,
802
- inputRegistry,
803
- inputs,
804
- enums,
805
- cache
806
- );
807
- }
808
- }
809
- for (const [, inputReg] of inputs) {
810
- if (inputReg.schema.ast === valueType) {
811
- return toGraphQLInputTypeWithRegistry(
812
- inputReg.schema,
813
- enumRegistry,
814
- inputRegistry,
815
- inputs,
816
- enums,
817
- cache
818
- );
819
- }
820
- let regAst = inputReg.schema.ast;
821
- while (regAst._tag === "Transformation") {
822
- regAst = regAst.to;
823
- if (regAst === valueType) {
824
- return toGraphQLInputTypeWithRegistry(
825
- inputReg.schema,
826
- enumRegistry,
827
- inputRegistry,
828
- inputs,
829
- enums,
830
- cache
831
- );
832
- }
833
- }
834
- if (regAst._tag === "Declaration" && regAst.typeParameters?.[0] === valueType) {
835
- return toGraphQLInputTypeWithRegistry(
836
- inputReg.schema,
837
- enumRegistry,
838
- inputRegistry,
839
- inputs,
840
- enums,
841
- cache
842
- );
843
- }
844
- }
845
- const innerResult = toGraphQLInputTypeWithRegistry(
846
- S2__namespace.make(valueType),
847
- enumRegistry,
848
- inputRegistry,
849
- inputs,
850
- enums,
851
- cache
852
- );
853
- if (innerResult) {
854
- return innerResult;
855
- }
856
- }
857
- }
858
- }
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
+ );
859
693
  }
860
- return toGraphQLInputTypeWithRegistry(
861
- S2__namespace.make(toAst),
862
- enumRegistry,
863
- inputRegistry,
864
- inputs,
865
- enums,
866
- cache
867
- );
868
694
  }
869
- if (ast._tag === "Union") {
870
- const unionAst = ast;
871
- const nonUndefinedTypes = unionAst.types.filter((t) => t._tag !== "UndefinedKeyword");
872
- if (nonUndefinedTypes.length === 1 && nonUndefinedTypes[0]._tag === "Union") {
695
+ for (const [, inputReg] of inputs) {
696
+ if (inputReg.schema.ast === memberAst) {
873
697
  return toGraphQLInputTypeWithRegistry(
874
- S2__namespace.make(nonUndefinedTypes[0]),
698
+ inputReg.schema,
875
699
  enumRegistry,
876
700
  inputRegistry,
877
701
  inputs,
@@ -879,9 +703,18 @@ function toGraphQLInputTypeWithRegistry(schema, enumRegistry, inputRegistry, inp
879
703
  cache
880
704
  );
881
705
  }
882
- 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) {
883
716
  return toGraphQLInputTypeWithRegistry(
884
- S2__namespace.make(nonUndefinedTypes[0]),
717
+ inputReg.schema,
885
718
  enumRegistry,
886
719
  inputRegistry,
887
720
  inputs,
@@ -889,171 +722,210 @@ function toGraphQLInputTypeWithRegistry(schema, enumRegistry, inputRegistry, inp
889
722
  cache
890
723
  );
891
724
  }
892
- for (const memberAst of unionAst.types) {
893
- const inputName = cache?.astToInputName?.get(memberAst);
894
- if (inputName) {
895
- const inputReg = inputs.get(inputName);
896
- if (inputReg) {
897
- return toGraphQLInputTypeWithRegistry(
898
- inputReg.schema,
899
- enumRegistry,
900
- inputRegistry,
901
- inputs,
902
- enums,
903
- cache
904
- );
905
- }
906
- }
907
- for (const [, inputReg] of inputs) {
908
- if (inputReg.schema.ast === memberAst) {
909
- return toGraphQLInputTypeWithRegistry(
910
- inputReg.schema,
911
- enumRegistry,
912
- inputRegistry,
913
- inputs,
914
- enums,
915
- cache
916
- );
917
- }
918
- }
919
- if (memberAst._tag === "Transformation") {
920
- const toAst = memberAst.to;
921
- const transformedInputName = cache?.astToInputName?.get(toAst);
922
- if (transformedInputName) {
923
- const inputReg = inputs.get(transformedInputName);
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 === toAst) {
937
- return toGraphQLInputTypeWithRegistry(
938
- inputReg.schema,
939
- enumRegistry,
940
- inputRegistry,
941
- inputs,
942
- enums,
943
- cache
944
- );
945
- }
946
- }
947
- }
948
- if (memberAst._tag === "TypeLiteral") {
949
- const valueField = memberAst.propertySignatures?.find(
950
- (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
951
783
  );
952
- if (valueField) {
953
- const valueType = valueField.type;
954
- const valueInputName = cache?.astToInputName?.get(valueType);
955
- if (valueInputName) {
956
- const inputReg = inputs.get(valueInputName);
957
- if (inputReg) {
958
- return toGraphQLInputTypeWithRegistry(
959
- inputReg.schema,
960
- enumRegistry,
961
- inputRegistry,
962
- inputs,
963
- enums,
964
- cache
965
- );
966
- }
967
- }
968
- for (const [, inputReg] of inputs) {
969
- if (inputReg.schema.ast === valueType) {
970
- return toGraphQLInputTypeWithRegistry(
971
- inputReg.schema,
972
- enumRegistry,
973
- inputRegistry,
974
- inputs,
975
- enums,
976
- cache
977
- );
978
- }
979
- let regAst = inputReg.schema.ast;
980
- while (regAst._tag === "Transformation") {
981
- regAst = regAst.to;
982
- if (regAst === valueType) {
983
- return toGraphQLInputTypeWithRegistry(
984
- inputReg.schema,
985
- enumRegistry,
986
- inputRegistry,
987
- inputs,
988
- enums,
989
- cache
990
- );
991
- }
992
- }
993
- if (regAst._tag === "Declaration" && regAst.typeParameters?.[0] === valueType) {
994
- return toGraphQLInputTypeWithRegistry(
995
- inputReg.schema,
996
- enumRegistry,
997
- inputRegistry,
998
- inputs,
999
- enums,
1000
- cache
1001
- );
1002
- }
1003
- }
1004
- const innerResult = toGraphQLInputTypeWithRegistry(
1005
- S2__namespace.make(valueType),
1006
- enumRegistry,
1007
- inputRegistry,
1008
- inputs,
1009
- enums,
1010
- cache
1011
- );
1012
- if (innerResult) {
1013
- return innerResult;
1014
- }
1015
- }
1016
784
  }
1017
785
  }
1018
- const allLiterals = unionAst.types.every((t) => t._tag === "Literal");
1019
- if (allLiterals) {
1020
- const literalValues = unionAst.types.map((t) => String(t.literal)).sort();
1021
- for (const [enumName] of enums) {
1022
- const enumValues = cache?.enumSortedValues?.get(enumName) ?? [...enums.get(enumName).values].sort();
1023
- if (literalValues.length === enumValues.length && literalValues.every((v, i) => v === enumValues[i])) {
1024
- const result = enumRegistry.get(enumName);
1025
- if (result) return result;
1026
- }
1027
- }
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
+ );
1028
795
  }
1029
796
  }
1030
- if (ast._tag === "Literal") {
1031
- const literalValue = String(ast.literal);
1032
- if (cache?.literalToEnumName) {
1033
- const enumName = cache.literalToEnumName.get(literalValue);
1034
- 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])) {
1035
878
  const result = enumRegistry.get(enumName);
1036
879
  if (result) return result;
1037
880
  }
1038
- } else {
1039
- for (const [enumName, enumReg] of enums) {
1040
- if (enumReg.values.includes(literalValue)) {
1041
- const result = enumRegistry.get(enumName);
1042
- if (result) return result;
1043
- }
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);
1044
896
  }
1045
897
  }
1046
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
+ }
1047
927
  if (ast._tag === "Suspend") {
1048
- const innerAst = ast.f();
1049
- return toGraphQLInputTypeWithRegistry(
1050
- S2__namespace.make(innerAst),
1051
- enumRegistry,
1052
- inputRegistry,
1053
- inputs,
1054
- enums,
1055
- cache
1056
- );
928
+ return handleSuspendForInput(ast, inputs, inputRegistry, enumRegistry, enums, cache);
1057
929
  }
1058
930
  return toGraphQLInputType(schema);
1059
931
  }