@effect-gql/core 1.4.0 → 1.4.2

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
@@ -103,6 +103,7 @@ var toGraphQLType = (schema) => {
103
103
  const fields = {};
104
104
  for (const field2 of ast.propertySignatures) {
105
105
  const fieldName = String(field2.name);
106
+ if (fieldName === "_tag") continue;
106
107
  const fieldSchema = S__namespace.make(field2.type);
107
108
  let fieldType = toGraphQLType(fieldSchema);
108
109
  if (!field2.isOptional) {
@@ -178,6 +179,7 @@ var toGraphQLInputType = (schema) => {
178
179
  const fields = {};
179
180
  for (const field2 of ast.propertySignatures) {
180
181
  const fieldName = String(field2.name);
182
+ if (fieldName === "_tag") continue;
181
183
  const fieldSchema = S__namespace.make(field2.type);
182
184
  let fieldType = toGraphQLInputType(fieldSchema);
183
185
  if (!field2.isOptional) {
@@ -240,6 +242,7 @@ var toGraphQLObjectType = (name, schema, additionalFields) => {
240
242
  const fields = {};
241
243
  for (const field2 of ast.propertySignatures) {
242
244
  const fieldName = String(field2.name);
245
+ if (fieldName === "_tag") continue;
243
246
  const fieldSchema = S__namespace.make(field2.type);
244
247
  let fieldType = toGraphQLType(fieldSchema);
245
248
  if (!field2.isOptional) {
@@ -271,6 +274,7 @@ var toGraphQLArgs = (schema) => {
271
274
  const args = {};
272
275
  for (const field2 of ast.propertySignatures) {
273
276
  const fieldName = String(field2.name);
277
+ if (fieldName === "_tag") continue;
274
278
  const fieldSchema = S__namespace.make(field2.type);
275
279
  let fieldType = toGraphQLInputType(fieldSchema);
276
280
  if (!field2.isOptional) {
@@ -427,7 +431,27 @@ function getOptionInnerType2(ast) {
427
431
  }
428
432
  function handleTransformationAST(ast, ctx) {
429
433
  const toAst = ast.to;
434
+ const fromAst = ast.from;
430
435
  if (isOptionDeclaration2(toAst)) {
436
+ if (fromAst && fromAst._tag === "Union") {
437
+ for (const memberAst of fromAst.types) {
438
+ if (memberAst._tag === "Literal") continue;
439
+ if (memberAst._tag === "UndefinedKeyword") continue;
440
+ const typeName = ctx.astToTypeName?.get(memberAst);
441
+ if (typeName) {
442
+ const result = ctx.typeRegistry.get(typeName);
443
+ if (result) return result;
444
+ }
445
+ if (memberAst._tag === "Transformation") {
446
+ const innerToAst = memberAst.to;
447
+ const transformedTypeName = ctx.astToTypeName?.get(innerToAst);
448
+ if (transformedTypeName) {
449
+ const result = ctx.typeRegistry.get(transformedTypeName);
450
+ if (result) return result;
451
+ }
452
+ }
453
+ }
454
+ }
431
455
  const innerType = getOptionInnerType2(toAst);
432
456
  if (innerType) {
433
457
  return toGraphQLTypeWithRegistry(S__namespace.make(innerType), ctx);
@@ -455,6 +479,21 @@ function handleUnionAST(ast, ctx) {
455
479
  const unionType2 = findRegisteredUnion(ast.types, ctx);
456
480
  if (unionType2) return unionType2;
457
481
  }
482
+ for (const memberAst of ast.types) {
483
+ const typeName = ctx.astToTypeName?.get(memberAst);
484
+ if (typeName) {
485
+ const result = ctx.typeRegistry.get(typeName);
486
+ if (result) return result;
487
+ }
488
+ if (memberAst._tag === "Transformation") {
489
+ const toAst = memberAst.to;
490
+ const transformedTypeName = ctx.astToTypeName?.get(toAst);
491
+ if (transformedTypeName) {
492
+ const result = ctx.typeRegistry.get(transformedTypeName);
493
+ if (result) return result;
494
+ }
495
+ }
496
+ }
458
497
  if (ast.types.length > 0) {
459
498
  return toGraphQLTypeWithRegistry(S__namespace.make(ast.types[0]), ctx);
460
499
  }
@@ -518,14 +557,21 @@ function schemaToFields(schema, ctx) {
518
557
  }
519
558
  if (ast._tag === "Declaration") {
520
559
  const typeParams = ast.typeParameters;
521
- if (typeParams && typeParams.length > 0 && typeParams[0]._tag === "TypeLiteral") {
522
- ast = typeParams[0];
560
+ if (typeParams && typeParams.length > 0) {
561
+ let innerAst = typeParams[0];
562
+ while (innerAst._tag === "Transformation") {
563
+ innerAst = innerAst.to;
564
+ }
565
+ if (innerAst._tag === "TypeLiteral") {
566
+ ast = innerAst;
567
+ }
523
568
  }
524
569
  }
525
570
  if (ast._tag === "TypeLiteral") {
526
571
  const fields = {};
527
572
  for (const field2 of ast.propertySignatures) {
528
573
  const fieldName = String(field2.name);
574
+ if (fieldName === "_tag") continue;
529
575
  const fieldSchema = S__namespace.make(field2.type);
530
576
  let fieldType = toGraphQLTypeWithRegistry(fieldSchema, ctx);
531
577
  if (!field2.isOptional) {
@@ -538,11 +584,15 @@ function schemaToFields(schema, ctx) {
538
584
  return {};
539
585
  }
540
586
  function schemaToInputFields(schema, enumRegistry, inputRegistry, inputs, enums, cache) {
541
- const ast = schema.ast;
587
+ let ast = schema.ast;
588
+ while (ast._tag === "Transformation") {
589
+ ast = ast.to;
590
+ }
542
591
  if (ast._tag === "TypeLiteral") {
543
592
  const fields = {};
544
593
  for (const field2 of ast.propertySignatures) {
545
594
  const fieldName = String(field2.name);
595
+ if (fieldName === "_tag") continue;
546
596
  const fieldSchema = S__namespace.make(field2.type);
547
597
  let fieldType = toGraphQLInputTypeWithRegistry(
548
598
  fieldSchema,
@@ -582,17 +632,6 @@ function buildInputTypeLookupCache(inputs, enums) {
582
632
  }
583
633
  function toGraphQLInputTypeWithRegistry(schema, enumRegistry, inputRegistry, inputs, enums, cache) {
584
634
  const ast = schema.ast;
585
- if (ast._tag === "Transformation") {
586
- const toAst = ast.to;
587
- return toGraphQLInputTypeWithRegistry(
588
- S__namespace.make(toAst),
589
- enumRegistry,
590
- inputRegistry,
591
- inputs,
592
- enums,
593
- cache
594
- );
595
- }
596
635
  if (cache?.schemaToInputName || cache?.astToInputName) {
597
636
  const inputName = cache.schemaToInputName?.get(schema) ?? cache.astToInputName?.get(ast);
598
637
  if (inputName) {
@@ -607,6 +646,37 @@ function toGraphQLInputTypeWithRegistry(schema, enumRegistry, inputRegistry, inp
607
646
  }
608
647
  }
609
648
  }
649
+ if (ast._tag === "Transformation") {
650
+ const toAst = ast.to;
651
+ const fromAst = ast.from;
652
+ if (isOptionDeclaration2(toAst) && fromAst && fromAst._tag === "Union") {
653
+ for (const memberAst of fromAst.types) {
654
+ if (memberAst._tag === "Literal") continue;
655
+ if (memberAst._tag === "UndefinedKeyword") continue;
656
+ const inputName = cache?.astToInputName?.get(memberAst);
657
+ if (inputName) {
658
+ const result = inputRegistry.get(inputName);
659
+ if (result) return result;
660
+ }
661
+ if (memberAst._tag === "Transformation") {
662
+ const innerToAst = memberAst.to;
663
+ const transformedInputName = cache?.astToInputName?.get(innerToAst);
664
+ if (transformedInputName) {
665
+ const result = inputRegistry.get(transformedInputName);
666
+ if (result) return result;
667
+ }
668
+ }
669
+ }
670
+ }
671
+ return toGraphQLInputTypeWithRegistry(
672
+ S__namespace.make(toAst),
673
+ enumRegistry,
674
+ inputRegistry,
675
+ inputs,
676
+ enums,
677
+ cache
678
+ );
679
+ }
610
680
  if (ast._tag === "Union") {
611
681
  const unionAst = ast;
612
682
  const nonUndefinedTypes = unionAst.types.filter((t) => t._tag !== "UndefinedKeyword");
@@ -630,6 +700,21 @@ function toGraphQLInputTypeWithRegistry(schema, enumRegistry, inputRegistry, inp
630
700
  cache
631
701
  );
632
702
  }
703
+ for (const memberAst of unionAst.types) {
704
+ const inputName = cache?.astToInputName?.get(memberAst);
705
+ if (inputName) {
706
+ const result = inputRegistry.get(inputName);
707
+ if (result) return result;
708
+ }
709
+ if (memberAst._tag === "Transformation") {
710
+ const toAst = memberAst.to;
711
+ const transformedInputName = cache?.astToInputName?.get(toAst);
712
+ if (transformedInputName) {
713
+ const result = inputRegistry.get(transformedInputName);
714
+ if (result) return result;
715
+ }
716
+ }
717
+ }
633
718
  const allLiterals = unionAst.types.every((t) => t._tag === "Literal");
634
719
  if (allLiterals) {
635
720
  const literalValues = unionAst.types.map((t) => String(t.literal)).sort();
@@ -678,6 +763,7 @@ function toGraphQLArgsWithRegistry(schema, enumRegistry, inputRegistry, inputs,
678
763
  const args = {};
679
764
  for (const field2 of ast.propertySignatures) {
680
765
  const fieldName = String(field2.name);
766
+ if (fieldName === "_tag") continue;
681
767
  const fieldSchema = S__namespace.make(field2.type);
682
768
  let fieldType = toGraphQLInputTypeWithRegistry(
683
769
  fieldSchema,