@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/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, isInput) {
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,19 @@ 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);
200
197
  const typeName = schema.annotations?.identifier || `Input_${Math.random().toString(36).slice(2, 11)}`;
201
198
  return new graphql.GraphQLInputObjectType({
202
199
  name: typeName,
@@ -249,18 +246,8 @@ var toGraphQLObjectType = (name, schema, additionalFields) => {
249
246
  }
250
247
  }
251
248
  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
- }
249
+ const baseFields = buildFieldsFromPropertySignatures(ast.propertySignatures, toGraphQLType);
250
+ const fields = { ...baseFields };
264
251
  if (additionalFields) {
265
252
  for (const [fieldName, fieldConfig] of Object.entries(additionalFields)) {
266
253
  fields[fieldName] = {
@@ -282,18 +269,7 @@ var toGraphQLObjectType = (name, schema, additionalFields) => {
282
269
  var toGraphQLArgs = (schema) => {
283
270
  const ast = schema.ast;
284
271
  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
- }
272
+ const args = buildFieldsFromPropertySignatures(ast.propertySignatures, toGraphQLInputType);
297
273
  return args;
298
274
  }
299
275
  throw new Error(`Schema must be an object type to convert to GraphQL arguments`);
@@ -409,7 +385,7 @@ function toGraphQLTypeWithRegistry(schema, ctx) {
409
385
  if (enumType2) return enumType2;
410
386
  }
411
387
  if (ast._tag === "TupleType") {
412
- return handleTupleTypeAST(ast, ctx);
388
+ return handleTupleTypeAST2(ast, ctx);
413
389
  }
414
390
  if (ast._tag === "Declaration") {
415
391
  if (isOptionDeclaration2(ast)) {
@@ -465,88 +441,112 @@ function getOptionInnerType2(ast) {
465
441
  }
466
442
  return void 0;
467
443
  }
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
- }
444
+ function findRegisteredTypeForAST(memberAst, ctx) {
445
+ const typeName = ctx.astToTypeName?.get(memberAst);
446
+ if (typeName) {
447
+ const result = ctx.typeRegistry.get(typeName);
448
+ if (result) return result;
449
+ }
450
+ for (const [regTypeName, typeReg] of ctx.types) {
451
+ if (typeReg.schema.ast === memberAst) {
452
+ const result = ctx.typeRegistry.get(regTypeName);
453
+ if (result) return result;
531
454
  }
532
- const innerType = getOptionInnerType2(toAst);
533
- if (innerType) {
534
- return toGraphQLTypeWithRegistry(S2__namespace.make(innerType), ctx);
455
+ }
456
+ return void 0;
457
+ }
458
+ function findRegisteredTypeForTransformation(memberAst, ctx) {
459
+ if (memberAst._tag !== "Transformation") return void 0;
460
+ const innerToAst = memberAst.to;
461
+ const transformedTypeName = ctx.astToTypeName?.get(innerToAst);
462
+ if (transformedTypeName) {
463
+ const result = ctx.typeRegistry.get(transformedTypeName);
464
+ if (result) return result;
465
+ }
466
+ for (const [regTypeName, typeReg] of ctx.types) {
467
+ if (typeReg.schema.ast === innerToAst) {
468
+ const result = ctx.typeRegistry.get(regTypeName);
469
+ if (result) return result;
535
470
  }
536
471
  }
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);
472
+ return void 0;
473
+ }
474
+ function findRegisteredTypeForOptionSome(memberAst, ctx) {
475
+ if (memberAst._tag !== "TypeLiteral") return void 0;
476
+ const valueField = memberAst.propertySignatures?.find(
477
+ (p) => String(p.name) === "value"
478
+ );
479
+ if (!valueField) return void 0;
480
+ const valueType = valueField.type;
481
+ const valueTypeName = ctx.astToTypeName?.get(valueType);
482
+ if (valueTypeName) {
483
+ const result = ctx.typeRegistry.get(valueTypeName);
484
+ if (result) return result;
485
+ }
486
+ for (const [regTypeName, typeReg] of ctx.types) {
487
+ if (typeReg.schema.ast === valueType) {
488
+ const result = ctx.typeRegistry.get(regTypeName);
489
+ if (result) return result;
490
+ }
491
+ let regAst = typeReg.schema.ast;
492
+ while (regAst._tag === "Transformation") {
493
+ regAst = regAst.to;
494
+ if (regAst === valueType) {
495
+ const result = ctx.typeRegistry.get(regTypeName);
496
+ if (result) return result;
497
+ }
546
498
  }
547
499
  }
500
+ const innerResult = toGraphQLTypeWithRegistry(S2__namespace.make(valueType), ctx);
501
+ return innerResult;
502
+ }
503
+ function handleOptionTransformation(ast, fromAst, toAst, ctx) {
504
+ if (fromAst && fromAst._tag === "Union") {
505
+ for (const memberAst of fromAst.types) {
506
+ if (memberAst._tag === "Literal") continue;
507
+ if (memberAst._tag === "UndefinedKeyword") continue;
508
+ const registeredType = findRegisteredTypeForAST(memberAst, ctx) || findRegisteredTypeForTransformation(memberAst, ctx) || findRegisteredTypeForOptionSome(memberAst, ctx);
509
+ if (registeredType) return registeredType;
510
+ }
511
+ }
512
+ const innerType = getOptionInnerType2(toAst);
513
+ if (innerType) {
514
+ return toGraphQLTypeWithRegistry(S2__namespace.make(innerType), ctx);
515
+ }
516
+ return void 0;
517
+ }
518
+ function handleArrayTransformation(toAst, ctx) {
519
+ if (toAst._tag !== "TupleType") return void 0;
520
+ let elementType;
521
+ if (toAst.rest && toAst.rest.length > 0) {
522
+ const elementSchema = S2__namespace.make(toAst.rest[0].type);
523
+ elementType = toGraphQLTypeWithRegistry(elementSchema, ctx);
524
+ } else if (toAst.elements.length > 0) {
525
+ const elementSchema = S2__namespace.make(toAst.elements[0].type);
526
+ elementType = toGraphQLTypeWithRegistry(elementSchema, ctx);
527
+ } else {
528
+ return void 0;
529
+ }
530
+ return new graphql.GraphQLList(elementType);
531
+ }
532
+ function handleTransformationAST(ast, ctx) {
533
+ const toAst = ast.to;
534
+ const fromAst = ast.from;
535
+ if (isOptionDeclaration2(toAst)) {
536
+ const optionResult = handleOptionTransformation(ast, fromAst, toAst, ctx);
537
+ if (optionResult) return optionResult;
538
+ }
539
+ const arrayResult = handleArrayTransformation(toAst, ctx);
540
+ if (arrayResult) return arrayResult;
548
541
  return toGraphQLTypeWithRegistry(S2__namespace.make(ast.to), ctx);
549
542
  }
543
+ function findRegisteredTypeInUnionMembers(types, ctx) {
544
+ for (const memberAst of types) {
545
+ const registeredType = findRegisteredTypeForAST(memberAst, ctx) || findRegisteredTypeForTransformation(memberAst, ctx) || findRegisteredTypeForOptionSome(memberAst, ctx);
546
+ if (registeredType) return registeredType;
547
+ }
548
+ return void 0;
549
+ }
550
550
  function handleUnionAST(ast, ctx) {
551
551
  const allLiterals = ast.types.every((t) => t._tag === "Literal");
552
552
  if (allLiterals) {
@@ -556,64 +556,8 @@ function handleUnionAST(ast, ctx) {
556
556
  const unionType2 = findRegisteredUnion(ast.types, ctx);
557
557
  if (unionType2) return unionType2;
558
558
  }
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
- }
559
+ const registeredType = findRegisteredTypeInUnionMembers(ast.types, ctx);
560
+ if (registeredType) return registeredType;
617
561
  if (ast.types.length > 0) {
618
562
  return toGraphQLTypeWithRegistry(S2__namespace.make(ast.types[0]), ctx);
619
563
  }
@@ -658,7 +602,7 @@ function findEnumForLiteral(ast, ctx) {
658
602
  }
659
603
  return void 0;
660
604
  }
661
- function handleTupleTypeAST(ast, ctx) {
605
+ function handleTupleTypeAST2(ast, ctx) {
662
606
  if (ast.rest && ast.rest.length > 0) {
663
607
  const elementSchema = S2__namespace.make(ast.rest[0].type);
664
608
  const elementType = toGraphQLTypeWithRegistry(elementSchema, ctx);
@@ -758,170 +702,40 @@ function buildInputTypeLookupCache(inputs, enums) {
758
702
  }
759
703
  return cache;
760
704
  }
761
- function toGraphQLInputTypeWithRegistry(schema, enumRegistry, inputRegistry, inputs, enums, cache) {
762
- const ast = schema.ast;
705
+ function findRegisteredInputType(schema, ast, inputs, inputRegistry, cache) {
763
706
  if (cache?.schemaToInputName || cache?.astToInputName) {
764
707
  const inputName = cache.schemaToInputName?.get(schema) ?? cache.astToInputName?.get(ast);
765
708
  if (inputName) {
766
- const result = inputRegistry.get(inputName);
767
- if (result) return result;
709
+ return inputRegistry.get(inputName);
768
710
  }
769
711
  } else {
770
712
  for (const [inputName, inputReg] of inputs) {
771
713
  if (inputReg.schema.ast === ast || inputReg.schema === schema) {
772
- const result = inputRegistry.get(inputName);
773
- if (result) return result;
714
+ return inputRegistry.get(inputName);
774
715
  }
775
716
  }
776
717
  }
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
- }
718
+ return void 0;
719
+ }
720
+ function findRegisteredInputForAST(memberAst, inputs, inputRegistry, enumRegistry, enums, cache) {
721
+ const inputName = cache?.astToInputName?.get(memberAst);
722
+ if (inputName) {
723
+ const inputReg = inputs.get(inputName);
724
+ if (inputReg) {
725
+ return toGraphQLInputTypeWithRegistry(
726
+ inputReg.schema,
727
+ enumRegistry,
728
+ inputRegistry,
729
+ inputs,
730
+ enums,
731
+ cache
732
+ );
909
733
  }
910
- return toGraphQLInputTypeWithRegistry(
911
- S2__namespace.make(toAst),
912
- enumRegistry,
913
- inputRegistry,
914
- inputs,
915
- enums,
916
- cache
917
- );
918
734
  }
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") {
735
+ for (const [, inputReg] of inputs) {
736
+ if (inputReg.schema.ast === memberAst) {
923
737
  return toGraphQLInputTypeWithRegistry(
924
- S2__namespace.make(nonUndefinedTypes[0]),
738
+ inputReg.schema,
925
739
  enumRegistry,
926
740
  inputRegistry,
927
741
  inputs,
@@ -929,9 +743,18 @@ function toGraphQLInputTypeWithRegistry(schema, enumRegistry, inputRegistry, inp
929
743
  cache
930
744
  );
931
745
  }
932
- if (nonUndefinedTypes.length === 1 && nonUndefinedTypes[0]._tag === "TypeLiteral") {
746
+ }
747
+ return void 0;
748
+ }
749
+ function findRegisteredInputForTransformation(memberAst, inputs, inputRegistry, enumRegistry, enums, cache) {
750
+ if (memberAst._tag !== "Transformation") return void 0;
751
+ const innerToAst = memberAst.to;
752
+ const transformedInputName = cache?.astToInputName?.get(innerToAst);
753
+ if (transformedInputName) {
754
+ const inputReg = inputs.get(transformedInputName);
755
+ if (inputReg) {
933
756
  return toGraphQLInputTypeWithRegistry(
934
- S2__namespace.make(nonUndefinedTypes[0]),
757
+ inputReg.schema,
935
758
  enumRegistry,
936
759
  inputRegistry,
937
760
  inputs,
@@ -939,171 +762,210 @@ function toGraphQLInputTypeWithRegistry(schema, enumRegistry, inputRegistry, inp
939
762
  cache
940
763
  );
941
764
  }
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"
765
+ }
766
+ for (const [, inputReg] of inputs) {
767
+ if (inputReg.schema.ast === innerToAst) {
768
+ return toGraphQLInputTypeWithRegistry(
769
+ inputReg.schema,
770
+ enumRegistry,
771
+ inputRegistry,
772
+ inputs,
773
+ enums,
774
+ cache
775
+ );
776
+ }
777
+ }
778
+ return void 0;
779
+ }
780
+ function findRegisteredInputForOptionSome(memberAst, inputs, inputRegistry, enumRegistry, enums, cache) {
781
+ if (memberAst._tag !== "TypeLiteral") return void 0;
782
+ const valueField = memberAst.propertySignatures?.find(
783
+ (p) => String(p.name) === "value"
784
+ );
785
+ if (!valueField) return void 0;
786
+ const valueType = valueField.type;
787
+ const valueInputName = cache?.astToInputName?.get(valueType);
788
+ if (valueInputName) {
789
+ const inputReg = inputs.get(valueInputName);
790
+ if (inputReg) {
791
+ return toGraphQLInputTypeWithRegistry(
792
+ inputReg.schema,
793
+ enumRegistry,
794
+ inputRegistry,
795
+ inputs,
796
+ enums,
797
+ cache
798
+ );
799
+ }
800
+ }
801
+ for (const [, inputReg] of inputs) {
802
+ if (inputReg.schema.ast === valueType) {
803
+ return toGraphQLInputTypeWithRegistry(
804
+ inputReg.schema,
805
+ enumRegistry,
806
+ inputRegistry,
807
+ inputs,
808
+ enums,
809
+ cache
810
+ );
811
+ }
812
+ let regAst = inputReg.schema.ast;
813
+ while (regAst._tag === "Transformation") {
814
+ regAst = regAst.to;
815
+ if (regAst === valueType) {
816
+ return toGraphQLInputTypeWithRegistry(
817
+ inputReg.schema,
818
+ enumRegistry,
819
+ inputRegistry,
820
+ inputs,
821
+ enums,
822
+ cache
1001
823
  );
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
824
  }
1067
825
  }
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
- }
826
+ if (regAst._tag === "Declaration" && regAst.typeParameters?.[0] === valueType) {
827
+ return toGraphQLInputTypeWithRegistry(
828
+ inputReg.schema,
829
+ enumRegistry,
830
+ inputRegistry,
831
+ inputs,
832
+ enums,
833
+ cache
834
+ );
1078
835
  }
1079
836
  }
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) {
837
+ const innerResult = toGraphQLInputTypeWithRegistry(
838
+ S2__namespace.make(valueType),
839
+ enumRegistry,
840
+ inputRegistry,
841
+ inputs,
842
+ enums,
843
+ cache
844
+ );
845
+ return innerResult || void 0;
846
+ }
847
+ function handleOptionTransformationForInput(fromAst, toAst, inputs, inputRegistry, enumRegistry, enums, cache) {
848
+ if (!fromAst || fromAst._tag !== "Union") return void 0;
849
+ for (const memberAst of fromAst.types) {
850
+ if (memberAst._tag === "Literal") continue;
851
+ if (memberAst._tag === "UndefinedKeyword") continue;
852
+ const registeredInput = findRegisteredInputForAST(memberAst, inputs, inputRegistry, enumRegistry, enums, cache) || findRegisteredInputForTransformation(memberAst, inputs, inputRegistry, enumRegistry, enums, cache) || findRegisteredInputForOptionSome(memberAst, inputs, inputRegistry, enumRegistry, enums, cache);
853
+ if (registeredInput) return registeredInput;
854
+ }
855
+ return void 0;
856
+ }
857
+ function handleTransformationForInput(ast, inputs, inputRegistry, enumRegistry, enums, cache) {
858
+ const toAst = ast.to;
859
+ const fromAst = ast.from;
860
+ if (isOptionDeclaration2(toAst)) {
861
+ const optionResult = handleOptionTransformationForInput(
862
+ fromAst,
863
+ toAst,
864
+ inputs,
865
+ inputRegistry,
866
+ enumRegistry,
867
+ enums,
868
+ cache
869
+ );
870
+ if (optionResult) return optionResult;
871
+ }
872
+ return toGraphQLInputTypeWithRegistry(
873
+ S2__namespace.make(toAst),
874
+ enumRegistry,
875
+ inputRegistry,
876
+ inputs,
877
+ enums,
878
+ cache
879
+ );
880
+ }
881
+ function findRegisteredInputInUnionMembers(types, inputs, inputRegistry, enumRegistry, enums, cache) {
882
+ for (const memberAst of types) {
883
+ const registeredInput = findRegisteredInputForAST(memberAst, inputs, inputRegistry, enumRegistry, enums, cache) || findRegisteredInputForTransformation(memberAst, inputs, inputRegistry, enumRegistry, enums, cache) || findRegisteredInputForOptionSome(memberAst, inputs, inputRegistry, enumRegistry, enums, cache);
884
+ if (registeredInput) return registeredInput;
885
+ }
886
+ return void 0;
887
+ }
888
+ function handleUnionForInput(ast, inputs, inputRegistry, enumRegistry, enums, cache) {
889
+ const unionAst = ast;
890
+ const nonUndefinedTypes = unionAst.types.filter((t) => t._tag !== "UndefinedKeyword");
891
+ if (nonUndefinedTypes.length === 1) {
892
+ if (nonUndefinedTypes[0]._tag === "Union" || nonUndefinedTypes[0]._tag === "TypeLiteral") {
893
+ return toGraphQLInputTypeWithRegistry(
894
+ S2__namespace.make(nonUndefinedTypes[0]),
895
+ enumRegistry,
896
+ inputRegistry,
897
+ inputs,
898
+ enums,
899
+ cache
900
+ );
901
+ }
902
+ }
903
+ const registeredInput = findRegisteredInputInUnionMembers(
904
+ unionAst.types,
905
+ inputs,
906
+ inputRegistry,
907
+ enumRegistry,
908
+ enums,
909
+ cache
910
+ );
911
+ if (registeredInput) return registeredInput;
912
+ const allLiterals = unionAst.types.every((t) => t._tag === "Literal");
913
+ if (allLiterals) {
914
+ const literalValues = unionAst.types.map((t) => String(t.literal)).sort();
915
+ for (const [enumName] of enums) {
916
+ const enumValues = cache?.enumSortedValues?.get(enumName) ?? [...enums.get(enumName).values].sort();
917
+ if (literalValues.length === enumValues.length && literalValues.every((v, i) => v === enumValues[i])) {
1085
918
  const result = enumRegistry.get(enumName);
1086
919
  if (result) return result;
1087
920
  }
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
- }
921
+ }
922
+ }
923
+ return void 0;
924
+ }
925
+ function handleLiteralForInput(ast, enumRegistry, enums, cache) {
926
+ const literalValue = String(ast.literal);
927
+ if (cache?.literalToEnumName) {
928
+ const enumName = cache.literalToEnumName.get(literalValue);
929
+ if (enumName) {
930
+ return enumRegistry.get(enumName);
931
+ }
932
+ } else {
933
+ for (const [enumName, enumReg] of enums) {
934
+ if (enumReg.values.includes(literalValue)) {
935
+ return enumRegistry.get(enumName);
1094
936
  }
1095
937
  }
1096
938
  }
939
+ return void 0;
940
+ }
941
+ function handleSuspendForInput(ast, inputs, inputRegistry, enumRegistry, enums, cache) {
942
+ const innerAst = ast.f();
943
+ return toGraphQLInputTypeWithRegistry(
944
+ S2__namespace.make(innerAst),
945
+ enumRegistry,
946
+ inputRegistry,
947
+ inputs,
948
+ enums,
949
+ cache
950
+ );
951
+ }
952
+ function toGraphQLInputTypeWithRegistry(schema, enumRegistry, inputRegistry, inputs, enums, cache) {
953
+ const ast = schema.ast;
954
+ const registeredInput = findRegisteredInputType(schema, ast, inputs, inputRegistry, cache);
955
+ if (registeredInput) return registeredInput;
956
+ if (ast._tag === "Transformation") {
957
+ return handleTransformationForInput(ast, inputs, inputRegistry, enumRegistry, enums, cache);
958
+ }
959
+ if (ast._tag === "Union") {
960
+ const unionResult = handleUnionForInput(ast, inputs, inputRegistry, enumRegistry, enums, cache);
961
+ if (unionResult) return unionResult;
962
+ }
963
+ if (ast._tag === "Literal") {
964
+ const literalResult = handleLiteralForInput(ast, enumRegistry, enums, cache);
965
+ if (literalResult) return literalResult;
966
+ }
1097
967
  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
- );
968
+ return handleSuspendForInput(ast, inputs, inputRegistry, enumRegistry, enums, cache);
1107
969
  }
1108
970
  return toGraphQLInputType(schema);
1109
971
  }