@effect-gql/core 1.4.8 → 1.4.10

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/index.cjs CHANGED
@@ -54,6 +54,51 @@ var isIntegerType = (ast) => {
54
54
  }
55
55
  return false;
56
56
  };
57
+ function handlePrimitiveAST(ast) {
58
+ if (ast._tag === "StringKeyword") return graphql.GraphQLString;
59
+ if (ast._tag === "NumberKeyword") return graphql.GraphQLFloat;
60
+ if (ast._tag === "BooleanKeyword") return graphql.GraphQLBoolean;
61
+ return void 0;
62
+ }
63
+ function handleRefinementAST(ast, convertFn) {
64
+ if (isIntegerType(ast)) {
65
+ return graphql.GraphQLInt;
66
+ }
67
+ return convertFn(S2__namespace.make(ast.from));
68
+ }
69
+ function handleLiteralAST(ast) {
70
+ if (ast._tag !== "Literal") return void 0;
71
+ if (typeof ast.literal === "string") return graphql.GraphQLString;
72
+ if (typeof ast.literal === "number") {
73
+ return Number.isInteger(ast.literal) ? graphql.GraphQLInt : graphql.GraphQLFloat;
74
+ }
75
+ if (typeof ast.literal === "boolean") return graphql.GraphQLBoolean;
76
+ return void 0;
77
+ }
78
+ function handleTupleTypeAST(ast, convertFn) {
79
+ if (ast._tag !== "TupleType") return void 0;
80
+ const elements = ast.elements;
81
+ if (elements.length > 0) {
82
+ const elementSchema = S2__namespace.make(elements[0].type);
83
+ return new graphql.GraphQLList(convertFn(elementSchema));
84
+ }
85
+ return void 0;
86
+ }
87
+ function buildFieldsFromPropertySignatures(propertySignatures, convertFn) {
88
+ const fields = {};
89
+ for (const field2 of propertySignatures) {
90
+ const fieldName = String(field2.name);
91
+ if (fieldName === "_tag") continue;
92
+ const fieldSchema = S2__namespace.make(field2.type);
93
+ let fieldType = convertFn(fieldSchema);
94
+ const isOptionField = isOptionTransformation(field2.type) || isOptionDeclaration(field2.type);
95
+ if (!field2.isOptional && !isOptionField) {
96
+ fieldType = new graphql.GraphQLNonNull(fieldType);
97
+ }
98
+ fields[fieldName] = { type: fieldType };
99
+ }
100
+ return fields;
101
+ }
57
102
  var isOptionDeclaration = (ast) => {
58
103
  if (ast._tag === "Declaration") {
59
104
  const annotations = ast.annotations;
@@ -84,42 +129,17 @@ var getOptionInnerType = (ast) => {
84
129
  };
85
130
  var toGraphQLType = (schema) => {
86
131
  const ast = schema.ast;
87
- if (ast._tag === "StringKeyword") return graphql.GraphQLString;
88
- if (ast._tag === "NumberKeyword") return graphql.GraphQLFloat;
89
- if (ast._tag === "BooleanKeyword") return graphql.GraphQLBoolean;
132
+ const primitiveResult = handlePrimitiveAST(ast);
133
+ if (primitiveResult) return primitiveResult;
90
134
  if (ast._tag === "Refinement") {
91
- if (isIntegerType(ast)) {
92
- return graphql.GraphQLInt;
93
- }
94
- return toGraphQLType(S2__namespace.make(ast.from));
95
- }
96
- if (ast._tag === "Literal") {
97
- if (typeof ast.literal === "string") return graphql.GraphQLString;
98
- if (typeof ast.literal === "number") {
99
- return Number.isInteger(ast.literal) ? graphql.GraphQLInt : graphql.GraphQLFloat;
100
- }
101
- if (typeof ast.literal === "boolean") return graphql.GraphQLBoolean;
102
- }
103
- if (ast._tag === "TupleType") {
104
- const elements = ast.elements;
105
- if (elements.length > 0) {
106
- const elementSchema = S2__namespace.make(elements[0].type);
107
- return new graphql.GraphQLList(toGraphQLType(elementSchema));
108
- }
135
+ return handleRefinementAST(ast, toGraphQLType);
109
136
  }
137
+ const literalResult = handleLiteralAST(ast);
138
+ if (literalResult) return literalResult;
139
+ const tupleResult = handleTupleTypeAST(ast, toGraphQLType);
140
+ if (tupleResult) return tupleResult;
110
141
  if (ast._tag === "TypeLiteral") {
111
- const fields = {};
112
- for (const field2 of ast.propertySignatures) {
113
- const fieldName = String(field2.name);
114
- if (fieldName === "_tag") continue;
115
- const fieldSchema = S2__namespace.make(field2.type);
116
- let fieldType = toGraphQLType(fieldSchema);
117
- const isOptionField = isOptionTransformation(field2.type) || isOptionDeclaration(field2.type);
118
- if (!field2.isOptional && !isOptionField) {
119
- fieldType = new graphql.GraphQLNonNull(fieldType);
120
- }
121
- fields[fieldName] = { type: fieldType };
122
- }
142
+ const fields = buildFieldsFromPropertySignatures(ast.propertySignatures, toGraphQLType);
123
143
  const typeName = schema.annotations?.identifier || `Object_${Math.random().toString(36).slice(2, 11)}`;
124
144
  return new graphql.GraphQLObjectType({
125
145
  name: typeName,
@@ -161,42 +181,20 @@ var toGraphQLType = (schema) => {
161
181
  };
162
182
  var toGraphQLInputType = (schema) => {
163
183
  const ast = schema.ast;
164
- if (ast._tag === "StringKeyword") return graphql.GraphQLString;
165
- if (ast._tag === "NumberKeyword") return graphql.GraphQLFloat;
166
- if (ast._tag === "BooleanKeyword") return graphql.GraphQLBoolean;
184
+ const primitiveResult = handlePrimitiveAST(ast);
185
+ if (primitiveResult) return primitiveResult;
167
186
  if (ast._tag === "Refinement") {
168
- if (isIntegerType(ast)) {
169
- return graphql.GraphQLInt;
170
- }
171
- return toGraphQLInputType(S2__namespace.make(ast.from));
172
- }
173
- if (ast._tag === "Literal") {
174
- if (typeof ast.literal === "string") return graphql.GraphQLString;
175
- if (typeof ast.literal === "number") {
176
- return Number.isInteger(ast.literal) ? graphql.GraphQLInt : graphql.GraphQLFloat;
177
- }
178
- if (typeof ast.literal === "boolean") return graphql.GraphQLBoolean;
179
- }
180
- if (ast._tag === "TupleType") {
181
- const elements = ast.elements;
182
- if (elements.length > 0) {
183
- const elementSchema = S2__namespace.make(elements[0].type);
184
- return new graphql.GraphQLList(toGraphQLInputType(elementSchema));
185
- }
187
+ return handleRefinementAST(ast, toGraphQLInputType);
186
188
  }
189
+ const literalResult = handleLiteralAST(ast);
190
+ if (literalResult) return literalResult;
191
+ const tupleResult = handleTupleTypeAST(ast, toGraphQLInputType);
192
+ if (tupleResult) return tupleResult;
187
193
  if (ast._tag === "TypeLiteral") {
188
- const fields = {};
189
- for (const field2 of ast.propertySignatures) {
190
- const fieldName = String(field2.name);
191
- if (fieldName === "_tag") continue;
192
- const fieldSchema = S2__namespace.make(field2.type);
193
- let fieldType = toGraphQLInputType(fieldSchema);
194
- const isOptionField = isOptionTransformation(field2.type) || isOptionDeclaration(field2.type);
195
- if (!field2.isOptional && !isOptionField) {
196
- fieldType = new graphql.GraphQLNonNull(fieldType);
197
- }
198
- fields[fieldName] = { type: fieldType };
199
- }
194
+ const fields = buildFieldsFromPropertySignatures(
195
+ ast.propertySignatures,
196
+ toGraphQLInputType
197
+ );
200
198
  const typeName = schema.annotations?.identifier || `Input_${Math.random().toString(36).slice(2, 11)}`;
201
199
  return new graphql.GraphQLInputObjectType({
202
200
  name: typeName,
@@ -249,18 +247,8 @@ var toGraphQLObjectType = (name, schema, additionalFields) => {
249
247
  }
250
248
  }
251
249
  if (ast._tag === "TypeLiteral") {
252
- const fields = {};
253
- for (const field2 of ast.propertySignatures) {
254
- const fieldName = String(field2.name);
255
- if (fieldName === "_tag") continue;
256
- const fieldSchema = S2__namespace.make(field2.type);
257
- let fieldType = toGraphQLType(fieldSchema);
258
- const isOptionField = isOptionTransformation(field2.type) || isOptionDeclaration(field2.type);
259
- if (!field2.isOptional && !isOptionField) {
260
- fieldType = new graphql.GraphQLNonNull(fieldType);
261
- }
262
- fields[fieldName] = { type: fieldType };
263
- }
250
+ const baseFields = buildFieldsFromPropertySignatures(ast.propertySignatures, toGraphQLType);
251
+ const fields = { ...baseFields };
264
252
  if (additionalFields) {
265
253
  for (const [fieldName, fieldConfig] of Object.entries(additionalFields)) {
266
254
  fields[fieldName] = {
@@ -282,18 +270,7 @@ var toGraphQLObjectType = (name, schema, additionalFields) => {
282
270
  var toGraphQLArgs = (schema) => {
283
271
  const ast = schema.ast;
284
272
  if (ast._tag === "TypeLiteral") {
285
- const args = {};
286
- for (const field2 of ast.propertySignatures) {
287
- const fieldName = String(field2.name);
288
- if (fieldName === "_tag") continue;
289
- const fieldSchema = S2__namespace.make(field2.type);
290
- let fieldType = toGraphQLInputType(fieldSchema);
291
- const isOptionField = isOptionTransformation(field2.type) || isOptionDeclaration(field2.type);
292
- if (!field2.isOptional && !isOptionField) {
293
- fieldType = new graphql.GraphQLNonNull(fieldType);
294
- }
295
- args[fieldName] = { type: fieldType };
296
- }
273
+ const args = buildFieldsFromPropertySignatures(ast.propertySignatures, toGraphQLInputType);
297
274
  return args;
298
275
  }
299
276
  throw new Error(`Schema must be an object type to convert to GraphQL arguments`);
@@ -409,7 +386,7 @@ function toGraphQLTypeWithRegistry(schema, ctx) {
409
386
  if (enumType2) return enumType2;
410
387
  }
411
388
  if (ast._tag === "TupleType") {
412
- return handleTupleTypeAST(ast, ctx);
389
+ return handleTupleTypeAST2(ast, ctx);
413
390
  }
414
391
  if (ast._tag === "Declaration") {
415
392
  if (isOptionDeclaration2(ast)) {
@@ -465,88 +442,112 @@ function getOptionInnerType2(ast) {
465
442
  }
466
443
  return void 0;
467
444
  }
468
- function handleTransformationAST(ast, ctx) {
469
- const toAst = ast.to;
470
- const fromAst = ast.from;
471
- if (isOptionDeclaration2(toAst)) {
472
- if (fromAst && fromAst._tag === "Union") {
473
- for (const memberAst of fromAst.types) {
474
- if (memberAst._tag === "Literal") continue;
475
- if (memberAst._tag === "UndefinedKeyword") continue;
476
- const typeName = ctx.astToTypeName?.get(memberAst);
477
- if (typeName) {
478
- const result = ctx.typeRegistry.get(typeName);
479
- if (result) return result;
480
- }
481
- for (const [regTypeName, typeReg] of ctx.types) {
482
- if (typeReg.schema.ast === memberAst) {
483
- const result = ctx.typeRegistry.get(regTypeName);
484
- if (result) return result;
485
- }
486
- }
487
- if (memberAst._tag === "Transformation") {
488
- const innerToAst = memberAst.to;
489
- const transformedTypeName = ctx.astToTypeName?.get(innerToAst);
490
- if (transformedTypeName) {
491
- const result = ctx.typeRegistry.get(transformedTypeName);
492
- if (result) return result;
493
- }
494
- for (const [regTypeName, typeReg] of ctx.types) {
495
- if (typeReg.schema.ast === innerToAst) {
496
- const result = ctx.typeRegistry.get(regTypeName);
497
- if (result) return result;
498
- }
499
- }
500
- }
501
- if (memberAst._tag === "TypeLiteral") {
502
- const valueField = memberAst.propertySignatures?.find(
503
- (p) => String(p.name) === "value"
504
- );
505
- if (valueField) {
506
- const valueType = valueField.type;
507
- const valueTypeName = ctx.astToTypeName?.get(valueType);
508
- if (valueTypeName) {
509
- const result = ctx.typeRegistry.get(valueTypeName);
510
- if (result) return result;
511
- }
512
- for (const [regTypeName, typeReg] of ctx.types) {
513
- if (typeReg.schema.ast === valueType) {
514
- const result = ctx.typeRegistry.get(regTypeName);
515
- if (result) return result;
516
- }
517
- let regAst = typeReg.schema.ast;
518
- while (regAst._tag === "Transformation") {
519
- regAst = regAst.to;
520
- if (regAst === valueType) {
521
- const result = ctx.typeRegistry.get(regTypeName);
522
- if (result) return result;
523
- }
524
- }
525
- }
526
- const innerResult = toGraphQLTypeWithRegistry(S2__namespace.make(valueType), ctx);
527
- if (innerResult) return innerResult;
528
- }
529
- }
530
- }
445
+ function findRegisteredTypeForAST(memberAst, ctx) {
446
+ const typeName = ctx.astToTypeName?.get(memberAst);
447
+ if (typeName) {
448
+ const result = ctx.typeRegistry.get(typeName);
449
+ if (result) return result;
450
+ }
451
+ for (const [regTypeName, typeReg] of ctx.types) {
452
+ if (typeReg.schema.ast === memberAst) {
453
+ const result = ctx.typeRegistry.get(regTypeName);
454
+ if (result) return result;
531
455
  }
532
- const innerType = getOptionInnerType2(toAst);
533
- if (innerType) {
534
- return toGraphQLTypeWithRegistry(S2__namespace.make(innerType), ctx);
456
+ }
457
+ return void 0;
458
+ }
459
+ function findRegisteredTypeForTransformation(memberAst, ctx) {
460
+ if (memberAst._tag !== "Transformation") return void 0;
461
+ const innerToAst = memberAst.to;
462
+ const transformedTypeName = ctx.astToTypeName?.get(innerToAst);
463
+ if (transformedTypeName) {
464
+ const result = ctx.typeRegistry.get(transformedTypeName);
465
+ if (result) return result;
466
+ }
467
+ for (const [regTypeName, typeReg] of ctx.types) {
468
+ if (typeReg.schema.ast === innerToAst) {
469
+ const result = ctx.typeRegistry.get(regTypeName);
470
+ if (result) return result;
535
471
  }
536
472
  }
537
- if (toAst._tag === "TupleType") {
538
- if (toAst.rest && toAst.rest.length > 0) {
539
- const elementSchema = S2__namespace.make(toAst.rest[0].type);
540
- const elementType = toGraphQLTypeWithRegistry(elementSchema, ctx);
541
- return new graphql.GraphQLList(elementType);
542
- } else if (toAst.elements.length > 0) {
543
- const elementSchema = S2__namespace.make(toAst.elements[0].type);
544
- const elementType = toGraphQLTypeWithRegistry(elementSchema, ctx);
545
- return new graphql.GraphQLList(elementType);
473
+ return void 0;
474
+ }
475
+ function findRegisteredTypeForOptionSome(memberAst, ctx) {
476
+ if (memberAst._tag !== "TypeLiteral") return void 0;
477
+ const valueField = memberAst.propertySignatures?.find(
478
+ (p) => String(p.name) === "value"
479
+ );
480
+ if (!valueField) return void 0;
481
+ const valueType = valueField.type;
482
+ const valueTypeName = ctx.astToTypeName?.get(valueType);
483
+ if (valueTypeName) {
484
+ const result = ctx.typeRegistry.get(valueTypeName);
485
+ if (result) return result;
486
+ }
487
+ for (const [regTypeName, typeReg] of ctx.types) {
488
+ if (typeReg.schema.ast === valueType) {
489
+ const result = ctx.typeRegistry.get(regTypeName);
490
+ if (result) return result;
491
+ }
492
+ let regAst = typeReg.schema.ast;
493
+ while (regAst._tag === "Transformation") {
494
+ regAst = regAst.to;
495
+ if (regAst === valueType) {
496
+ const result = ctx.typeRegistry.get(regTypeName);
497
+ if (result) return result;
498
+ }
546
499
  }
547
500
  }
501
+ const innerResult = toGraphQLTypeWithRegistry(S2__namespace.make(valueType), ctx);
502
+ return innerResult;
503
+ }
504
+ function handleOptionTransformation(ast, fromAst, toAst, ctx) {
505
+ if (fromAst && fromAst._tag === "Union") {
506
+ for (const memberAst of fromAst.types) {
507
+ if (memberAst._tag === "Literal") continue;
508
+ if (memberAst._tag === "UndefinedKeyword") continue;
509
+ const registeredType = findRegisteredTypeForAST(memberAst, ctx) || findRegisteredTypeForTransformation(memberAst, ctx) || findRegisteredTypeForOptionSome(memberAst, ctx);
510
+ if (registeredType) return registeredType;
511
+ }
512
+ }
513
+ const innerType = getOptionInnerType2(toAst);
514
+ if (innerType) {
515
+ return toGraphQLTypeWithRegistry(S2__namespace.make(innerType), ctx);
516
+ }
517
+ return void 0;
518
+ }
519
+ function handleArrayTransformation(toAst, ctx) {
520
+ if (toAst._tag !== "TupleType") return void 0;
521
+ let elementType;
522
+ if (toAst.rest && toAst.rest.length > 0) {
523
+ const elementSchema = S2__namespace.make(toAst.rest[0].type);
524
+ elementType = toGraphQLTypeWithRegistry(elementSchema, ctx);
525
+ } else if (toAst.elements.length > 0) {
526
+ const elementSchema = S2__namespace.make(toAst.elements[0].type);
527
+ elementType = toGraphQLTypeWithRegistry(elementSchema, ctx);
528
+ } else {
529
+ return void 0;
530
+ }
531
+ return new graphql.GraphQLList(elementType);
532
+ }
533
+ function handleTransformationAST(ast, ctx) {
534
+ const toAst = ast.to;
535
+ const fromAst = ast.from;
536
+ if (isOptionDeclaration2(toAst)) {
537
+ const optionResult = handleOptionTransformation(ast, fromAst, toAst, ctx);
538
+ if (optionResult) return optionResult;
539
+ }
540
+ const arrayResult = handleArrayTransformation(toAst, ctx);
541
+ if (arrayResult) return arrayResult;
548
542
  return toGraphQLTypeWithRegistry(S2__namespace.make(ast.to), ctx);
549
543
  }
544
+ function findRegisteredTypeInUnionMembers(types, ctx) {
545
+ for (const memberAst of types) {
546
+ const registeredType = findRegisteredTypeForAST(memberAst, ctx) || findRegisteredTypeForTransformation(memberAst, ctx) || findRegisteredTypeForOptionSome(memberAst, ctx);
547
+ if (registeredType) return registeredType;
548
+ }
549
+ return void 0;
550
+ }
550
551
  function handleUnionAST(ast, ctx) {
551
552
  const allLiterals = ast.types.every((t) => t._tag === "Literal");
552
553
  if (allLiterals) {
@@ -556,64 +557,8 @@ function handleUnionAST(ast, ctx) {
556
557
  const unionType2 = findRegisteredUnion(ast.types, ctx);
557
558
  if (unionType2) return unionType2;
558
559
  }
559
- for (const memberAst of ast.types) {
560
- const typeName = ctx.astToTypeName?.get(memberAst);
561
- if (typeName) {
562
- const result = ctx.typeRegistry.get(typeName);
563
- if (result) return result;
564
- }
565
- for (const [regTypeName, typeReg] of ctx.types) {
566
- if (typeReg.schema.ast === memberAst) {
567
- const result = ctx.typeRegistry.get(regTypeName);
568
- if (result) return result;
569
- }
570
- }
571
- if (memberAst._tag === "Transformation") {
572
- const toAst = memberAst.to;
573
- const transformedTypeName = ctx.astToTypeName?.get(toAst);
574
- if (transformedTypeName) {
575
- const result = ctx.typeRegistry.get(transformedTypeName);
576
- if (result) return result;
577
- }
578
- for (const [regTypeName, typeReg] of ctx.types) {
579
- if (typeReg.schema.ast === toAst) {
580
- const result = ctx.typeRegistry.get(regTypeName);
581
- if (result) return result;
582
- }
583
- }
584
- }
585
- if (memberAst._tag === "TypeLiteral") {
586
- const valueField = memberAst.propertySignatures?.find(
587
- (p) => String(p.name) === "value"
588
- );
589
- if (valueField) {
590
- const valueType = valueField.type;
591
- const valueTypeName = ctx.astToTypeName?.get(valueType);
592
- if (valueTypeName) {
593
- const result = ctx.typeRegistry.get(valueTypeName);
594
- if (result) return result;
595
- }
596
- for (const [regTypeName, typeReg] of ctx.types) {
597
- if (typeReg.schema.ast === valueType) {
598
- const result = ctx.typeRegistry.get(regTypeName);
599
- if (result) return result;
600
- }
601
- let regAst = typeReg.schema.ast;
602
- while (regAst._tag === "Transformation") {
603
- regAst = regAst.to;
604
- if (regAst === valueType) {
605
- const result = ctx.typeRegistry.get(regTypeName);
606
- if (result) return result;
607
- }
608
- }
609
- }
610
- const innerResult = toGraphQLTypeWithRegistry(S2__namespace.make(valueType), ctx);
611
- if (innerResult) {
612
- return innerResult;
613
- }
614
- }
615
- }
616
- }
560
+ const registeredType = findRegisteredTypeInUnionMembers(ast.types, ctx);
561
+ if (registeredType) return registeredType;
617
562
  if (ast.types.length > 0) {
618
563
  return toGraphQLTypeWithRegistry(S2__namespace.make(ast.types[0]), ctx);
619
564
  }
@@ -658,7 +603,7 @@ function findEnumForLiteral(ast, ctx) {
658
603
  }
659
604
  return void 0;
660
605
  }
661
- function handleTupleTypeAST(ast, ctx) {
606
+ function handleTupleTypeAST2(ast, ctx) {
662
607
  if (ast.rest && ast.rest.length > 0) {
663
608
  const elementSchema = S2__namespace.make(ast.rest[0].type);
664
609
  const elementType = toGraphQLTypeWithRegistry(elementSchema, ctx);
@@ -758,170 +703,40 @@ function buildInputTypeLookupCache(inputs, enums) {
758
703
  }
759
704
  return cache;
760
705
  }
761
- function toGraphQLInputTypeWithRegistry(schema, enumRegistry, inputRegistry, inputs, enums, cache) {
762
- const ast = schema.ast;
706
+ function findRegisteredInputType(schema, ast, inputs, inputRegistry, cache) {
763
707
  if (cache?.schemaToInputName || cache?.astToInputName) {
764
708
  const inputName = cache.schemaToInputName?.get(schema) ?? cache.astToInputName?.get(ast);
765
709
  if (inputName) {
766
- const result = inputRegistry.get(inputName);
767
- if (result) return result;
710
+ return inputRegistry.get(inputName);
768
711
  }
769
712
  } else {
770
713
  for (const [inputName, inputReg] of inputs) {
771
714
  if (inputReg.schema.ast === ast || inputReg.schema === schema) {
772
- const result = inputRegistry.get(inputName);
773
- if (result) return result;
715
+ return inputRegistry.get(inputName);
774
716
  }
775
717
  }
776
718
  }
777
- if (ast._tag === "Transformation") {
778
- const toAst = ast.to;
779
- const fromAst = ast.from;
780
- if (isOptionDeclaration2(toAst) && fromAst && fromAst._tag === "Union") {
781
- for (const memberAst of fromAst.types) {
782
- if (memberAst._tag === "Literal") continue;
783
- if (memberAst._tag === "UndefinedKeyword") continue;
784
- const inputName = cache?.astToInputName?.get(memberAst);
785
- if (inputName) {
786
- const inputReg = inputs.get(inputName);
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 === memberAst) {
800
- return toGraphQLInputTypeWithRegistry(
801
- inputReg.schema,
802
- enumRegistry,
803
- inputRegistry,
804
- inputs,
805
- enums,
806
- cache
807
- );
808
- }
809
- }
810
- if (memberAst._tag === "Transformation") {
811
- const innerToAst = memberAst.to;
812
- const transformedInputName = cache?.astToInputName?.get(innerToAst);
813
- if (transformedInputName) {
814
- const inputReg = inputs.get(transformedInputName);
815
- if (inputReg) {
816
- return toGraphQLInputTypeWithRegistry(
817
- inputReg.schema,
818
- enumRegistry,
819
- inputRegistry,
820
- inputs,
821
- enums,
822
- cache
823
- );
824
- }
825
- }
826
- for (const [, inputReg] of inputs) {
827
- if (inputReg.schema.ast === innerToAst) {
828
- return toGraphQLInputTypeWithRegistry(
829
- inputReg.schema,
830
- enumRegistry,
831
- inputRegistry,
832
- inputs,
833
- enums,
834
- cache
835
- );
836
- }
837
- }
838
- }
839
- if (memberAst._tag === "TypeLiteral") {
840
- const valueField = memberAst.propertySignatures?.find(
841
- (p) => String(p.name) === "value"
842
- );
843
- if (valueField) {
844
- const valueType = valueField.type;
845
- const valueInputName = cache?.astToInputName?.get(valueType);
846
- if (valueInputName) {
847
- const inputReg = inputs.get(valueInputName);
848
- if (inputReg) {
849
- return toGraphQLInputTypeWithRegistry(
850
- inputReg.schema,
851
- enumRegistry,
852
- inputRegistry,
853
- inputs,
854
- enums,
855
- cache
856
- );
857
- }
858
- }
859
- for (const [, inputReg] of inputs) {
860
- if (inputReg.schema.ast === valueType) {
861
- return toGraphQLInputTypeWithRegistry(
862
- inputReg.schema,
863
- enumRegistry,
864
- inputRegistry,
865
- inputs,
866
- enums,
867
- cache
868
- );
869
- }
870
- let regAst = inputReg.schema.ast;
871
- while (regAst._tag === "Transformation") {
872
- regAst = regAst.to;
873
- if (regAst === valueType) {
874
- return toGraphQLInputTypeWithRegistry(
875
- inputReg.schema,
876
- enumRegistry,
877
- inputRegistry,
878
- inputs,
879
- enums,
880
- cache
881
- );
882
- }
883
- }
884
- if (regAst._tag === "Declaration" && regAst.typeParameters?.[0] === valueType) {
885
- return toGraphQLInputTypeWithRegistry(
886
- inputReg.schema,
887
- enumRegistry,
888
- inputRegistry,
889
- inputs,
890
- enums,
891
- cache
892
- );
893
- }
894
- }
895
- const innerResult = toGraphQLInputTypeWithRegistry(
896
- S2__namespace.make(valueType),
897
- enumRegistry,
898
- inputRegistry,
899
- inputs,
900
- enums,
901
- cache
902
- );
903
- if (innerResult) {
904
- return innerResult;
905
- }
906
- }
907
- }
908
- }
719
+ return void 0;
720
+ }
721
+ function findRegisteredInputForAST(memberAst, inputs, inputRegistry, enumRegistry, enums, cache) {
722
+ const inputName = cache?.astToInputName?.get(memberAst);
723
+ if (inputName) {
724
+ const inputReg = inputs.get(inputName);
725
+ if (inputReg) {
726
+ return toGraphQLInputTypeWithRegistry(
727
+ inputReg.schema,
728
+ enumRegistry,
729
+ inputRegistry,
730
+ inputs,
731
+ enums,
732
+ cache
733
+ );
909
734
  }
910
- return toGraphQLInputTypeWithRegistry(
911
- S2__namespace.make(toAst),
912
- enumRegistry,
913
- inputRegistry,
914
- inputs,
915
- enums,
916
- cache
917
- );
918
735
  }
919
- if (ast._tag === "Union") {
920
- const unionAst = ast;
921
- const nonUndefinedTypes = unionAst.types.filter((t) => t._tag !== "UndefinedKeyword");
922
- if (nonUndefinedTypes.length === 1 && nonUndefinedTypes[0]._tag === "Union") {
736
+ for (const [, inputReg] of inputs) {
737
+ if (inputReg.schema.ast === memberAst) {
923
738
  return toGraphQLInputTypeWithRegistry(
924
- S2__namespace.make(nonUndefinedTypes[0]),
739
+ inputReg.schema,
925
740
  enumRegistry,
926
741
  inputRegistry,
927
742
  inputs,
@@ -929,9 +744,18 @@ function toGraphQLInputTypeWithRegistry(schema, enumRegistry, inputRegistry, inp
929
744
  cache
930
745
  );
931
746
  }
932
- if (nonUndefinedTypes.length === 1 && nonUndefinedTypes[0]._tag === "TypeLiteral") {
747
+ }
748
+ return void 0;
749
+ }
750
+ function findRegisteredInputForTransformation(memberAst, inputs, inputRegistry, enumRegistry, enums, cache) {
751
+ if (memberAst._tag !== "Transformation") return void 0;
752
+ const innerToAst = memberAst.to;
753
+ const transformedInputName = cache?.astToInputName?.get(innerToAst);
754
+ if (transformedInputName) {
755
+ const inputReg = inputs.get(transformedInputName);
756
+ if (inputReg) {
933
757
  return toGraphQLInputTypeWithRegistry(
934
- S2__namespace.make(nonUndefinedTypes[0]),
758
+ inputReg.schema,
935
759
  enumRegistry,
936
760
  inputRegistry,
937
761
  inputs,
@@ -939,171 +763,210 @@ function toGraphQLInputTypeWithRegistry(schema, enumRegistry, inputRegistry, inp
939
763
  cache
940
764
  );
941
765
  }
942
- for (const memberAst of unionAst.types) {
943
- const inputName = cache?.astToInputName?.get(memberAst);
944
- if (inputName) {
945
- const inputReg = inputs.get(inputName);
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 === memberAst) {
959
- return toGraphQLInputTypeWithRegistry(
960
- inputReg.schema,
961
- enumRegistry,
962
- inputRegistry,
963
- inputs,
964
- enums,
965
- cache
966
- );
967
- }
968
- }
969
- if (memberAst._tag === "Transformation") {
970
- const toAst = memberAst.to;
971
- const transformedInputName = cache?.astToInputName?.get(toAst);
972
- if (transformedInputName) {
973
- const inputReg = inputs.get(transformedInputName);
974
- if (inputReg) {
975
- return toGraphQLInputTypeWithRegistry(
976
- inputReg.schema,
977
- enumRegistry,
978
- inputRegistry,
979
- inputs,
980
- enums,
981
- cache
982
- );
983
- }
984
- }
985
- for (const [, inputReg] of inputs) {
986
- if (inputReg.schema.ast === toAst) {
987
- return toGraphQLInputTypeWithRegistry(
988
- inputReg.schema,
989
- enumRegistry,
990
- inputRegistry,
991
- inputs,
992
- enums,
993
- cache
994
- );
995
- }
996
- }
997
- }
998
- if (memberAst._tag === "TypeLiteral") {
999
- const valueField = memberAst.propertySignatures?.find(
1000
- (p) => String(p.name) === "value"
766
+ }
767
+ for (const [, inputReg] of inputs) {
768
+ if (inputReg.schema.ast === innerToAst) {
769
+ return toGraphQLInputTypeWithRegistry(
770
+ inputReg.schema,
771
+ enumRegistry,
772
+ inputRegistry,
773
+ inputs,
774
+ enums,
775
+ cache
776
+ );
777
+ }
778
+ }
779
+ return void 0;
780
+ }
781
+ function findRegisteredInputForOptionSome(memberAst, inputs, inputRegistry, enumRegistry, enums, cache) {
782
+ if (memberAst._tag !== "TypeLiteral") return void 0;
783
+ const valueField = memberAst.propertySignatures?.find(
784
+ (p) => String(p.name) === "value"
785
+ );
786
+ if (!valueField) return void 0;
787
+ const valueType = valueField.type;
788
+ const valueInputName = cache?.astToInputName?.get(valueType);
789
+ if (valueInputName) {
790
+ const inputReg = inputs.get(valueInputName);
791
+ if (inputReg) {
792
+ return toGraphQLInputTypeWithRegistry(
793
+ inputReg.schema,
794
+ enumRegistry,
795
+ inputRegistry,
796
+ inputs,
797
+ enums,
798
+ cache
799
+ );
800
+ }
801
+ }
802
+ for (const [, inputReg] of inputs) {
803
+ if (inputReg.schema.ast === valueType) {
804
+ return toGraphQLInputTypeWithRegistry(
805
+ inputReg.schema,
806
+ enumRegistry,
807
+ inputRegistry,
808
+ inputs,
809
+ enums,
810
+ cache
811
+ );
812
+ }
813
+ let regAst = inputReg.schema.ast;
814
+ while (regAst._tag === "Transformation") {
815
+ regAst = regAst.to;
816
+ if (regAst === valueType) {
817
+ return toGraphQLInputTypeWithRegistry(
818
+ inputReg.schema,
819
+ enumRegistry,
820
+ inputRegistry,
821
+ inputs,
822
+ enums,
823
+ cache
1001
824
  );
1002
- if (valueField) {
1003
- const valueType = valueField.type;
1004
- const valueInputName = cache?.astToInputName?.get(valueType);
1005
- if (valueInputName) {
1006
- const inputReg = inputs.get(valueInputName);
1007
- if (inputReg) {
1008
- return toGraphQLInputTypeWithRegistry(
1009
- inputReg.schema,
1010
- enumRegistry,
1011
- inputRegistry,
1012
- inputs,
1013
- enums,
1014
- cache
1015
- );
1016
- }
1017
- }
1018
- for (const [, inputReg] of inputs) {
1019
- if (inputReg.schema.ast === valueType) {
1020
- return toGraphQLInputTypeWithRegistry(
1021
- inputReg.schema,
1022
- enumRegistry,
1023
- inputRegistry,
1024
- inputs,
1025
- enums,
1026
- cache
1027
- );
1028
- }
1029
- let regAst = inputReg.schema.ast;
1030
- while (regAst._tag === "Transformation") {
1031
- regAst = regAst.to;
1032
- if (regAst === valueType) {
1033
- return toGraphQLInputTypeWithRegistry(
1034
- inputReg.schema,
1035
- enumRegistry,
1036
- inputRegistry,
1037
- inputs,
1038
- enums,
1039
- cache
1040
- );
1041
- }
1042
- }
1043
- if (regAst._tag === "Declaration" && regAst.typeParameters?.[0] === valueType) {
1044
- return toGraphQLInputTypeWithRegistry(
1045
- inputReg.schema,
1046
- enumRegistry,
1047
- inputRegistry,
1048
- inputs,
1049
- enums,
1050
- cache
1051
- );
1052
- }
1053
- }
1054
- const innerResult = toGraphQLInputTypeWithRegistry(
1055
- S2__namespace.make(valueType),
1056
- enumRegistry,
1057
- inputRegistry,
1058
- inputs,
1059
- enums,
1060
- cache
1061
- );
1062
- if (innerResult) {
1063
- return innerResult;
1064
- }
1065
- }
1066
825
  }
1067
826
  }
1068
- const allLiterals = unionAst.types.every((t) => t._tag === "Literal");
1069
- if (allLiterals) {
1070
- const literalValues = unionAst.types.map((t) => String(t.literal)).sort();
1071
- for (const [enumName] of enums) {
1072
- const enumValues = cache?.enumSortedValues?.get(enumName) ?? [...enums.get(enumName).values].sort();
1073
- if (literalValues.length === enumValues.length && literalValues.every((v, i) => v === enumValues[i])) {
1074
- const result = enumRegistry.get(enumName);
1075
- if (result) return result;
1076
- }
1077
- }
827
+ if (regAst._tag === "Declaration" && regAst.typeParameters?.[0] === valueType) {
828
+ return toGraphQLInputTypeWithRegistry(
829
+ inputReg.schema,
830
+ enumRegistry,
831
+ inputRegistry,
832
+ inputs,
833
+ enums,
834
+ cache
835
+ );
1078
836
  }
1079
837
  }
1080
- if (ast._tag === "Literal") {
1081
- const literalValue = String(ast.literal);
1082
- if (cache?.literalToEnumName) {
1083
- const enumName = cache.literalToEnumName.get(literalValue);
1084
- if (enumName) {
838
+ const innerResult = toGraphQLInputTypeWithRegistry(
839
+ S2__namespace.make(valueType),
840
+ enumRegistry,
841
+ inputRegistry,
842
+ inputs,
843
+ enums,
844
+ cache
845
+ );
846
+ return innerResult || void 0;
847
+ }
848
+ function handleOptionTransformationForInput(fromAst, toAst, inputs, inputRegistry, enumRegistry, enums, cache) {
849
+ if (!fromAst || fromAst._tag !== "Union") return void 0;
850
+ for (const memberAst of fromAst.types) {
851
+ if (memberAst._tag === "Literal") continue;
852
+ if (memberAst._tag === "UndefinedKeyword") continue;
853
+ const registeredInput = findRegisteredInputForAST(memberAst, inputs, inputRegistry, enumRegistry, enums, cache) || findRegisteredInputForTransformation(memberAst, inputs, inputRegistry, enumRegistry, enums, cache) || findRegisteredInputForOptionSome(memberAst, inputs, inputRegistry, enumRegistry, enums, cache);
854
+ if (registeredInput) return registeredInput;
855
+ }
856
+ return void 0;
857
+ }
858
+ function handleTransformationForInput(ast, inputs, inputRegistry, enumRegistry, enums, cache) {
859
+ const toAst = ast.to;
860
+ const fromAst = ast.from;
861
+ if (isOptionDeclaration2(toAst)) {
862
+ const optionResult = handleOptionTransformationForInput(
863
+ fromAst,
864
+ toAst,
865
+ inputs,
866
+ inputRegistry,
867
+ enumRegistry,
868
+ enums,
869
+ cache
870
+ );
871
+ if (optionResult) return optionResult;
872
+ }
873
+ return toGraphQLInputTypeWithRegistry(
874
+ S2__namespace.make(toAst),
875
+ enumRegistry,
876
+ inputRegistry,
877
+ inputs,
878
+ enums,
879
+ cache
880
+ );
881
+ }
882
+ function findRegisteredInputInUnionMembers(types, inputs, inputRegistry, enumRegistry, enums, cache) {
883
+ for (const memberAst of types) {
884
+ const registeredInput = findRegisteredInputForAST(memberAst, inputs, inputRegistry, enumRegistry, enums, cache) || findRegisteredInputForTransformation(memberAst, inputs, inputRegistry, enumRegistry, enums, cache) || findRegisteredInputForOptionSome(memberAst, inputs, inputRegistry, enumRegistry, enums, cache);
885
+ if (registeredInput) return registeredInput;
886
+ }
887
+ return void 0;
888
+ }
889
+ function handleUnionForInput(ast, inputs, inputRegistry, enumRegistry, enums, cache) {
890
+ const unionAst = ast;
891
+ const nonUndefinedTypes = unionAst.types.filter((t) => t._tag !== "UndefinedKeyword");
892
+ if (nonUndefinedTypes.length === 1) {
893
+ if (nonUndefinedTypes[0]._tag === "Union" || nonUndefinedTypes[0]._tag === "TypeLiteral") {
894
+ return toGraphQLInputTypeWithRegistry(
895
+ S2__namespace.make(nonUndefinedTypes[0]),
896
+ enumRegistry,
897
+ inputRegistry,
898
+ inputs,
899
+ enums,
900
+ cache
901
+ );
902
+ }
903
+ }
904
+ const registeredInput = findRegisteredInputInUnionMembers(
905
+ unionAst.types,
906
+ inputs,
907
+ inputRegistry,
908
+ enumRegistry,
909
+ enums,
910
+ cache
911
+ );
912
+ if (registeredInput) return registeredInput;
913
+ const allLiterals = unionAst.types.every((t) => t._tag === "Literal");
914
+ if (allLiterals) {
915
+ const literalValues = unionAst.types.map((t) => String(t.literal)).sort();
916
+ for (const [enumName] of enums) {
917
+ const enumValues = cache?.enumSortedValues?.get(enumName) ?? [...enums.get(enumName).values].sort();
918
+ if (literalValues.length === enumValues.length && literalValues.every((v, i) => v === enumValues[i])) {
1085
919
  const result = enumRegistry.get(enumName);
1086
920
  if (result) return result;
1087
921
  }
1088
- } else {
1089
- for (const [enumName, enumReg] of enums) {
1090
- if (enumReg.values.includes(literalValue)) {
1091
- const result = enumRegistry.get(enumName);
1092
- if (result) return result;
1093
- }
922
+ }
923
+ }
924
+ return void 0;
925
+ }
926
+ function handleLiteralForInput(ast, enumRegistry, enums, cache) {
927
+ const literalValue = String(ast.literal);
928
+ if (cache?.literalToEnumName) {
929
+ const enumName = cache.literalToEnumName.get(literalValue);
930
+ if (enumName) {
931
+ return enumRegistry.get(enumName);
932
+ }
933
+ } else {
934
+ for (const [enumName, enumReg] of enums) {
935
+ if (enumReg.values.includes(literalValue)) {
936
+ return enumRegistry.get(enumName);
1094
937
  }
1095
938
  }
1096
939
  }
940
+ return void 0;
941
+ }
942
+ function handleSuspendForInput(ast, inputs, inputRegistry, enumRegistry, enums, cache) {
943
+ const innerAst = ast.f();
944
+ return toGraphQLInputTypeWithRegistry(
945
+ S2__namespace.make(innerAst),
946
+ enumRegistry,
947
+ inputRegistry,
948
+ inputs,
949
+ enums,
950
+ cache
951
+ );
952
+ }
953
+ function toGraphQLInputTypeWithRegistry(schema, enumRegistry, inputRegistry, inputs, enums, cache) {
954
+ const ast = schema.ast;
955
+ const registeredInput = findRegisteredInputType(schema, ast, inputs, inputRegistry, cache);
956
+ if (registeredInput) return registeredInput;
957
+ if (ast._tag === "Transformation") {
958
+ return handleTransformationForInput(ast, inputs, inputRegistry, enumRegistry, enums, cache);
959
+ }
960
+ if (ast._tag === "Union") {
961
+ const unionResult = handleUnionForInput(ast, inputs, inputRegistry, enumRegistry, enums, cache);
962
+ if (unionResult) return unionResult;
963
+ }
964
+ if (ast._tag === "Literal") {
965
+ const literalResult = handleLiteralForInput(ast, enumRegistry, enums, cache);
966
+ if (literalResult) return literalResult;
967
+ }
1097
968
  if (ast._tag === "Suspend") {
1098
- const innerAst = ast.f();
1099
- return toGraphQLInputTypeWithRegistry(
1100
- S2__namespace.make(innerAst),
1101
- enumRegistry,
1102
- inputRegistry,
1103
- inputs,
1104
- enums,
1105
- cache
1106
- );
969
+ return handleSuspendForInput(ast, inputs, inputRegistry, enumRegistry, enums, cache);
1107
970
  }
1108
971
  return toGraphQLInputType(schema);
1109
972
  }