@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/builder/index.cjs +99 -14
- package/builder/index.cjs.map +1 -1
- package/builder/index.js +99 -14
- package/builder/index.js.map +1 -1
- package/index.cjs +100 -14
- package/index.cjs.map +1 -1
- package/index.js +100 -14
- package/index.js.map +1 -1
- package/package.json +1 -1
package/builder/index.js
CHANGED
|
@@ -76,6 +76,7 @@ var toGraphQLType = (schema) => {
|
|
|
76
76
|
const fields = {};
|
|
77
77
|
for (const field2 of ast.propertySignatures) {
|
|
78
78
|
const fieldName = String(field2.name);
|
|
79
|
+
if (fieldName === "_tag") continue;
|
|
79
80
|
const fieldSchema = S.make(field2.type);
|
|
80
81
|
let fieldType = toGraphQLType(fieldSchema);
|
|
81
82
|
if (!field2.isOptional) {
|
|
@@ -151,6 +152,7 @@ var toGraphQLInputType = (schema) => {
|
|
|
151
152
|
const fields = {};
|
|
152
153
|
for (const field2 of ast.propertySignatures) {
|
|
153
154
|
const fieldName = String(field2.name);
|
|
155
|
+
if (fieldName === "_tag") continue;
|
|
154
156
|
const fieldSchema = S.make(field2.type);
|
|
155
157
|
let fieldType = toGraphQLInputType(fieldSchema);
|
|
156
158
|
if (!field2.isOptional) {
|
|
@@ -201,6 +203,7 @@ var toGraphQLArgs = (schema) => {
|
|
|
201
203
|
const args = {};
|
|
202
204
|
for (const field2 of ast.propertySignatures) {
|
|
203
205
|
const fieldName = String(field2.name);
|
|
206
|
+
if (fieldName === "_tag") continue;
|
|
204
207
|
const fieldSchema = S.make(field2.type);
|
|
205
208
|
let fieldType = toGraphQLInputType(fieldSchema);
|
|
206
209
|
if (!field2.isOptional) {
|
|
@@ -357,7 +360,27 @@ function getOptionInnerType2(ast) {
|
|
|
357
360
|
}
|
|
358
361
|
function handleTransformationAST(ast, ctx) {
|
|
359
362
|
const toAst = ast.to;
|
|
363
|
+
const fromAst = ast.from;
|
|
360
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
|
+
}
|
|
361
384
|
const innerType = getOptionInnerType2(toAst);
|
|
362
385
|
if (innerType) {
|
|
363
386
|
return toGraphQLTypeWithRegistry(S.make(innerType), ctx);
|
|
@@ -385,6 +408,21 @@ function handleUnionAST(ast, ctx) {
|
|
|
385
408
|
const unionType2 = findRegisteredUnion(ast.types, ctx);
|
|
386
409
|
if (unionType2) return unionType2;
|
|
387
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
|
+
}
|
|
388
426
|
if (ast.types.length > 0) {
|
|
389
427
|
return toGraphQLTypeWithRegistry(S.make(ast.types[0]), ctx);
|
|
390
428
|
}
|
|
@@ -448,14 +486,21 @@ function schemaToFields(schema, ctx) {
|
|
|
448
486
|
}
|
|
449
487
|
if (ast._tag === "Declaration") {
|
|
450
488
|
const typeParams = ast.typeParameters;
|
|
451
|
-
if (typeParams && typeParams.length > 0
|
|
452
|
-
|
|
489
|
+
if (typeParams && typeParams.length > 0) {
|
|
490
|
+
let innerAst = typeParams[0];
|
|
491
|
+
while (innerAst._tag === "Transformation") {
|
|
492
|
+
innerAst = innerAst.to;
|
|
493
|
+
}
|
|
494
|
+
if (innerAst._tag === "TypeLiteral") {
|
|
495
|
+
ast = innerAst;
|
|
496
|
+
}
|
|
453
497
|
}
|
|
454
498
|
}
|
|
455
499
|
if (ast._tag === "TypeLiteral") {
|
|
456
500
|
const fields = {};
|
|
457
501
|
for (const field2 of ast.propertySignatures) {
|
|
458
502
|
const fieldName = String(field2.name);
|
|
503
|
+
if (fieldName === "_tag") continue;
|
|
459
504
|
const fieldSchema = S.make(field2.type);
|
|
460
505
|
let fieldType = toGraphQLTypeWithRegistry(fieldSchema, ctx);
|
|
461
506
|
if (!field2.isOptional) {
|
|
@@ -468,11 +513,15 @@ function schemaToFields(schema, ctx) {
|
|
|
468
513
|
return {};
|
|
469
514
|
}
|
|
470
515
|
function schemaToInputFields(schema, enumRegistry, inputRegistry, inputs, enums, cache) {
|
|
471
|
-
|
|
516
|
+
let ast = schema.ast;
|
|
517
|
+
while (ast._tag === "Transformation") {
|
|
518
|
+
ast = ast.to;
|
|
519
|
+
}
|
|
472
520
|
if (ast._tag === "TypeLiteral") {
|
|
473
521
|
const fields = {};
|
|
474
522
|
for (const field2 of ast.propertySignatures) {
|
|
475
523
|
const fieldName = String(field2.name);
|
|
524
|
+
if (fieldName === "_tag") continue;
|
|
476
525
|
const fieldSchema = S.make(field2.type);
|
|
477
526
|
let fieldType = toGraphQLInputTypeWithRegistry(
|
|
478
527
|
fieldSchema,
|
|
@@ -512,17 +561,6 @@ function buildInputTypeLookupCache(inputs, enums) {
|
|
|
512
561
|
}
|
|
513
562
|
function toGraphQLInputTypeWithRegistry(schema, enumRegistry, inputRegistry, inputs, enums, cache) {
|
|
514
563
|
const ast = schema.ast;
|
|
515
|
-
if (ast._tag === "Transformation") {
|
|
516
|
-
const toAst = ast.to;
|
|
517
|
-
return toGraphQLInputTypeWithRegistry(
|
|
518
|
-
S.make(toAst),
|
|
519
|
-
enumRegistry,
|
|
520
|
-
inputRegistry,
|
|
521
|
-
inputs,
|
|
522
|
-
enums,
|
|
523
|
-
cache
|
|
524
|
-
);
|
|
525
|
-
}
|
|
526
564
|
if (cache?.schemaToInputName || cache?.astToInputName) {
|
|
527
565
|
const inputName = cache.schemaToInputName?.get(schema) ?? cache.astToInputName?.get(ast);
|
|
528
566
|
if (inputName) {
|
|
@@ -537,6 +575,37 @@ function toGraphQLInputTypeWithRegistry(schema, enumRegistry, inputRegistry, inp
|
|
|
537
575
|
}
|
|
538
576
|
}
|
|
539
577
|
}
|
|
578
|
+
if (ast._tag === "Transformation") {
|
|
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
|
+
}
|
|
600
|
+
return toGraphQLInputTypeWithRegistry(
|
|
601
|
+
S.make(toAst),
|
|
602
|
+
enumRegistry,
|
|
603
|
+
inputRegistry,
|
|
604
|
+
inputs,
|
|
605
|
+
enums,
|
|
606
|
+
cache
|
|
607
|
+
);
|
|
608
|
+
}
|
|
540
609
|
if (ast._tag === "Union") {
|
|
541
610
|
const unionAst = ast;
|
|
542
611
|
const nonUndefinedTypes = unionAst.types.filter((t) => t._tag !== "UndefinedKeyword");
|
|
@@ -560,6 +629,21 @@ function toGraphQLInputTypeWithRegistry(schema, enumRegistry, inputRegistry, inp
|
|
|
560
629
|
cache
|
|
561
630
|
);
|
|
562
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
|
+
}
|
|
563
647
|
const allLiterals = unionAst.types.every((t) => t._tag === "Literal");
|
|
564
648
|
if (allLiterals) {
|
|
565
649
|
const literalValues = unionAst.types.map((t) => String(t.literal)).sort();
|
|
@@ -608,6 +692,7 @@ function toGraphQLArgsWithRegistry(schema, enumRegistry, inputRegistry, inputs,
|
|
|
608
692
|
const args = {};
|
|
609
693
|
for (const field2 of ast.propertySignatures) {
|
|
610
694
|
const fieldName = String(field2.name);
|
|
695
|
+
if (fieldName === "_tag") continue;
|
|
611
696
|
const fieldSchema = S.make(field2.type);
|
|
612
697
|
let fieldType = toGraphQLInputTypeWithRegistry(
|
|
613
698
|
fieldSchema,
|