@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.js CHANGED
@@ -78,6 +78,7 @@ var toGraphQLType = (schema) => {
78
78
  const fields = {};
79
79
  for (const field2 of ast.propertySignatures) {
80
80
  const fieldName = String(field2.name);
81
+ if (fieldName === "_tag") continue;
81
82
  const fieldSchema = S.make(field2.type);
82
83
  let fieldType = toGraphQLType(fieldSchema);
83
84
  if (!field2.isOptional) {
@@ -153,6 +154,7 @@ var toGraphQLInputType = (schema) => {
153
154
  const fields = {};
154
155
  for (const field2 of ast.propertySignatures) {
155
156
  const fieldName = String(field2.name);
157
+ if (fieldName === "_tag") continue;
156
158
  const fieldSchema = S.make(field2.type);
157
159
  let fieldType = toGraphQLInputType(fieldSchema);
158
160
  if (!field2.isOptional) {
@@ -215,6 +217,7 @@ var toGraphQLObjectType = (name, schema, additionalFields) => {
215
217
  const fields = {};
216
218
  for (const field2 of ast.propertySignatures) {
217
219
  const fieldName = String(field2.name);
220
+ if (fieldName === "_tag") continue;
218
221
  const fieldSchema = S.make(field2.type);
219
222
  let fieldType = toGraphQLType(fieldSchema);
220
223
  if (!field2.isOptional) {
@@ -246,6 +249,7 @@ var toGraphQLArgs = (schema) => {
246
249
  const args = {};
247
250
  for (const field2 of ast.propertySignatures) {
248
251
  const fieldName = String(field2.name);
252
+ if (fieldName === "_tag") continue;
249
253
  const fieldSchema = S.make(field2.type);
250
254
  let fieldType = toGraphQLInputType(fieldSchema);
251
255
  if (!field2.isOptional) {
@@ -402,7 +406,27 @@ function getOptionInnerType2(ast) {
402
406
  }
403
407
  function handleTransformationAST(ast, ctx) {
404
408
  const toAst = ast.to;
409
+ const fromAst = ast.from;
405
410
  if (isOptionDeclaration2(toAst)) {
411
+ if (fromAst && fromAst._tag === "Union") {
412
+ for (const memberAst of fromAst.types) {
413
+ if (memberAst._tag === "Literal") continue;
414
+ if (memberAst._tag === "UndefinedKeyword") continue;
415
+ const typeName = ctx.astToTypeName?.get(memberAst);
416
+ if (typeName) {
417
+ const result = ctx.typeRegistry.get(typeName);
418
+ if (result) return result;
419
+ }
420
+ if (memberAst._tag === "Transformation") {
421
+ const innerToAst = memberAst.to;
422
+ const transformedTypeName = ctx.astToTypeName?.get(innerToAst);
423
+ if (transformedTypeName) {
424
+ const result = ctx.typeRegistry.get(transformedTypeName);
425
+ if (result) return result;
426
+ }
427
+ }
428
+ }
429
+ }
406
430
  const innerType = getOptionInnerType2(toAst);
407
431
  if (innerType) {
408
432
  return toGraphQLTypeWithRegistry(S.make(innerType), ctx);
@@ -430,6 +454,21 @@ function handleUnionAST(ast, ctx) {
430
454
  const unionType2 = findRegisteredUnion(ast.types, ctx);
431
455
  if (unionType2) return unionType2;
432
456
  }
457
+ for (const memberAst of ast.types) {
458
+ const typeName = ctx.astToTypeName?.get(memberAst);
459
+ if (typeName) {
460
+ const result = ctx.typeRegistry.get(typeName);
461
+ if (result) return result;
462
+ }
463
+ if (memberAst._tag === "Transformation") {
464
+ const toAst = memberAst.to;
465
+ const transformedTypeName = ctx.astToTypeName?.get(toAst);
466
+ if (transformedTypeName) {
467
+ const result = ctx.typeRegistry.get(transformedTypeName);
468
+ if (result) return result;
469
+ }
470
+ }
471
+ }
433
472
  if (ast.types.length > 0) {
434
473
  return toGraphQLTypeWithRegistry(S.make(ast.types[0]), ctx);
435
474
  }
@@ -493,14 +532,21 @@ function schemaToFields(schema, ctx) {
493
532
  }
494
533
  if (ast._tag === "Declaration") {
495
534
  const typeParams = ast.typeParameters;
496
- if (typeParams && typeParams.length > 0 && typeParams[0]._tag === "TypeLiteral") {
497
- ast = typeParams[0];
535
+ if (typeParams && typeParams.length > 0) {
536
+ let innerAst = typeParams[0];
537
+ while (innerAst._tag === "Transformation") {
538
+ innerAst = innerAst.to;
539
+ }
540
+ if (innerAst._tag === "TypeLiteral") {
541
+ ast = innerAst;
542
+ }
498
543
  }
499
544
  }
500
545
  if (ast._tag === "TypeLiteral") {
501
546
  const fields = {};
502
547
  for (const field2 of ast.propertySignatures) {
503
548
  const fieldName = String(field2.name);
549
+ if (fieldName === "_tag") continue;
504
550
  const fieldSchema = S.make(field2.type);
505
551
  let fieldType = toGraphQLTypeWithRegistry(fieldSchema, ctx);
506
552
  if (!field2.isOptional) {
@@ -513,11 +559,15 @@ function schemaToFields(schema, ctx) {
513
559
  return {};
514
560
  }
515
561
  function schemaToInputFields(schema, enumRegistry, inputRegistry, inputs, enums, cache) {
516
- const ast = schema.ast;
562
+ let ast = schema.ast;
563
+ while (ast._tag === "Transformation") {
564
+ ast = ast.to;
565
+ }
517
566
  if (ast._tag === "TypeLiteral") {
518
567
  const fields = {};
519
568
  for (const field2 of ast.propertySignatures) {
520
569
  const fieldName = String(field2.name);
570
+ if (fieldName === "_tag") continue;
521
571
  const fieldSchema = S.make(field2.type);
522
572
  let fieldType = toGraphQLInputTypeWithRegistry(
523
573
  fieldSchema,
@@ -557,17 +607,6 @@ function buildInputTypeLookupCache(inputs, enums) {
557
607
  }
558
608
  function toGraphQLInputTypeWithRegistry(schema, enumRegistry, inputRegistry, inputs, enums, cache) {
559
609
  const ast = schema.ast;
560
- if (ast._tag === "Transformation") {
561
- const toAst = ast.to;
562
- return toGraphQLInputTypeWithRegistry(
563
- S.make(toAst),
564
- enumRegistry,
565
- inputRegistry,
566
- inputs,
567
- enums,
568
- cache
569
- );
570
- }
571
610
  if (cache?.schemaToInputName || cache?.astToInputName) {
572
611
  const inputName = cache.schemaToInputName?.get(schema) ?? cache.astToInputName?.get(ast);
573
612
  if (inputName) {
@@ -582,6 +621,37 @@ function toGraphQLInputTypeWithRegistry(schema, enumRegistry, inputRegistry, inp
582
621
  }
583
622
  }
584
623
  }
624
+ if (ast._tag === "Transformation") {
625
+ const toAst = ast.to;
626
+ const fromAst = ast.from;
627
+ if (isOptionDeclaration2(toAst) && fromAst && fromAst._tag === "Union") {
628
+ for (const memberAst of fromAst.types) {
629
+ if (memberAst._tag === "Literal") continue;
630
+ if (memberAst._tag === "UndefinedKeyword") continue;
631
+ const inputName = cache?.astToInputName?.get(memberAst);
632
+ if (inputName) {
633
+ const result = inputRegistry.get(inputName);
634
+ if (result) return result;
635
+ }
636
+ if (memberAst._tag === "Transformation") {
637
+ const innerToAst = memberAst.to;
638
+ const transformedInputName = cache?.astToInputName?.get(innerToAst);
639
+ if (transformedInputName) {
640
+ const result = inputRegistry.get(transformedInputName);
641
+ if (result) return result;
642
+ }
643
+ }
644
+ }
645
+ }
646
+ return toGraphQLInputTypeWithRegistry(
647
+ S.make(toAst),
648
+ enumRegistry,
649
+ inputRegistry,
650
+ inputs,
651
+ enums,
652
+ cache
653
+ );
654
+ }
585
655
  if (ast._tag === "Union") {
586
656
  const unionAst = ast;
587
657
  const nonUndefinedTypes = unionAst.types.filter((t) => t._tag !== "UndefinedKeyword");
@@ -605,6 +675,21 @@ function toGraphQLInputTypeWithRegistry(schema, enumRegistry, inputRegistry, inp
605
675
  cache
606
676
  );
607
677
  }
678
+ for (const memberAst of unionAst.types) {
679
+ const inputName = cache?.astToInputName?.get(memberAst);
680
+ if (inputName) {
681
+ const result = inputRegistry.get(inputName);
682
+ if (result) return result;
683
+ }
684
+ if (memberAst._tag === "Transformation") {
685
+ const toAst = memberAst.to;
686
+ const transformedInputName = cache?.astToInputName?.get(toAst);
687
+ if (transformedInputName) {
688
+ const result = inputRegistry.get(transformedInputName);
689
+ if (result) return result;
690
+ }
691
+ }
692
+ }
608
693
  const allLiterals = unionAst.types.every((t) => t._tag === "Literal");
609
694
  if (allLiterals) {
610
695
  const literalValues = unionAst.types.map((t) => String(t.literal)).sort();
@@ -653,6 +738,7 @@ function toGraphQLArgsWithRegistry(schema, enumRegistry, inputRegistry, inputs,
653
738
  const args = {};
654
739
  for (const field2 of ast.propertySignatures) {
655
740
  const fieldName = String(field2.name);
741
+ if (fieldName === "_tag") continue;
656
742
  const fieldSchema = S.make(field2.type);
657
743
  let fieldType = toGraphQLInputTypeWithRegistry(
658
744
  fieldSchema,