@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.cjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var graphql = require('graphql');
|
|
4
4
|
var effect = require('effect');
|
|
5
|
-
var
|
|
5
|
+
var S2 = require('effect/Schema');
|
|
6
6
|
var AST = require('effect/SchemaAST');
|
|
7
7
|
|
|
8
8
|
function _interopNamespace(e) {
|
|
@@ -23,7 +23,7 @@ function _interopNamespace(e) {
|
|
|
23
23
|
return Object.freeze(n);
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
var
|
|
26
|
+
var S2__namespace = /*#__PURE__*/_interopNamespace(S2);
|
|
27
27
|
var AST__namespace = /*#__PURE__*/_interopNamespace(AST);
|
|
28
28
|
|
|
29
29
|
// src/builder/index.ts
|
|
@@ -78,7 +78,7 @@ var toGraphQLType = (schema) => {
|
|
|
78
78
|
if (isIntegerType(ast)) {
|
|
79
79
|
return graphql.GraphQLInt;
|
|
80
80
|
}
|
|
81
|
-
return toGraphQLType(
|
|
81
|
+
return toGraphQLType(S2__namespace.make(ast.from));
|
|
82
82
|
}
|
|
83
83
|
if (ast._tag === "Literal") {
|
|
84
84
|
if (typeof ast.literal === "string") return graphql.GraphQLString;
|
|
@@ -90,7 +90,7 @@ var toGraphQLType = (schema) => {
|
|
|
90
90
|
if (ast._tag === "TupleType") {
|
|
91
91
|
const elements = ast.elements;
|
|
92
92
|
if (elements.length > 0) {
|
|
93
|
-
const elementSchema =
|
|
93
|
+
const elementSchema = S2__namespace.make(elements[0].type);
|
|
94
94
|
return new graphql.GraphQLList(toGraphQLType(elementSchema));
|
|
95
95
|
}
|
|
96
96
|
}
|
|
@@ -99,7 +99,7 @@ var toGraphQLType = (schema) => {
|
|
|
99
99
|
for (const field2 of ast.propertySignatures) {
|
|
100
100
|
const fieldName = String(field2.name);
|
|
101
101
|
if (fieldName === "_tag") continue;
|
|
102
|
-
const fieldSchema =
|
|
102
|
+
const fieldSchema = S2__namespace.make(field2.type);
|
|
103
103
|
let fieldType = toGraphQLType(fieldSchema);
|
|
104
104
|
if (!field2.isOptional) {
|
|
105
105
|
fieldType = new graphql.GraphQLNonNull(fieldType);
|
|
@@ -116,32 +116,32 @@ var toGraphQLType = (schema) => {
|
|
|
116
116
|
if (isOptionTransformation(ast)) {
|
|
117
117
|
const innerType = getOptionInnerType(ast.to);
|
|
118
118
|
if (innerType) {
|
|
119
|
-
return toGraphQLType(
|
|
119
|
+
return toGraphQLType(S2__namespace.make(innerType));
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
|
-
return toGraphQLType(
|
|
122
|
+
return toGraphQLType(S2__namespace.make(ast.to));
|
|
123
123
|
}
|
|
124
124
|
if (ast._tag === "Declaration") {
|
|
125
125
|
if (isOptionDeclaration(ast)) {
|
|
126
126
|
const innerType = getOptionInnerType(ast);
|
|
127
127
|
if (innerType) {
|
|
128
|
-
return toGraphQLType(
|
|
128
|
+
return toGraphQLType(S2__namespace.make(innerType));
|
|
129
129
|
}
|
|
130
130
|
}
|
|
131
131
|
const typeParams = ast.typeParameters;
|
|
132
132
|
if (typeParams && typeParams.length > 0) {
|
|
133
|
-
return toGraphQLType(
|
|
133
|
+
return toGraphQLType(S2__namespace.make(typeParams[0]));
|
|
134
134
|
}
|
|
135
135
|
}
|
|
136
136
|
if (ast._tag === "Union") {
|
|
137
137
|
const types = ast.types;
|
|
138
138
|
if (types.length > 0) {
|
|
139
|
-
return toGraphQLType(
|
|
139
|
+
return toGraphQLType(S2__namespace.make(types[0]));
|
|
140
140
|
}
|
|
141
141
|
}
|
|
142
142
|
if (ast._tag === "Suspend") {
|
|
143
143
|
const innerAst = ast.f();
|
|
144
|
-
return toGraphQLType(
|
|
144
|
+
return toGraphQLType(S2__namespace.make(innerAst));
|
|
145
145
|
}
|
|
146
146
|
return graphql.GraphQLString;
|
|
147
147
|
};
|
|
@@ -154,7 +154,7 @@ var toGraphQLInputType = (schema) => {
|
|
|
154
154
|
if (isIntegerType(ast)) {
|
|
155
155
|
return graphql.GraphQLInt;
|
|
156
156
|
}
|
|
157
|
-
return toGraphQLInputType(
|
|
157
|
+
return toGraphQLInputType(S2__namespace.make(ast.from));
|
|
158
158
|
}
|
|
159
159
|
if (ast._tag === "Literal") {
|
|
160
160
|
if (typeof ast.literal === "string") return graphql.GraphQLString;
|
|
@@ -166,7 +166,7 @@ var toGraphQLInputType = (schema) => {
|
|
|
166
166
|
if (ast._tag === "TupleType") {
|
|
167
167
|
const elements = ast.elements;
|
|
168
168
|
if (elements.length > 0) {
|
|
169
|
-
const elementSchema =
|
|
169
|
+
const elementSchema = S2__namespace.make(elements[0].type);
|
|
170
170
|
return new graphql.GraphQLList(toGraphQLInputType(elementSchema));
|
|
171
171
|
}
|
|
172
172
|
}
|
|
@@ -175,7 +175,7 @@ var toGraphQLInputType = (schema) => {
|
|
|
175
175
|
for (const field2 of ast.propertySignatures) {
|
|
176
176
|
const fieldName = String(field2.name);
|
|
177
177
|
if (fieldName === "_tag") continue;
|
|
178
|
-
const fieldSchema =
|
|
178
|
+
const fieldSchema = S2__namespace.make(field2.type);
|
|
179
179
|
let fieldType = toGraphQLInputType(fieldSchema);
|
|
180
180
|
if (!field2.isOptional) {
|
|
181
181
|
fieldType = new graphql.GraphQLNonNull(fieldType);
|
|
@@ -189,33 +189,33 @@ var toGraphQLInputType = (schema) => {
|
|
|
189
189
|
});
|
|
190
190
|
}
|
|
191
191
|
if (ast._tag === "Transformation") {
|
|
192
|
-
return toGraphQLInputType(
|
|
192
|
+
return toGraphQLInputType(S2__namespace.make(ast.from));
|
|
193
193
|
}
|
|
194
194
|
if (ast._tag === "Declaration") {
|
|
195
195
|
if (isOptionDeclaration(ast)) {
|
|
196
196
|
const innerType = getOptionInnerType(ast);
|
|
197
197
|
if (innerType) {
|
|
198
|
-
return toGraphQLInputType(
|
|
198
|
+
return toGraphQLInputType(S2__namespace.make(innerType));
|
|
199
199
|
}
|
|
200
200
|
}
|
|
201
201
|
const typeParams = ast.typeParameters;
|
|
202
202
|
if (typeParams && typeParams.length > 0) {
|
|
203
|
-
return toGraphQLInputType(
|
|
203
|
+
return toGraphQLInputType(S2__namespace.make(typeParams[0]));
|
|
204
204
|
}
|
|
205
205
|
}
|
|
206
206
|
if (ast._tag === "Union") {
|
|
207
207
|
const types = ast.types;
|
|
208
208
|
const nonNullTypes = types.filter((t) => t._tag !== "Literal" || t.literal !== null).filter((t) => t._tag !== "UndefinedKeyword");
|
|
209
209
|
if (nonNullTypes.length > 0) {
|
|
210
|
-
return toGraphQLInputType(
|
|
210
|
+
return toGraphQLInputType(S2__namespace.make(nonNullTypes[0]));
|
|
211
211
|
}
|
|
212
212
|
if (types.length > 0) {
|
|
213
|
-
return toGraphQLInputType(
|
|
213
|
+
return toGraphQLInputType(S2__namespace.make(types[0]));
|
|
214
214
|
}
|
|
215
215
|
}
|
|
216
216
|
if (ast._tag === "Suspend") {
|
|
217
217
|
const innerAst = ast.f();
|
|
218
|
-
return toGraphQLInputType(
|
|
218
|
+
return toGraphQLInputType(S2__namespace.make(innerAst));
|
|
219
219
|
}
|
|
220
220
|
return graphql.GraphQLString;
|
|
221
221
|
};
|
|
@@ -226,7 +226,7 @@ var toGraphQLArgs = (schema) => {
|
|
|
226
226
|
for (const field2 of ast.propertySignatures) {
|
|
227
227
|
const fieldName = String(field2.name);
|
|
228
228
|
if (fieldName === "_tag") continue;
|
|
229
|
-
const fieldSchema =
|
|
229
|
+
const fieldSchema = S2__namespace.make(field2.type);
|
|
230
230
|
let fieldType = toGraphQLInputType(fieldSchema);
|
|
231
231
|
if (!field2.isOptional) {
|
|
232
232
|
fieldType = new graphql.GraphQLNonNull(fieldType);
|
|
@@ -354,17 +354,17 @@ function toGraphQLTypeWithRegistry(schema, ctx) {
|
|
|
354
354
|
if (isOptionDeclaration2(ast)) {
|
|
355
355
|
const innerType = getOptionInnerType2(ast);
|
|
356
356
|
if (innerType) {
|
|
357
|
-
return toGraphQLTypeWithRegistry(
|
|
357
|
+
return toGraphQLTypeWithRegistry(S2__namespace.make(innerType), ctx);
|
|
358
358
|
}
|
|
359
359
|
}
|
|
360
360
|
const typeParams = ast.typeParameters;
|
|
361
361
|
if (typeParams && typeParams.length > 0) {
|
|
362
|
-
return toGraphQLTypeWithRegistry(
|
|
362
|
+
return toGraphQLTypeWithRegistry(S2__namespace.make(typeParams[0]), ctx);
|
|
363
363
|
}
|
|
364
364
|
}
|
|
365
365
|
if (ast._tag === "Suspend") {
|
|
366
366
|
const innerAst = ast.f();
|
|
367
|
-
return toGraphQLTypeWithRegistry(
|
|
367
|
+
return toGraphQLTypeWithRegistry(S2__namespace.make(innerAst), ctx);
|
|
368
368
|
}
|
|
369
369
|
return toGraphQLType(schema);
|
|
370
370
|
}
|
|
@@ -429,21 +429,21 @@ function handleTransformationAST(ast, ctx) {
|
|
|
429
429
|
}
|
|
430
430
|
const innerType = getOptionInnerType2(toAst);
|
|
431
431
|
if (innerType) {
|
|
432
|
-
return toGraphQLTypeWithRegistry(
|
|
432
|
+
return toGraphQLTypeWithRegistry(S2__namespace.make(innerType), ctx);
|
|
433
433
|
}
|
|
434
434
|
}
|
|
435
435
|
if (toAst._tag === "TupleType") {
|
|
436
436
|
if (toAst.rest && toAst.rest.length > 0) {
|
|
437
|
-
const elementSchema =
|
|
437
|
+
const elementSchema = S2__namespace.make(toAst.rest[0].type);
|
|
438
438
|
const elementType = toGraphQLTypeWithRegistry(elementSchema, ctx);
|
|
439
439
|
return new graphql.GraphQLList(elementType);
|
|
440
440
|
} else if (toAst.elements.length > 0) {
|
|
441
|
-
const elementSchema =
|
|
441
|
+
const elementSchema = S2__namespace.make(toAst.elements[0].type);
|
|
442
442
|
const elementType = toGraphQLTypeWithRegistry(elementSchema, ctx);
|
|
443
443
|
return new graphql.GraphQLList(elementType);
|
|
444
444
|
}
|
|
445
445
|
}
|
|
446
|
-
return toGraphQLTypeWithRegistry(
|
|
446
|
+
return toGraphQLTypeWithRegistry(S2__namespace.make(ast.to), ctx);
|
|
447
447
|
}
|
|
448
448
|
function handleUnionAST(ast, ctx) {
|
|
449
449
|
const allLiterals = ast.types.every((t) => t._tag === "Literal");
|
|
@@ -468,11 +468,22 @@ function handleUnionAST(ast, ctx) {
|
|
|
468
468
|
if (result) return result;
|
|
469
469
|
}
|
|
470
470
|
}
|
|
471
|
+
if (memberAst._tag === "TypeLiteral") {
|
|
472
|
+
const valueField = memberAst.propertySignatures?.find(
|
|
473
|
+
(p) => String(p.name) === "value"
|
|
474
|
+
);
|
|
475
|
+
if (valueField) {
|
|
476
|
+
const innerResult = toGraphQLTypeWithRegistry(S2__namespace.make(valueField.type), ctx);
|
|
477
|
+
if (innerResult) {
|
|
478
|
+
return innerResult;
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
}
|
|
471
482
|
}
|
|
472
483
|
if (ast.types.length > 0) {
|
|
473
|
-
return toGraphQLTypeWithRegistry(
|
|
484
|
+
return toGraphQLTypeWithRegistry(S2__namespace.make(ast.types[0]), ctx);
|
|
474
485
|
}
|
|
475
|
-
return toGraphQLType(
|
|
486
|
+
return toGraphQLType(S2__namespace.make(ast));
|
|
476
487
|
}
|
|
477
488
|
function findEnumForLiteralUnion(types, ctx) {
|
|
478
489
|
const literalValues = types.map((t) => String(t.literal)).sort();
|
|
@@ -515,15 +526,15 @@ function findEnumForLiteral(ast, ctx) {
|
|
|
515
526
|
}
|
|
516
527
|
function handleTupleTypeAST(ast, ctx) {
|
|
517
528
|
if (ast.rest && ast.rest.length > 0) {
|
|
518
|
-
const elementSchema =
|
|
529
|
+
const elementSchema = S2__namespace.make(ast.rest[0].type);
|
|
519
530
|
const elementType = toGraphQLTypeWithRegistry(elementSchema, ctx);
|
|
520
531
|
return new graphql.GraphQLList(elementType);
|
|
521
532
|
} else if (ast.elements && ast.elements.length > 0) {
|
|
522
|
-
const elementSchema =
|
|
533
|
+
const elementSchema = S2__namespace.make(ast.elements[0].type);
|
|
523
534
|
const elementType = toGraphQLTypeWithRegistry(elementSchema, ctx);
|
|
524
535
|
return new graphql.GraphQLList(elementType);
|
|
525
536
|
}
|
|
526
|
-
return toGraphQLType(
|
|
537
|
+
return toGraphQLType(S2__namespace.make(ast));
|
|
527
538
|
}
|
|
528
539
|
function schemaToFields(schema, ctx) {
|
|
529
540
|
let ast = schema.ast;
|
|
@@ -547,7 +558,7 @@ function schemaToFields(schema, ctx) {
|
|
|
547
558
|
for (const field2 of ast.propertySignatures) {
|
|
548
559
|
const fieldName = String(field2.name);
|
|
549
560
|
if (fieldName === "_tag") continue;
|
|
550
|
-
const fieldSchema =
|
|
561
|
+
const fieldSchema = S2__namespace.make(field2.type);
|
|
551
562
|
let fieldType = toGraphQLTypeWithRegistry(fieldSchema, ctx);
|
|
552
563
|
if (!field2.isOptional) {
|
|
553
564
|
fieldType = getNonNull(fieldType);
|
|
@@ -568,7 +579,7 @@ function schemaToInputFields(schema, enumRegistry, inputRegistry, inputs, enums,
|
|
|
568
579
|
for (const field2 of ast.propertySignatures) {
|
|
569
580
|
const fieldName = String(field2.name);
|
|
570
581
|
if (fieldName === "_tag") continue;
|
|
571
|
-
const fieldSchema =
|
|
582
|
+
const fieldSchema = S2__namespace.make(field2.type);
|
|
572
583
|
let fieldType = toGraphQLInputTypeWithRegistry(
|
|
573
584
|
fieldSchema,
|
|
574
585
|
enumRegistry,
|
|
@@ -649,10 +660,28 @@ function toGraphQLInputTypeWithRegistry(schema, enumRegistry, inputRegistry, inp
|
|
|
649
660
|
if (result) return result;
|
|
650
661
|
}
|
|
651
662
|
}
|
|
663
|
+
if (memberAst._tag === "TypeLiteral") {
|
|
664
|
+
const valueField = memberAst.propertySignatures?.find(
|
|
665
|
+
(p) => String(p.name) === "value"
|
|
666
|
+
);
|
|
667
|
+
if (valueField) {
|
|
668
|
+
const innerResult = toGraphQLInputTypeWithRegistry(
|
|
669
|
+
S2__namespace.make(valueField.type),
|
|
670
|
+
enumRegistry,
|
|
671
|
+
inputRegistry,
|
|
672
|
+
inputs,
|
|
673
|
+
enums,
|
|
674
|
+
cache
|
|
675
|
+
);
|
|
676
|
+
if (innerResult) {
|
|
677
|
+
return innerResult;
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
}
|
|
652
681
|
}
|
|
653
682
|
}
|
|
654
683
|
return toGraphQLInputTypeWithRegistry(
|
|
655
|
-
|
|
684
|
+
S2__namespace.make(toAst),
|
|
656
685
|
enumRegistry,
|
|
657
686
|
inputRegistry,
|
|
658
687
|
inputs,
|
|
@@ -665,7 +694,7 @@ function toGraphQLInputTypeWithRegistry(schema, enumRegistry, inputRegistry, inp
|
|
|
665
694
|
const nonUndefinedTypes = unionAst.types.filter((t) => t._tag !== "UndefinedKeyword");
|
|
666
695
|
if (nonUndefinedTypes.length === 1 && nonUndefinedTypes[0]._tag === "Union") {
|
|
667
696
|
return toGraphQLInputTypeWithRegistry(
|
|
668
|
-
|
|
697
|
+
S2__namespace.make(nonUndefinedTypes[0]),
|
|
669
698
|
enumRegistry,
|
|
670
699
|
inputRegistry,
|
|
671
700
|
inputs,
|
|
@@ -675,7 +704,7 @@ function toGraphQLInputTypeWithRegistry(schema, enumRegistry, inputRegistry, inp
|
|
|
675
704
|
}
|
|
676
705
|
if (nonUndefinedTypes.length === 1 && nonUndefinedTypes[0]._tag === "TypeLiteral") {
|
|
677
706
|
return toGraphQLInputTypeWithRegistry(
|
|
678
|
-
|
|
707
|
+
S2__namespace.make(nonUndefinedTypes[0]),
|
|
679
708
|
enumRegistry,
|
|
680
709
|
inputRegistry,
|
|
681
710
|
inputs,
|
|
@@ -697,6 +726,24 @@ function toGraphQLInputTypeWithRegistry(schema, enumRegistry, inputRegistry, inp
|
|
|
697
726
|
if (result) return result;
|
|
698
727
|
}
|
|
699
728
|
}
|
|
729
|
+
if (memberAst._tag === "TypeLiteral") {
|
|
730
|
+
const valueField = memberAst.propertySignatures?.find(
|
|
731
|
+
(p) => String(p.name) === "value"
|
|
732
|
+
);
|
|
733
|
+
if (valueField) {
|
|
734
|
+
const innerResult = toGraphQLInputTypeWithRegistry(
|
|
735
|
+
S2__namespace.make(valueField.type),
|
|
736
|
+
enumRegistry,
|
|
737
|
+
inputRegistry,
|
|
738
|
+
inputs,
|
|
739
|
+
enums,
|
|
740
|
+
cache
|
|
741
|
+
);
|
|
742
|
+
if (innerResult) {
|
|
743
|
+
return innerResult;
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
}
|
|
700
747
|
}
|
|
701
748
|
const allLiterals = unionAst.types.every((t) => t._tag === "Literal");
|
|
702
749
|
if (allLiterals) {
|
|
@@ -730,7 +777,7 @@ function toGraphQLInputTypeWithRegistry(schema, enumRegistry, inputRegistry, inp
|
|
|
730
777
|
if (ast._tag === "Suspend") {
|
|
731
778
|
const innerAst = ast.f();
|
|
732
779
|
return toGraphQLInputTypeWithRegistry(
|
|
733
|
-
|
|
780
|
+
S2__namespace.make(innerAst),
|
|
734
781
|
enumRegistry,
|
|
735
782
|
inputRegistry,
|
|
736
783
|
inputs,
|
|
@@ -747,7 +794,7 @@ function toGraphQLArgsWithRegistry(schema, enumRegistry, inputRegistry, inputs,
|
|
|
747
794
|
for (const field2 of ast.propertySignatures) {
|
|
748
795
|
const fieldName = String(field2.name);
|
|
749
796
|
if (fieldName === "_tag") continue;
|
|
750
|
-
const fieldSchema =
|
|
797
|
+
const fieldSchema = S2__namespace.make(field2.type);
|
|
751
798
|
let fieldType = toGraphQLInputTypeWithRegistry(
|
|
752
799
|
fieldSchema,
|
|
753
800
|
enumRegistry,
|
|
@@ -784,7 +831,7 @@ function isOptionSchema(schema) {
|
|
|
784
831
|
}
|
|
785
832
|
function encodeResolverOutput(schema, value) {
|
|
786
833
|
if (isOptionSchema(schema)) {
|
|
787
|
-
return effect.Effect.orDie(
|
|
834
|
+
return effect.Effect.orDie(S2__namespace.encode(schema)(value));
|
|
788
835
|
}
|
|
789
836
|
return effect.Effect.succeed(value);
|
|
790
837
|
}
|