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