@effect-gql/core 1.4.3 → 1.4.4
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 +88 -41
- package/builder/index.cjs.map +1 -1
- package/builder/index.js +87 -40
- package/builder/index.js.map +1 -1
- package/index.cjs +89 -42
- package/index.cjs.map +1 -1
- package/index.js +88 -41
- package/index.js.map +1 -1
- package/package.json +1 -1
package/builder/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { GraphQLDirective, GraphQLEnumType, GraphQLInputObjectType, GraphQLInterfaceType, GraphQLObjectType, GraphQLUnionType, GraphQLSchema, GraphQLNonNull, GraphQLString, GraphQLFloat, GraphQLBoolean, GraphQLInt, GraphQLList, parse, GraphQLError, validate, execute as execute$1 } from 'graphql';
|
|
2
2
|
export { DirectiveLocation } from 'graphql';
|
|
3
3
|
import { Pipeable, Context, Runtime, Effect, Queue, Option, Stream, Fiber, Ref } from 'effect';
|
|
4
|
-
import * as
|
|
4
|
+
import * as S2 from 'effect/Schema';
|
|
5
5
|
import * as AST from 'effect/SchemaAST';
|
|
6
6
|
|
|
7
7
|
// src/builder/index.ts
|
|
@@ -56,7 +56,7 @@ var toGraphQLType = (schema) => {
|
|
|
56
56
|
if (isIntegerType(ast)) {
|
|
57
57
|
return GraphQLInt;
|
|
58
58
|
}
|
|
59
|
-
return toGraphQLType(
|
|
59
|
+
return toGraphQLType(S2.make(ast.from));
|
|
60
60
|
}
|
|
61
61
|
if (ast._tag === "Literal") {
|
|
62
62
|
if (typeof ast.literal === "string") return GraphQLString;
|
|
@@ -68,7 +68,7 @@ var toGraphQLType = (schema) => {
|
|
|
68
68
|
if (ast._tag === "TupleType") {
|
|
69
69
|
const elements = ast.elements;
|
|
70
70
|
if (elements.length > 0) {
|
|
71
|
-
const elementSchema =
|
|
71
|
+
const elementSchema = S2.make(elements[0].type);
|
|
72
72
|
return new GraphQLList(toGraphQLType(elementSchema));
|
|
73
73
|
}
|
|
74
74
|
}
|
|
@@ -77,7 +77,7 @@ var toGraphQLType = (schema) => {
|
|
|
77
77
|
for (const field2 of ast.propertySignatures) {
|
|
78
78
|
const fieldName = String(field2.name);
|
|
79
79
|
if (fieldName === "_tag") continue;
|
|
80
|
-
const fieldSchema =
|
|
80
|
+
const fieldSchema = S2.make(field2.type);
|
|
81
81
|
let fieldType = toGraphQLType(fieldSchema);
|
|
82
82
|
if (!field2.isOptional) {
|
|
83
83
|
fieldType = new GraphQLNonNull(fieldType);
|
|
@@ -94,32 +94,32 @@ var toGraphQLType = (schema) => {
|
|
|
94
94
|
if (isOptionTransformation(ast)) {
|
|
95
95
|
const innerType = getOptionInnerType(ast.to);
|
|
96
96
|
if (innerType) {
|
|
97
|
-
return toGraphQLType(
|
|
97
|
+
return toGraphQLType(S2.make(innerType));
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
|
-
return toGraphQLType(
|
|
100
|
+
return toGraphQLType(S2.make(ast.to));
|
|
101
101
|
}
|
|
102
102
|
if (ast._tag === "Declaration") {
|
|
103
103
|
if (isOptionDeclaration(ast)) {
|
|
104
104
|
const innerType = getOptionInnerType(ast);
|
|
105
105
|
if (innerType) {
|
|
106
|
-
return toGraphQLType(
|
|
106
|
+
return toGraphQLType(S2.make(innerType));
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
109
|
const typeParams = ast.typeParameters;
|
|
110
110
|
if (typeParams && typeParams.length > 0) {
|
|
111
|
-
return toGraphQLType(
|
|
111
|
+
return toGraphQLType(S2.make(typeParams[0]));
|
|
112
112
|
}
|
|
113
113
|
}
|
|
114
114
|
if (ast._tag === "Union") {
|
|
115
115
|
const types = ast.types;
|
|
116
116
|
if (types.length > 0) {
|
|
117
|
-
return toGraphQLType(
|
|
117
|
+
return toGraphQLType(S2.make(types[0]));
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
120
|
if (ast._tag === "Suspend") {
|
|
121
121
|
const innerAst = ast.f();
|
|
122
|
-
return toGraphQLType(
|
|
122
|
+
return toGraphQLType(S2.make(innerAst));
|
|
123
123
|
}
|
|
124
124
|
return GraphQLString;
|
|
125
125
|
};
|
|
@@ -132,7 +132,7 @@ var toGraphQLInputType = (schema) => {
|
|
|
132
132
|
if (isIntegerType(ast)) {
|
|
133
133
|
return GraphQLInt;
|
|
134
134
|
}
|
|
135
|
-
return toGraphQLInputType(
|
|
135
|
+
return toGraphQLInputType(S2.make(ast.from));
|
|
136
136
|
}
|
|
137
137
|
if (ast._tag === "Literal") {
|
|
138
138
|
if (typeof ast.literal === "string") return GraphQLString;
|
|
@@ -144,7 +144,7 @@ var toGraphQLInputType = (schema) => {
|
|
|
144
144
|
if (ast._tag === "TupleType") {
|
|
145
145
|
const elements = ast.elements;
|
|
146
146
|
if (elements.length > 0) {
|
|
147
|
-
const elementSchema =
|
|
147
|
+
const elementSchema = S2.make(elements[0].type);
|
|
148
148
|
return new GraphQLList(toGraphQLInputType(elementSchema));
|
|
149
149
|
}
|
|
150
150
|
}
|
|
@@ -153,7 +153,7 @@ var toGraphQLInputType = (schema) => {
|
|
|
153
153
|
for (const field2 of ast.propertySignatures) {
|
|
154
154
|
const fieldName = String(field2.name);
|
|
155
155
|
if (fieldName === "_tag") continue;
|
|
156
|
-
const fieldSchema =
|
|
156
|
+
const fieldSchema = S2.make(field2.type);
|
|
157
157
|
let fieldType = toGraphQLInputType(fieldSchema);
|
|
158
158
|
if (!field2.isOptional) {
|
|
159
159
|
fieldType = new GraphQLNonNull(fieldType);
|
|
@@ -167,33 +167,33 @@ var toGraphQLInputType = (schema) => {
|
|
|
167
167
|
});
|
|
168
168
|
}
|
|
169
169
|
if (ast._tag === "Transformation") {
|
|
170
|
-
return toGraphQLInputType(
|
|
170
|
+
return toGraphQLInputType(S2.make(ast.from));
|
|
171
171
|
}
|
|
172
172
|
if (ast._tag === "Declaration") {
|
|
173
173
|
if (isOptionDeclaration(ast)) {
|
|
174
174
|
const innerType = getOptionInnerType(ast);
|
|
175
175
|
if (innerType) {
|
|
176
|
-
return toGraphQLInputType(
|
|
176
|
+
return toGraphQLInputType(S2.make(innerType));
|
|
177
177
|
}
|
|
178
178
|
}
|
|
179
179
|
const typeParams = ast.typeParameters;
|
|
180
180
|
if (typeParams && typeParams.length > 0) {
|
|
181
|
-
return toGraphQLInputType(
|
|
181
|
+
return toGraphQLInputType(S2.make(typeParams[0]));
|
|
182
182
|
}
|
|
183
183
|
}
|
|
184
184
|
if (ast._tag === "Union") {
|
|
185
185
|
const types = ast.types;
|
|
186
186
|
const nonNullTypes = types.filter((t) => t._tag !== "Literal" || t.literal !== null).filter((t) => t._tag !== "UndefinedKeyword");
|
|
187
187
|
if (nonNullTypes.length > 0) {
|
|
188
|
-
return toGraphQLInputType(
|
|
188
|
+
return toGraphQLInputType(S2.make(nonNullTypes[0]));
|
|
189
189
|
}
|
|
190
190
|
if (types.length > 0) {
|
|
191
|
-
return toGraphQLInputType(
|
|
191
|
+
return toGraphQLInputType(S2.make(types[0]));
|
|
192
192
|
}
|
|
193
193
|
}
|
|
194
194
|
if (ast._tag === "Suspend") {
|
|
195
195
|
const innerAst = ast.f();
|
|
196
|
-
return toGraphQLInputType(
|
|
196
|
+
return toGraphQLInputType(S2.make(innerAst));
|
|
197
197
|
}
|
|
198
198
|
return GraphQLString;
|
|
199
199
|
};
|
|
@@ -204,7 +204,7 @@ var toGraphQLArgs = (schema) => {
|
|
|
204
204
|
for (const field2 of ast.propertySignatures) {
|
|
205
205
|
const fieldName = String(field2.name);
|
|
206
206
|
if (fieldName === "_tag") continue;
|
|
207
|
-
const fieldSchema =
|
|
207
|
+
const fieldSchema = S2.make(field2.type);
|
|
208
208
|
let fieldType = toGraphQLInputType(fieldSchema);
|
|
209
209
|
if (!field2.isOptional) {
|
|
210
210
|
fieldType = new GraphQLNonNull(fieldType);
|
|
@@ -332,17 +332,17 @@ function toGraphQLTypeWithRegistry(schema, ctx) {
|
|
|
332
332
|
if (isOptionDeclaration2(ast)) {
|
|
333
333
|
const innerType = getOptionInnerType2(ast);
|
|
334
334
|
if (innerType) {
|
|
335
|
-
return toGraphQLTypeWithRegistry(
|
|
335
|
+
return toGraphQLTypeWithRegistry(S2.make(innerType), ctx);
|
|
336
336
|
}
|
|
337
337
|
}
|
|
338
338
|
const typeParams = ast.typeParameters;
|
|
339
339
|
if (typeParams && typeParams.length > 0) {
|
|
340
|
-
return toGraphQLTypeWithRegistry(
|
|
340
|
+
return toGraphQLTypeWithRegistry(S2.make(typeParams[0]), ctx);
|
|
341
341
|
}
|
|
342
342
|
}
|
|
343
343
|
if (ast._tag === "Suspend") {
|
|
344
344
|
const innerAst = ast.f();
|
|
345
|
-
return toGraphQLTypeWithRegistry(
|
|
345
|
+
return toGraphQLTypeWithRegistry(S2.make(innerAst), ctx);
|
|
346
346
|
}
|
|
347
347
|
return toGraphQLType(schema);
|
|
348
348
|
}
|
|
@@ -407,21 +407,21 @@ function handleTransformationAST(ast, ctx) {
|
|
|
407
407
|
}
|
|
408
408
|
const innerType = getOptionInnerType2(toAst);
|
|
409
409
|
if (innerType) {
|
|
410
|
-
return toGraphQLTypeWithRegistry(
|
|
410
|
+
return toGraphQLTypeWithRegistry(S2.make(innerType), ctx);
|
|
411
411
|
}
|
|
412
412
|
}
|
|
413
413
|
if (toAst._tag === "TupleType") {
|
|
414
414
|
if (toAst.rest && toAst.rest.length > 0) {
|
|
415
|
-
const elementSchema =
|
|
415
|
+
const elementSchema = S2.make(toAst.rest[0].type);
|
|
416
416
|
const elementType = toGraphQLTypeWithRegistry(elementSchema, ctx);
|
|
417
417
|
return new GraphQLList(elementType);
|
|
418
418
|
} else if (toAst.elements.length > 0) {
|
|
419
|
-
const elementSchema =
|
|
419
|
+
const elementSchema = S2.make(toAst.elements[0].type);
|
|
420
420
|
const elementType = toGraphQLTypeWithRegistry(elementSchema, ctx);
|
|
421
421
|
return new GraphQLList(elementType);
|
|
422
422
|
}
|
|
423
423
|
}
|
|
424
|
-
return toGraphQLTypeWithRegistry(
|
|
424
|
+
return toGraphQLTypeWithRegistry(S2.make(ast.to), ctx);
|
|
425
425
|
}
|
|
426
426
|
function handleUnionAST(ast, ctx) {
|
|
427
427
|
const allLiterals = ast.types.every((t) => t._tag === "Literal");
|
|
@@ -446,11 +446,22 @@ function handleUnionAST(ast, ctx) {
|
|
|
446
446
|
if (result) return result;
|
|
447
447
|
}
|
|
448
448
|
}
|
|
449
|
+
if (memberAst._tag === "TypeLiteral") {
|
|
450
|
+
const valueField = memberAst.propertySignatures?.find(
|
|
451
|
+
(p) => String(p.name) === "value"
|
|
452
|
+
);
|
|
453
|
+
if (valueField) {
|
|
454
|
+
const innerResult = toGraphQLTypeWithRegistry(S2.make(valueField.type), ctx);
|
|
455
|
+
if (innerResult) {
|
|
456
|
+
return innerResult;
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
}
|
|
449
460
|
}
|
|
450
461
|
if (ast.types.length > 0) {
|
|
451
|
-
return toGraphQLTypeWithRegistry(
|
|
462
|
+
return toGraphQLTypeWithRegistry(S2.make(ast.types[0]), ctx);
|
|
452
463
|
}
|
|
453
|
-
return toGraphQLType(
|
|
464
|
+
return toGraphQLType(S2.make(ast));
|
|
454
465
|
}
|
|
455
466
|
function findEnumForLiteralUnion(types, ctx) {
|
|
456
467
|
const literalValues = types.map((t) => String(t.literal)).sort();
|
|
@@ -493,15 +504,15 @@ function findEnumForLiteral(ast, ctx) {
|
|
|
493
504
|
}
|
|
494
505
|
function handleTupleTypeAST(ast, ctx) {
|
|
495
506
|
if (ast.rest && ast.rest.length > 0) {
|
|
496
|
-
const elementSchema =
|
|
507
|
+
const elementSchema = S2.make(ast.rest[0].type);
|
|
497
508
|
const elementType = toGraphQLTypeWithRegistry(elementSchema, ctx);
|
|
498
509
|
return new GraphQLList(elementType);
|
|
499
510
|
} else if (ast.elements && ast.elements.length > 0) {
|
|
500
|
-
const elementSchema =
|
|
511
|
+
const elementSchema = S2.make(ast.elements[0].type);
|
|
501
512
|
const elementType = toGraphQLTypeWithRegistry(elementSchema, ctx);
|
|
502
513
|
return new GraphQLList(elementType);
|
|
503
514
|
}
|
|
504
|
-
return toGraphQLType(
|
|
515
|
+
return toGraphQLType(S2.make(ast));
|
|
505
516
|
}
|
|
506
517
|
function schemaToFields(schema, ctx) {
|
|
507
518
|
let ast = schema.ast;
|
|
@@ -525,7 +536,7 @@ function schemaToFields(schema, ctx) {
|
|
|
525
536
|
for (const field2 of ast.propertySignatures) {
|
|
526
537
|
const fieldName = String(field2.name);
|
|
527
538
|
if (fieldName === "_tag") continue;
|
|
528
|
-
const fieldSchema =
|
|
539
|
+
const fieldSchema = S2.make(field2.type);
|
|
529
540
|
let fieldType = toGraphQLTypeWithRegistry(fieldSchema, ctx);
|
|
530
541
|
if (!field2.isOptional) {
|
|
531
542
|
fieldType = getNonNull(fieldType);
|
|
@@ -546,7 +557,7 @@ function schemaToInputFields(schema, enumRegistry, inputRegistry, inputs, enums,
|
|
|
546
557
|
for (const field2 of ast.propertySignatures) {
|
|
547
558
|
const fieldName = String(field2.name);
|
|
548
559
|
if (fieldName === "_tag") continue;
|
|
549
|
-
const fieldSchema =
|
|
560
|
+
const fieldSchema = S2.make(field2.type);
|
|
550
561
|
let fieldType = toGraphQLInputTypeWithRegistry(
|
|
551
562
|
fieldSchema,
|
|
552
563
|
enumRegistry,
|
|
@@ -627,10 +638,28 @@ function toGraphQLInputTypeWithRegistry(schema, enumRegistry, inputRegistry, inp
|
|
|
627
638
|
if (result) return result;
|
|
628
639
|
}
|
|
629
640
|
}
|
|
641
|
+
if (memberAst._tag === "TypeLiteral") {
|
|
642
|
+
const valueField = memberAst.propertySignatures?.find(
|
|
643
|
+
(p) => String(p.name) === "value"
|
|
644
|
+
);
|
|
645
|
+
if (valueField) {
|
|
646
|
+
const innerResult = toGraphQLInputTypeWithRegistry(
|
|
647
|
+
S2.make(valueField.type),
|
|
648
|
+
enumRegistry,
|
|
649
|
+
inputRegistry,
|
|
650
|
+
inputs,
|
|
651
|
+
enums,
|
|
652
|
+
cache
|
|
653
|
+
);
|
|
654
|
+
if (innerResult) {
|
|
655
|
+
return innerResult;
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
}
|
|
630
659
|
}
|
|
631
660
|
}
|
|
632
661
|
return toGraphQLInputTypeWithRegistry(
|
|
633
|
-
|
|
662
|
+
S2.make(toAst),
|
|
634
663
|
enumRegistry,
|
|
635
664
|
inputRegistry,
|
|
636
665
|
inputs,
|
|
@@ -643,7 +672,7 @@ function toGraphQLInputTypeWithRegistry(schema, enumRegistry, inputRegistry, inp
|
|
|
643
672
|
const nonUndefinedTypes = unionAst.types.filter((t) => t._tag !== "UndefinedKeyword");
|
|
644
673
|
if (nonUndefinedTypes.length === 1 && nonUndefinedTypes[0]._tag === "Union") {
|
|
645
674
|
return toGraphQLInputTypeWithRegistry(
|
|
646
|
-
|
|
675
|
+
S2.make(nonUndefinedTypes[0]),
|
|
647
676
|
enumRegistry,
|
|
648
677
|
inputRegistry,
|
|
649
678
|
inputs,
|
|
@@ -653,7 +682,7 @@ function toGraphQLInputTypeWithRegistry(schema, enumRegistry, inputRegistry, inp
|
|
|
653
682
|
}
|
|
654
683
|
if (nonUndefinedTypes.length === 1 && nonUndefinedTypes[0]._tag === "TypeLiteral") {
|
|
655
684
|
return toGraphQLInputTypeWithRegistry(
|
|
656
|
-
|
|
685
|
+
S2.make(nonUndefinedTypes[0]),
|
|
657
686
|
enumRegistry,
|
|
658
687
|
inputRegistry,
|
|
659
688
|
inputs,
|
|
@@ -675,6 +704,24 @@ function toGraphQLInputTypeWithRegistry(schema, enumRegistry, inputRegistry, inp
|
|
|
675
704
|
if (result) return result;
|
|
676
705
|
}
|
|
677
706
|
}
|
|
707
|
+
if (memberAst._tag === "TypeLiteral") {
|
|
708
|
+
const valueField = memberAst.propertySignatures?.find(
|
|
709
|
+
(p) => String(p.name) === "value"
|
|
710
|
+
);
|
|
711
|
+
if (valueField) {
|
|
712
|
+
const innerResult = toGraphQLInputTypeWithRegistry(
|
|
713
|
+
S2.make(valueField.type),
|
|
714
|
+
enumRegistry,
|
|
715
|
+
inputRegistry,
|
|
716
|
+
inputs,
|
|
717
|
+
enums,
|
|
718
|
+
cache
|
|
719
|
+
);
|
|
720
|
+
if (innerResult) {
|
|
721
|
+
return innerResult;
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
}
|
|
678
725
|
}
|
|
679
726
|
const allLiterals = unionAst.types.every((t) => t._tag === "Literal");
|
|
680
727
|
if (allLiterals) {
|
|
@@ -708,7 +755,7 @@ function toGraphQLInputTypeWithRegistry(schema, enumRegistry, inputRegistry, inp
|
|
|
708
755
|
if (ast._tag === "Suspend") {
|
|
709
756
|
const innerAst = ast.f();
|
|
710
757
|
return toGraphQLInputTypeWithRegistry(
|
|
711
|
-
|
|
758
|
+
S2.make(innerAst),
|
|
712
759
|
enumRegistry,
|
|
713
760
|
inputRegistry,
|
|
714
761
|
inputs,
|
|
@@ -725,7 +772,7 @@ function toGraphQLArgsWithRegistry(schema, enumRegistry, inputRegistry, inputs,
|
|
|
725
772
|
for (const field2 of ast.propertySignatures) {
|
|
726
773
|
const fieldName = String(field2.name);
|
|
727
774
|
if (fieldName === "_tag") continue;
|
|
728
|
-
const fieldSchema =
|
|
775
|
+
const fieldSchema = S2.make(field2.type);
|
|
729
776
|
let fieldType = toGraphQLInputTypeWithRegistry(
|
|
730
777
|
fieldSchema,
|
|
731
778
|
enumRegistry,
|
|
@@ -762,7 +809,7 @@ function isOptionSchema(schema) {
|
|
|
762
809
|
}
|
|
763
810
|
function encodeResolverOutput(schema, value) {
|
|
764
811
|
if (isOptionSchema(schema)) {
|
|
765
|
-
return Effect.orDie(
|
|
812
|
+
return Effect.orDie(S2.encode(schema)(value));
|
|
766
813
|
}
|
|
767
814
|
return Effect.succeed(value);
|
|
768
815
|
}
|