@effect-gql/core 1.4.1 → 1.4.3

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
@@ -311,6 +311,14 @@ function buildReverseLookups(ctx) {
311
311
  for (const [typeName, typeReg] of ctx.types) {
312
312
  ctx.schemaToTypeName.set(typeReg.schema, typeName);
313
313
  ctx.astToTypeName.set(typeReg.schema.ast, typeName);
314
+ let ast = typeReg.schema.ast;
315
+ while (ast._tag === "Transformation") {
316
+ ast = ast.to;
317
+ ctx.astToTypeName.set(ast, typeName);
318
+ }
319
+ if (ast._tag === "Declaration" && ast.typeParameters?.[0]) {
320
+ ctx.astToTypeName.set(ast.typeParameters[0], typeName);
321
+ }
314
322
  }
315
323
  }
316
324
  if (!ctx.schemaToInterfaceName) {
@@ -319,6 +327,14 @@ function buildReverseLookups(ctx) {
319
327
  for (const [interfaceName, interfaceReg] of ctx.interfaces) {
320
328
  ctx.schemaToInterfaceName.set(interfaceReg.schema, interfaceName);
321
329
  ctx.astToInterfaceName.set(interfaceReg.schema.ast, interfaceName);
330
+ let ast = interfaceReg.schema.ast;
331
+ while (ast._tag === "Transformation") {
332
+ ast = ast.to;
333
+ ctx.astToInterfaceName.set(ast, interfaceName);
334
+ }
335
+ if (ast._tag === "Declaration" && ast.typeParameters?.[0]) {
336
+ ctx.astToInterfaceName.set(ast.typeParameters[0], interfaceName);
337
+ }
322
338
  }
323
339
  }
324
340
  if (!ctx.schemaToInputName) {
@@ -327,6 +343,14 @@ function buildReverseLookups(ctx) {
327
343
  for (const [inputName, inputReg] of ctx.inputs) {
328
344
  ctx.schemaToInputName.set(inputReg.schema, inputName);
329
345
  ctx.astToInputName.set(inputReg.schema.ast, inputName);
346
+ let ast = inputReg.schema.ast;
347
+ while (ast._tag === "Transformation") {
348
+ ast = ast.to;
349
+ ctx.astToInputName.set(ast, inputName);
350
+ }
351
+ if (ast._tag === "Declaration" && ast.typeParameters?.[0]) {
352
+ ctx.astToInputName.set(ast.typeParameters[0], inputName);
353
+ }
330
354
  }
331
355
  }
332
356
  if (!ctx.enumSortedValues) {
@@ -431,7 +455,27 @@ function getOptionInnerType2(ast) {
431
455
  }
432
456
  function handleTransformationAST(ast, ctx) {
433
457
  const toAst = ast.to;
458
+ const fromAst = ast.from;
434
459
  if (isOptionDeclaration2(toAst)) {
460
+ if (fromAst && fromAst._tag === "Union") {
461
+ for (const memberAst of fromAst.types) {
462
+ if (memberAst._tag === "Literal") continue;
463
+ if (memberAst._tag === "UndefinedKeyword") continue;
464
+ const typeName = ctx.astToTypeName?.get(memberAst);
465
+ if (typeName) {
466
+ const result = ctx.typeRegistry.get(typeName);
467
+ if (result) return result;
468
+ }
469
+ if (memberAst._tag === "Transformation") {
470
+ const innerToAst = memberAst.to;
471
+ const transformedTypeName = ctx.astToTypeName?.get(innerToAst);
472
+ if (transformedTypeName) {
473
+ const result = ctx.typeRegistry.get(transformedTypeName);
474
+ if (result) return result;
475
+ }
476
+ }
477
+ }
478
+ }
435
479
  const innerType = getOptionInnerType2(toAst);
436
480
  if (innerType) {
437
481
  return toGraphQLTypeWithRegistry(S__namespace.make(innerType), ctx);
@@ -459,6 +503,21 @@ function handleUnionAST(ast, ctx) {
459
503
  const unionType2 = findRegisteredUnion(ast.types, ctx);
460
504
  if (unionType2) return unionType2;
461
505
  }
506
+ for (const memberAst of ast.types) {
507
+ const typeName = ctx.astToTypeName?.get(memberAst);
508
+ if (typeName) {
509
+ const result = ctx.typeRegistry.get(typeName);
510
+ if (result) return result;
511
+ }
512
+ if (memberAst._tag === "Transformation") {
513
+ const toAst = memberAst.to;
514
+ const transformedTypeName = ctx.astToTypeName?.get(toAst);
515
+ if (transformedTypeName) {
516
+ const result = ctx.typeRegistry.get(transformedTypeName);
517
+ if (result) return result;
518
+ }
519
+ }
520
+ }
462
521
  if (ast.types.length > 0) {
463
522
  return toGraphQLTypeWithRegistry(S__namespace.make(ast.types[0]), ctx);
464
523
  }
@@ -586,6 +645,14 @@ function buildInputTypeLookupCache(inputs, enums) {
586
645
  for (const [inputName, inputReg] of inputs) {
587
646
  cache.schemaToInputName.set(inputReg.schema, inputName);
588
647
  cache.astToInputName.set(inputReg.schema.ast, inputName);
648
+ let ast = inputReg.schema.ast;
649
+ while (ast._tag === "Transformation") {
650
+ ast = ast.to;
651
+ cache.astToInputName.set(ast, inputName);
652
+ }
653
+ if (ast._tag === "Declaration" && ast.typeParameters?.[0]) {
654
+ cache.astToInputName.set(ast.typeParameters[0], inputName);
655
+ }
589
656
  }
590
657
  for (const [enumName, enumReg] of enums) {
591
658
  cache.enumSortedValues.set(enumName, [...enumReg.values].sort());
@@ -613,6 +680,26 @@ function toGraphQLInputTypeWithRegistry(schema, enumRegistry, inputRegistry, inp
613
680
  }
614
681
  if (ast._tag === "Transformation") {
615
682
  const toAst = ast.to;
683
+ const fromAst = ast.from;
684
+ if (isOptionDeclaration2(toAst) && fromAst && fromAst._tag === "Union") {
685
+ for (const memberAst of fromAst.types) {
686
+ if (memberAst._tag === "Literal") continue;
687
+ if (memberAst._tag === "UndefinedKeyword") continue;
688
+ const inputName = cache?.astToInputName?.get(memberAst);
689
+ if (inputName) {
690
+ const result = inputRegistry.get(inputName);
691
+ if (result) return result;
692
+ }
693
+ if (memberAst._tag === "Transformation") {
694
+ const innerToAst = memberAst.to;
695
+ const transformedInputName = cache?.astToInputName?.get(innerToAst);
696
+ if (transformedInputName) {
697
+ const result = inputRegistry.get(transformedInputName);
698
+ if (result) return result;
699
+ }
700
+ }
701
+ }
702
+ }
616
703
  return toGraphQLInputTypeWithRegistry(
617
704
  S__namespace.make(toAst),
618
705
  enumRegistry,
@@ -645,6 +732,21 @@ function toGraphQLInputTypeWithRegistry(schema, enumRegistry, inputRegistry, inp
645
732
  cache
646
733
  );
647
734
  }
735
+ for (const memberAst of unionAst.types) {
736
+ const inputName = cache?.astToInputName?.get(memberAst);
737
+ if (inputName) {
738
+ const result = inputRegistry.get(inputName);
739
+ if (result) return result;
740
+ }
741
+ if (memberAst._tag === "Transformation") {
742
+ const toAst = memberAst.to;
743
+ const transformedInputName = cache?.astToInputName?.get(toAst);
744
+ if (transformedInputName) {
745
+ const result = inputRegistry.get(transformedInputName);
746
+ if (result) return result;
747
+ }
748
+ }
749
+ }
648
750
  const allLiterals = unionAst.types.every((t) => t._tag === "Literal");
649
751
  if (allLiterals) {
650
752
  const literalValues = unionAst.types.map((t) => String(t.literal)).sort();