@effect-gql/core 1.4.1 → 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/builder/index.js CHANGED
@@ -360,7 +360,27 @@ function getOptionInnerType2(ast) {
360
360
  }
361
361
  function handleTransformationAST(ast, ctx) {
362
362
  const toAst = ast.to;
363
+ const fromAst = ast.from;
363
364
  if (isOptionDeclaration2(toAst)) {
365
+ if (fromAst && fromAst._tag === "Union") {
366
+ for (const memberAst of fromAst.types) {
367
+ if (memberAst._tag === "Literal") continue;
368
+ if (memberAst._tag === "UndefinedKeyword") continue;
369
+ const typeName = ctx.astToTypeName?.get(memberAst);
370
+ if (typeName) {
371
+ const result = ctx.typeRegistry.get(typeName);
372
+ if (result) return result;
373
+ }
374
+ if (memberAst._tag === "Transformation") {
375
+ const innerToAst = memberAst.to;
376
+ const transformedTypeName = ctx.astToTypeName?.get(innerToAst);
377
+ if (transformedTypeName) {
378
+ const result = ctx.typeRegistry.get(transformedTypeName);
379
+ if (result) return result;
380
+ }
381
+ }
382
+ }
383
+ }
364
384
  const innerType = getOptionInnerType2(toAst);
365
385
  if (innerType) {
366
386
  return toGraphQLTypeWithRegistry(S.make(innerType), ctx);
@@ -388,6 +408,21 @@ function handleUnionAST(ast, ctx) {
388
408
  const unionType2 = findRegisteredUnion(ast.types, ctx);
389
409
  if (unionType2) return unionType2;
390
410
  }
411
+ for (const memberAst of ast.types) {
412
+ const typeName = ctx.astToTypeName?.get(memberAst);
413
+ if (typeName) {
414
+ const result = ctx.typeRegistry.get(typeName);
415
+ if (result) return result;
416
+ }
417
+ if (memberAst._tag === "Transformation") {
418
+ const toAst = memberAst.to;
419
+ const transformedTypeName = ctx.astToTypeName?.get(toAst);
420
+ if (transformedTypeName) {
421
+ const result = ctx.typeRegistry.get(transformedTypeName);
422
+ if (result) return result;
423
+ }
424
+ }
425
+ }
391
426
  if (ast.types.length > 0) {
392
427
  return toGraphQLTypeWithRegistry(S.make(ast.types[0]), ctx);
393
428
  }
@@ -542,6 +577,26 @@ function toGraphQLInputTypeWithRegistry(schema, enumRegistry, inputRegistry, inp
542
577
  }
543
578
  if (ast._tag === "Transformation") {
544
579
  const toAst = ast.to;
580
+ const fromAst = ast.from;
581
+ if (isOptionDeclaration2(toAst) && fromAst && fromAst._tag === "Union") {
582
+ for (const memberAst of fromAst.types) {
583
+ if (memberAst._tag === "Literal") continue;
584
+ if (memberAst._tag === "UndefinedKeyword") continue;
585
+ const inputName = cache?.astToInputName?.get(memberAst);
586
+ if (inputName) {
587
+ const result = inputRegistry.get(inputName);
588
+ if (result) return result;
589
+ }
590
+ if (memberAst._tag === "Transformation") {
591
+ const innerToAst = memberAst.to;
592
+ const transformedInputName = cache?.astToInputName?.get(innerToAst);
593
+ if (transformedInputName) {
594
+ const result = inputRegistry.get(transformedInputName);
595
+ if (result) return result;
596
+ }
597
+ }
598
+ }
599
+ }
545
600
  return toGraphQLInputTypeWithRegistry(
546
601
  S.make(toAst),
547
602
  enumRegistry,
@@ -574,6 +629,21 @@ function toGraphQLInputTypeWithRegistry(schema, enumRegistry, inputRegistry, inp
574
629
  cache
575
630
  );
576
631
  }
632
+ for (const memberAst of unionAst.types) {
633
+ const inputName = cache?.astToInputName?.get(memberAst);
634
+ if (inputName) {
635
+ const result = inputRegistry.get(inputName);
636
+ if (result) return result;
637
+ }
638
+ if (memberAst._tag === "Transformation") {
639
+ const toAst = memberAst.to;
640
+ const transformedInputName = cache?.astToInputName?.get(toAst);
641
+ if (transformedInputName) {
642
+ const result = inputRegistry.get(transformedInputName);
643
+ if (result) return result;
644
+ }
645
+ }
646
+ }
577
647
  const allLiterals = unionAst.types.every((t) => t._tag === "Literal");
578
648
  if (allLiterals) {
579
649
  const literalValues = unionAst.types.map((t) => String(t.literal)).sort();