@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/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, Kind, specifiedRules, NoSchemaIntrospectionCustomRule, subscribe, GraphQLScalarType } from 'graphql';
|
|
2
2
|
export { DirectiveLocation, GraphQLBoolean, GraphQLEnumType, GraphQLFloat, GraphQLID, GraphQLInputObjectType, GraphQLInt, GraphQLInterfaceType, GraphQLList, GraphQLNonNull, GraphQLObjectType, GraphQLScalarType, GraphQLSchema, GraphQLString, GraphQLUnionType, Kind, graphql, lexicographicSortSchema, printSchema } from 'graphql';
|
|
3
3
|
import { Pipeable, Context, Data, Layer, Effect, Ref, HashMap, Config, Option, Schema, Runtime, Queue, Stream, Fiber, Deferred } from 'effect';
|
|
4
|
-
import * as
|
|
4
|
+
import * as S2 from 'effect/Schema';
|
|
5
5
|
import * as AST from 'effect/SchemaAST';
|
|
6
6
|
import DataLoader from 'dataloader';
|
|
7
7
|
import { HttpIncomingMessage, HttpServerResponse, HttpServerRequest, HttpRouter } from '@effect/platform';
|
|
@@ -58,7 +58,7 @@ var toGraphQLType = (schema) => {
|
|
|
58
58
|
if (isIntegerType(ast)) {
|
|
59
59
|
return GraphQLInt;
|
|
60
60
|
}
|
|
61
|
-
return toGraphQLType(
|
|
61
|
+
return toGraphQLType(S2.make(ast.from));
|
|
62
62
|
}
|
|
63
63
|
if (ast._tag === "Literal") {
|
|
64
64
|
if (typeof ast.literal === "string") return GraphQLString;
|
|
@@ -70,7 +70,7 @@ var toGraphQLType = (schema) => {
|
|
|
70
70
|
if (ast._tag === "TupleType") {
|
|
71
71
|
const elements = ast.elements;
|
|
72
72
|
if (elements.length > 0) {
|
|
73
|
-
const elementSchema =
|
|
73
|
+
const elementSchema = S2.make(elements[0].type);
|
|
74
74
|
return new GraphQLList(toGraphQLType(elementSchema));
|
|
75
75
|
}
|
|
76
76
|
}
|
|
@@ -79,7 +79,7 @@ var toGraphQLType = (schema) => {
|
|
|
79
79
|
for (const field2 of ast.propertySignatures) {
|
|
80
80
|
const fieldName = String(field2.name);
|
|
81
81
|
if (fieldName === "_tag") continue;
|
|
82
|
-
const fieldSchema =
|
|
82
|
+
const fieldSchema = S2.make(field2.type);
|
|
83
83
|
let fieldType = toGraphQLType(fieldSchema);
|
|
84
84
|
if (!field2.isOptional) {
|
|
85
85
|
fieldType = new GraphQLNonNull(fieldType);
|
|
@@ -96,32 +96,32 @@ var toGraphQLType = (schema) => {
|
|
|
96
96
|
if (isOptionTransformation(ast)) {
|
|
97
97
|
const innerType = getOptionInnerType(ast.to);
|
|
98
98
|
if (innerType) {
|
|
99
|
-
return toGraphQLType(
|
|
99
|
+
return toGraphQLType(S2.make(innerType));
|
|
100
100
|
}
|
|
101
101
|
}
|
|
102
|
-
return toGraphQLType(
|
|
102
|
+
return toGraphQLType(S2.make(ast.to));
|
|
103
103
|
}
|
|
104
104
|
if (ast._tag === "Declaration") {
|
|
105
105
|
if (isOptionDeclaration(ast)) {
|
|
106
106
|
const innerType = getOptionInnerType(ast);
|
|
107
107
|
if (innerType) {
|
|
108
|
-
return toGraphQLType(
|
|
108
|
+
return toGraphQLType(S2.make(innerType));
|
|
109
109
|
}
|
|
110
110
|
}
|
|
111
111
|
const typeParams = ast.typeParameters;
|
|
112
112
|
if (typeParams && typeParams.length > 0) {
|
|
113
|
-
return toGraphQLType(
|
|
113
|
+
return toGraphQLType(S2.make(typeParams[0]));
|
|
114
114
|
}
|
|
115
115
|
}
|
|
116
116
|
if (ast._tag === "Union") {
|
|
117
117
|
const types = ast.types;
|
|
118
118
|
if (types.length > 0) {
|
|
119
|
-
return toGraphQLType(
|
|
119
|
+
return toGraphQLType(S2.make(types[0]));
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
122
|
if (ast._tag === "Suspend") {
|
|
123
123
|
const innerAst = ast.f();
|
|
124
|
-
return toGraphQLType(
|
|
124
|
+
return toGraphQLType(S2.make(innerAst));
|
|
125
125
|
}
|
|
126
126
|
return GraphQLString;
|
|
127
127
|
};
|
|
@@ -134,7 +134,7 @@ var toGraphQLInputType = (schema) => {
|
|
|
134
134
|
if (isIntegerType(ast)) {
|
|
135
135
|
return GraphQLInt;
|
|
136
136
|
}
|
|
137
|
-
return toGraphQLInputType(
|
|
137
|
+
return toGraphQLInputType(S2.make(ast.from));
|
|
138
138
|
}
|
|
139
139
|
if (ast._tag === "Literal") {
|
|
140
140
|
if (typeof ast.literal === "string") return GraphQLString;
|
|
@@ -146,7 +146,7 @@ var toGraphQLInputType = (schema) => {
|
|
|
146
146
|
if (ast._tag === "TupleType") {
|
|
147
147
|
const elements = ast.elements;
|
|
148
148
|
if (elements.length > 0) {
|
|
149
|
-
const elementSchema =
|
|
149
|
+
const elementSchema = S2.make(elements[0].type);
|
|
150
150
|
return new GraphQLList(toGraphQLInputType(elementSchema));
|
|
151
151
|
}
|
|
152
152
|
}
|
|
@@ -155,7 +155,7 @@ var toGraphQLInputType = (schema) => {
|
|
|
155
155
|
for (const field2 of ast.propertySignatures) {
|
|
156
156
|
const fieldName = String(field2.name);
|
|
157
157
|
if (fieldName === "_tag") continue;
|
|
158
|
-
const fieldSchema =
|
|
158
|
+
const fieldSchema = S2.make(field2.type);
|
|
159
159
|
let fieldType = toGraphQLInputType(fieldSchema);
|
|
160
160
|
if (!field2.isOptional) {
|
|
161
161
|
fieldType = new GraphQLNonNull(fieldType);
|
|
@@ -169,33 +169,33 @@ var toGraphQLInputType = (schema) => {
|
|
|
169
169
|
});
|
|
170
170
|
}
|
|
171
171
|
if (ast._tag === "Transformation") {
|
|
172
|
-
return toGraphQLInputType(
|
|
172
|
+
return toGraphQLInputType(S2.make(ast.from));
|
|
173
173
|
}
|
|
174
174
|
if (ast._tag === "Declaration") {
|
|
175
175
|
if (isOptionDeclaration(ast)) {
|
|
176
176
|
const innerType = getOptionInnerType(ast);
|
|
177
177
|
if (innerType) {
|
|
178
|
-
return toGraphQLInputType(
|
|
178
|
+
return toGraphQLInputType(S2.make(innerType));
|
|
179
179
|
}
|
|
180
180
|
}
|
|
181
181
|
const typeParams = ast.typeParameters;
|
|
182
182
|
if (typeParams && typeParams.length > 0) {
|
|
183
|
-
return toGraphQLInputType(
|
|
183
|
+
return toGraphQLInputType(S2.make(typeParams[0]));
|
|
184
184
|
}
|
|
185
185
|
}
|
|
186
186
|
if (ast._tag === "Union") {
|
|
187
187
|
const types = ast.types;
|
|
188
188
|
const nonNullTypes = types.filter((t) => t._tag !== "Literal" || t.literal !== null).filter((t) => t._tag !== "UndefinedKeyword");
|
|
189
189
|
if (nonNullTypes.length > 0) {
|
|
190
|
-
return toGraphQLInputType(
|
|
190
|
+
return toGraphQLInputType(S2.make(nonNullTypes[0]));
|
|
191
191
|
}
|
|
192
192
|
if (types.length > 0) {
|
|
193
|
-
return toGraphQLInputType(
|
|
193
|
+
return toGraphQLInputType(S2.make(types[0]));
|
|
194
194
|
}
|
|
195
195
|
}
|
|
196
196
|
if (ast._tag === "Suspend") {
|
|
197
197
|
const innerAst = ast.f();
|
|
198
|
-
return toGraphQLInputType(
|
|
198
|
+
return toGraphQLInputType(S2.make(innerAst));
|
|
199
199
|
}
|
|
200
200
|
return GraphQLString;
|
|
201
201
|
};
|
|
@@ -218,7 +218,7 @@ var toGraphQLObjectType = (name, schema, additionalFields) => {
|
|
|
218
218
|
for (const field2 of ast.propertySignatures) {
|
|
219
219
|
const fieldName = String(field2.name);
|
|
220
220
|
if (fieldName === "_tag") continue;
|
|
221
|
-
const fieldSchema =
|
|
221
|
+
const fieldSchema = S2.make(field2.type);
|
|
222
222
|
let fieldType = toGraphQLType(fieldSchema);
|
|
223
223
|
if (!field2.isOptional) {
|
|
224
224
|
fieldType = new GraphQLNonNull(fieldType);
|
|
@@ -250,7 +250,7 @@ var toGraphQLArgs = (schema) => {
|
|
|
250
250
|
for (const field2 of ast.propertySignatures) {
|
|
251
251
|
const fieldName = String(field2.name);
|
|
252
252
|
if (fieldName === "_tag") continue;
|
|
253
|
-
const fieldSchema =
|
|
253
|
+
const fieldSchema = S2.make(field2.type);
|
|
254
254
|
let fieldType = toGraphQLInputType(fieldSchema);
|
|
255
255
|
if (!field2.isOptional) {
|
|
256
256
|
fieldType = new GraphQLNonNull(fieldType);
|
|
@@ -378,17 +378,17 @@ function toGraphQLTypeWithRegistry(schema, ctx) {
|
|
|
378
378
|
if (isOptionDeclaration2(ast)) {
|
|
379
379
|
const innerType = getOptionInnerType2(ast);
|
|
380
380
|
if (innerType) {
|
|
381
|
-
return toGraphQLTypeWithRegistry(
|
|
381
|
+
return toGraphQLTypeWithRegistry(S2.make(innerType), ctx);
|
|
382
382
|
}
|
|
383
383
|
}
|
|
384
384
|
const typeParams = ast.typeParameters;
|
|
385
385
|
if (typeParams && typeParams.length > 0) {
|
|
386
|
-
return toGraphQLTypeWithRegistry(
|
|
386
|
+
return toGraphQLTypeWithRegistry(S2.make(typeParams[0]), ctx);
|
|
387
387
|
}
|
|
388
388
|
}
|
|
389
389
|
if (ast._tag === "Suspend") {
|
|
390
390
|
const innerAst = ast.f();
|
|
391
|
-
return toGraphQLTypeWithRegistry(
|
|
391
|
+
return toGraphQLTypeWithRegistry(S2.make(innerAst), ctx);
|
|
392
392
|
}
|
|
393
393
|
return toGraphQLType(schema);
|
|
394
394
|
}
|
|
@@ -453,21 +453,21 @@ function handleTransformationAST(ast, ctx) {
|
|
|
453
453
|
}
|
|
454
454
|
const innerType = getOptionInnerType2(toAst);
|
|
455
455
|
if (innerType) {
|
|
456
|
-
return toGraphQLTypeWithRegistry(
|
|
456
|
+
return toGraphQLTypeWithRegistry(S2.make(innerType), ctx);
|
|
457
457
|
}
|
|
458
458
|
}
|
|
459
459
|
if (toAst._tag === "TupleType") {
|
|
460
460
|
if (toAst.rest && toAst.rest.length > 0) {
|
|
461
|
-
const elementSchema =
|
|
461
|
+
const elementSchema = S2.make(toAst.rest[0].type);
|
|
462
462
|
const elementType = toGraphQLTypeWithRegistry(elementSchema, ctx);
|
|
463
463
|
return new GraphQLList(elementType);
|
|
464
464
|
} else if (toAst.elements.length > 0) {
|
|
465
|
-
const elementSchema =
|
|
465
|
+
const elementSchema = S2.make(toAst.elements[0].type);
|
|
466
466
|
const elementType = toGraphQLTypeWithRegistry(elementSchema, ctx);
|
|
467
467
|
return new GraphQLList(elementType);
|
|
468
468
|
}
|
|
469
469
|
}
|
|
470
|
-
return toGraphQLTypeWithRegistry(
|
|
470
|
+
return toGraphQLTypeWithRegistry(S2.make(ast.to), ctx);
|
|
471
471
|
}
|
|
472
472
|
function handleUnionAST(ast, ctx) {
|
|
473
473
|
const allLiterals = ast.types.every((t) => t._tag === "Literal");
|
|
@@ -492,11 +492,22 @@ function handleUnionAST(ast, ctx) {
|
|
|
492
492
|
if (result) return result;
|
|
493
493
|
}
|
|
494
494
|
}
|
|
495
|
+
if (memberAst._tag === "TypeLiteral") {
|
|
496
|
+
const valueField = memberAst.propertySignatures?.find(
|
|
497
|
+
(p) => String(p.name) === "value"
|
|
498
|
+
);
|
|
499
|
+
if (valueField) {
|
|
500
|
+
const innerResult = toGraphQLTypeWithRegistry(S2.make(valueField.type), ctx);
|
|
501
|
+
if (innerResult) {
|
|
502
|
+
return innerResult;
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
}
|
|
495
506
|
}
|
|
496
507
|
if (ast.types.length > 0) {
|
|
497
|
-
return toGraphQLTypeWithRegistry(
|
|
508
|
+
return toGraphQLTypeWithRegistry(S2.make(ast.types[0]), ctx);
|
|
498
509
|
}
|
|
499
|
-
return toGraphQLType(
|
|
510
|
+
return toGraphQLType(S2.make(ast));
|
|
500
511
|
}
|
|
501
512
|
function findEnumForLiteralUnion(types, ctx) {
|
|
502
513
|
const literalValues = types.map((t) => String(t.literal)).sort();
|
|
@@ -539,15 +550,15 @@ function findEnumForLiteral(ast, ctx) {
|
|
|
539
550
|
}
|
|
540
551
|
function handleTupleTypeAST(ast, ctx) {
|
|
541
552
|
if (ast.rest && ast.rest.length > 0) {
|
|
542
|
-
const elementSchema =
|
|
553
|
+
const elementSchema = S2.make(ast.rest[0].type);
|
|
543
554
|
const elementType = toGraphQLTypeWithRegistry(elementSchema, ctx);
|
|
544
555
|
return new GraphQLList(elementType);
|
|
545
556
|
} else if (ast.elements && ast.elements.length > 0) {
|
|
546
|
-
const elementSchema =
|
|
557
|
+
const elementSchema = S2.make(ast.elements[0].type);
|
|
547
558
|
const elementType = toGraphQLTypeWithRegistry(elementSchema, ctx);
|
|
548
559
|
return new GraphQLList(elementType);
|
|
549
560
|
}
|
|
550
|
-
return toGraphQLType(
|
|
561
|
+
return toGraphQLType(S2.make(ast));
|
|
551
562
|
}
|
|
552
563
|
function schemaToFields(schema, ctx) {
|
|
553
564
|
let ast = schema.ast;
|
|
@@ -571,7 +582,7 @@ function schemaToFields(schema, ctx) {
|
|
|
571
582
|
for (const field2 of ast.propertySignatures) {
|
|
572
583
|
const fieldName = String(field2.name);
|
|
573
584
|
if (fieldName === "_tag") continue;
|
|
574
|
-
const fieldSchema =
|
|
585
|
+
const fieldSchema = S2.make(field2.type);
|
|
575
586
|
let fieldType = toGraphQLTypeWithRegistry(fieldSchema, ctx);
|
|
576
587
|
if (!field2.isOptional) {
|
|
577
588
|
fieldType = getNonNull(fieldType);
|
|
@@ -592,7 +603,7 @@ function schemaToInputFields(schema, enumRegistry, inputRegistry, inputs, enums,
|
|
|
592
603
|
for (const field2 of ast.propertySignatures) {
|
|
593
604
|
const fieldName = String(field2.name);
|
|
594
605
|
if (fieldName === "_tag") continue;
|
|
595
|
-
const fieldSchema =
|
|
606
|
+
const fieldSchema = S2.make(field2.type);
|
|
596
607
|
let fieldType = toGraphQLInputTypeWithRegistry(
|
|
597
608
|
fieldSchema,
|
|
598
609
|
enumRegistry,
|
|
@@ -673,10 +684,28 @@ function toGraphQLInputTypeWithRegistry(schema, enumRegistry, inputRegistry, inp
|
|
|
673
684
|
if (result) return result;
|
|
674
685
|
}
|
|
675
686
|
}
|
|
687
|
+
if (memberAst._tag === "TypeLiteral") {
|
|
688
|
+
const valueField = memberAst.propertySignatures?.find(
|
|
689
|
+
(p) => String(p.name) === "value"
|
|
690
|
+
);
|
|
691
|
+
if (valueField) {
|
|
692
|
+
const innerResult = toGraphQLInputTypeWithRegistry(
|
|
693
|
+
S2.make(valueField.type),
|
|
694
|
+
enumRegistry,
|
|
695
|
+
inputRegistry,
|
|
696
|
+
inputs,
|
|
697
|
+
enums,
|
|
698
|
+
cache
|
|
699
|
+
);
|
|
700
|
+
if (innerResult) {
|
|
701
|
+
return innerResult;
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
}
|
|
676
705
|
}
|
|
677
706
|
}
|
|
678
707
|
return toGraphQLInputTypeWithRegistry(
|
|
679
|
-
|
|
708
|
+
S2.make(toAst),
|
|
680
709
|
enumRegistry,
|
|
681
710
|
inputRegistry,
|
|
682
711
|
inputs,
|
|
@@ -689,7 +718,7 @@ function toGraphQLInputTypeWithRegistry(schema, enumRegistry, inputRegistry, inp
|
|
|
689
718
|
const nonUndefinedTypes = unionAst.types.filter((t) => t._tag !== "UndefinedKeyword");
|
|
690
719
|
if (nonUndefinedTypes.length === 1 && nonUndefinedTypes[0]._tag === "Union") {
|
|
691
720
|
return toGraphQLInputTypeWithRegistry(
|
|
692
|
-
|
|
721
|
+
S2.make(nonUndefinedTypes[0]),
|
|
693
722
|
enumRegistry,
|
|
694
723
|
inputRegistry,
|
|
695
724
|
inputs,
|
|
@@ -699,7 +728,7 @@ function toGraphQLInputTypeWithRegistry(schema, enumRegistry, inputRegistry, inp
|
|
|
699
728
|
}
|
|
700
729
|
if (nonUndefinedTypes.length === 1 && nonUndefinedTypes[0]._tag === "TypeLiteral") {
|
|
701
730
|
return toGraphQLInputTypeWithRegistry(
|
|
702
|
-
|
|
731
|
+
S2.make(nonUndefinedTypes[0]),
|
|
703
732
|
enumRegistry,
|
|
704
733
|
inputRegistry,
|
|
705
734
|
inputs,
|
|
@@ -721,6 +750,24 @@ function toGraphQLInputTypeWithRegistry(schema, enumRegistry, inputRegistry, inp
|
|
|
721
750
|
if (result) return result;
|
|
722
751
|
}
|
|
723
752
|
}
|
|
753
|
+
if (memberAst._tag === "TypeLiteral") {
|
|
754
|
+
const valueField = memberAst.propertySignatures?.find(
|
|
755
|
+
(p) => String(p.name) === "value"
|
|
756
|
+
);
|
|
757
|
+
if (valueField) {
|
|
758
|
+
const innerResult = toGraphQLInputTypeWithRegistry(
|
|
759
|
+
S2.make(valueField.type),
|
|
760
|
+
enumRegistry,
|
|
761
|
+
inputRegistry,
|
|
762
|
+
inputs,
|
|
763
|
+
enums,
|
|
764
|
+
cache
|
|
765
|
+
);
|
|
766
|
+
if (innerResult) {
|
|
767
|
+
return innerResult;
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
}
|
|
724
771
|
}
|
|
725
772
|
const allLiterals = unionAst.types.every((t) => t._tag === "Literal");
|
|
726
773
|
if (allLiterals) {
|
|
@@ -754,7 +801,7 @@ function toGraphQLInputTypeWithRegistry(schema, enumRegistry, inputRegistry, inp
|
|
|
754
801
|
if (ast._tag === "Suspend") {
|
|
755
802
|
const innerAst = ast.f();
|
|
756
803
|
return toGraphQLInputTypeWithRegistry(
|
|
757
|
-
|
|
804
|
+
S2.make(innerAst),
|
|
758
805
|
enumRegistry,
|
|
759
806
|
inputRegistry,
|
|
760
807
|
inputs,
|
|
@@ -771,7 +818,7 @@ function toGraphQLArgsWithRegistry(schema, enumRegistry, inputRegistry, inputs,
|
|
|
771
818
|
for (const field2 of ast.propertySignatures) {
|
|
772
819
|
const fieldName = String(field2.name);
|
|
773
820
|
if (fieldName === "_tag") continue;
|
|
774
|
-
const fieldSchema =
|
|
821
|
+
const fieldSchema = S2.make(field2.type);
|
|
775
822
|
let fieldType = toGraphQLInputTypeWithRegistry(
|
|
776
823
|
fieldSchema,
|
|
777
824
|
enumRegistry,
|
|
@@ -808,7 +855,7 @@ function isOptionSchema(schema) {
|
|
|
808
855
|
}
|
|
809
856
|
function encodeResolverOutput(schema, value) {
|
|
810
857
|
if (isOptionSchema(schema)) {
|
|
811
|
-
return Effect.orDie(
|
|
858
|
+
return Effect.orDie(S2.encode(schema)(value));
|
|
812
859
|
}
|
|
813
860
|
return Effect.succeed(value);
|
|
814
861
|
}
|