@effect-gql/core 1.3.4 → 1.4.1
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 +196 -49
- package/builder/index.cjs.map +1 -1
- package/builder/index.js +196 -49
- package/builder/index.js.map +1 -1
- package/index.cjs +211 -51
- package/index.cjs.map +1 -1
- package/index.js +210 -50
- package/index.js.map +1 -1
- package/package.json +1 -1
package/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 S = require('effect/Schema');
|
|
6
6
|
var AST = require('effect/SchemaAST');
|
|
7
7
|
var DataLoader = require('dataloader');
|
|
8
8
|
var platform = require('@effect/platform');
|
|
@@ -27,7 +27,7 @@ function _interopNamespace(e) {
|
|
|
27
27
|
return Object.freeze(n);
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
var
|
|
30
|
+
var S__namespace = /*#__PURE__*/_interopNamespace(S);
|
|
31
31
|
var AST__namespace = /*#__PURE__*/_interopNamespace(AST);
|
|
32
32
|
var DataLoader__default = /*#__PURE__*/_interopDefault(DataLoader);
|
|
33
33
|
|
|
@@ -46,6 +46,34 @@ var isIntegerType = (ast) => {
|
|
|
46
46
|
}
|
|
47
47
|
return false;
|
|
48
48
|
};
|
|
49
|
+
var isOptionDeclaration = (ast) => {
|
|
50
|
+
if (ast._tag === "Declaration") {
|
|
51
|
+
const annotations = ast.annotations;
|
|
52
|
+
if (annotations) {
|
|
53
|
+
const TypeConstructorSymbol = /* @__PURE__ */ Symbol.for("effect/annotation/TypeConstructor");
|
|
54
|
+
const typeConstructor = annotations[TypeConstructorSymbol];
|
|
55
|
+
if (typeConstructor && typeConstructor._tag === "effect/Option") {
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return false;
|
|
61
|
+
};
|
|
62
|
+
var isOptionTransformation = (ast) => {
|
|
63
|
+
if (ast._tag === "Transformation") {
|
|
64
|
+
return isOptionDeclaration(ast.to);
|
|
65
|
+
}
|
|
66
|
+
return false;
|
|
67
|
+
};
|
|
68
|
+
var getOptionInnerType = (ast) => {
|
|
69
|
+
if (ast._tag === "Declaration") {
|
|
70
|
+
const typeParams = ast.typeParameters;
|
|
71
|
+
if (typeParams && typeParams.length > 0) {
|
|
72
|
+
return typeParams[0];
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return void 0;
|
|
76
|
+
};
|
|
49
77
|
var toGraphQLType = (schema) => {
|
|
50
78
|
const ast = schema.ast;
|
|
51
79
|
if (ast._tag === "StringKeyword") return graphql.GraphQLString;
|
|
@@ -55,7 +83,7 @@ var toGraphQLType = (schema) => {
|
|
|
55
83
|
if (isIntegerType(ast)) {
|
|
56
84
|
return graphql.GraphQLInt;
|
|
57
85
|
}
|
|
58
|
-
return toGraphQLType(
|
|
86
|
+
return toGraphQLType(S__namespace.make(ast.from));
|
|
59
87
|
}
|
|
60
88
|
if (ast._tag === "Literal") {
|
|
61
89
|
if (typeof ast.literal === "string") return graphql.GraphQLString;
|
|
@@ -67,7 +95,7 @@ var toGraphQLType = (schema) => {
|
|
|
67
95
|
if (ast._tag === "TupleType") {
|
|
68
96
|
const elements = ast.elements;
|
|
69
97
|
if (elements.length > 0) {
|
|
70
|
-
const elementSchema =
|
|
98
|
+
const elementSchema = S__namespace.make(elements[0].type);
|
|
71
99
|
return new graphql.GraphQLList(toGraphQLType(elementSchema));
|
|
72
100
|
}
|
|
73
101
|
}
|
|
@@ -75,7 +103,8 @@ var toGraphQLType = (schema) => {
|
|
|
75
103
|
const fields = {};
|
|
76
104
|
for (const field2 of ast.propertySignatures) {
|
|
77
105
|
const fieldName = String(field2.name);
|
|
78
|
-
|
|
106
|
+
if (fieldName === "_tag") continue;
|
|
107
|
+
const fieldSchema = S__namespace.make(field2.type);
|
|
79
108
|
let fieldType = toGraphQLType(fieldSchema);
|
|
80
109
|
if (!field2.isOptional) {
|
|
81
110
|
fieldType = new graphql.GraphQLNonNull(fieldType);
|
|
@@ -89,17 +118,35 @@ var toGraphQLType = (schema) => {
|
|
|
89
118
|
});
|
|
90
119
|
}
|
|
91
120
|
if (ast._tag === "Transformation") {
|
|
92
|
-
|
|
121
|
+
if (isOptionTransformation(ast)) {
|
|
122
|
+
const innerType = getOptionInnerType(ast.to);
|
|
123
|
+
if (innerType) {
|
|
124
|
+
return toGraphQLType(S__namespace.make(innerType));
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return toGraphQLType(S__namespace.make(ast.to));
|
|
128
|
+
}
|
|
129
|
+
if (ast._tag === "Declaration") {
|
|
130
|
+
if (isOptionDeclaration(ast)) {
|
|
131
|
+
const innerType = getOptionInnerType(ast);
|
|
132
|
+
if (innerType) {
|
|
133
|
+
return toGraphQLType(S__namespace.make(innerType));
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
const typeParams = ast.typeParameters;
|
|
137
|
+
if (typeParams && typeParams.length > 0) {
|
|
138
|
+
return toGraphQLType(S__namespace.make(typeParams[0]));
|
|
139
|
+
}
|
|
93
140
|
}
|
|
94
141
|
if (ast._tag === "Union") {
|
|
95
142
|
const types = ast.types;
|
|
96
143
|
if (types.length > 0) {
|
|
97
|
-
return toGraphQLType(
|
|
144
|
+
return toGraphQLType(S__namespace.make(types[0]));
|
|
98
145
|
}
|
|
99
146
|
}
|
|
100
147
|
if (ast._tag === "Suspend") {
|
|
101
148
|
const innerAst = ast.f();
|
|
102
|
-
return toGraphQLType(
|
|
149
|
+
return toGraphQLType(S__namespace.make(innerAst));
|
|
103
150
|
}
|
|
104
151
|
return graphql.GraphQLString;
|
|
105
152
|
};
|
|
@@ -112,7 +159,7 @@ var toGraphQLInputType = (schema) => {
|
|
|
112
159
|
if (isIntegerType(ast)) {
|
|
113
160
|
return graphql.GraphQLInt;
|
|
114
161
|
}
|
|
115
|
-
return toGraphQLInputType(
|
|
162
|
+
return toGraphQLInputType(S__namespace.make(ast.from));
|
|
116
163
|
}
|
|
117
164
|
if (ast._tag === "Literal") {
|
|
118
165
|
if (typeof ast.literal === "string") return graphql.GraphQLString;
|
|
@@ -124,7 +171,7 @@ var toGraphQLInputType = (schema) => {
|
|
|
124
171
|
if (ast._tag === "TupleType") {
|
|
125
172
|
const elements = ast.elements;
|
|
126
173
|
if (elements.length > 0) {
|
|
127
|
-
const elementSchema =
|
|
174
|
+
const elementSchema = S__namespace.make(elements[0].type);
|
|
128
175
|
return new graphql.GraphQLList(toGraphQLInputType(elementSchema));
|
|
129
176
|
}
|
|
130
177
|
}
|
|
@@ -132,7 +179,8 @@ var toGraphQLInputType = (schema) => {
|
|
|
132
179
|
const fields = {};
|
|
133
180
|
for (const field2 of ast.propertySignatures) {
|
|
134
181
|
const fieldName = String(field2.name);
|
|
135
|
-
|
|
182
|
+
if (fieldName === "_tag") continue;
|
|
183
|
+
const fieldSchema = S__namespace.make(field2.type);
|
|
136
184
|
let fieldType = toGraphQLInputType(fieldSchema);
|
|
137
185
|
if (!field2.isOptional) {
|
|
138
186
|
fieldType = new graphql.GraphQLNonNull(fieldType);
|
|
@@ -146,27 +194,56 @@ var toGraphQLInputType = (schema) => {
|
|
|
146
194
|
});
|
|
147
195
|
}
|
|
148
196
|
if (ast._tag === "Transformation") {
|
|
149
|
-
return toGraphQLInputType(
|
|
197
|
+
return toGraphQLInputType(S__namespace.make(ast.from));
|
|
198
|
+
}
|
|
199
|
+
if (ast._tag === "Declaration") {
|
|
200
|
+
if (isOptionDeclaration(ast)) {
|
|
201
|
+
const innerType = getOptionInnerType(ast);
|
|
202
|
+
if (innerType) {
|
|
203
|
+
return toGraphQLInputType(S__namespace.make(innerType));
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
const typeParams = ast.typeParameters;
|
|
207
|
+
if (typeParams && typeParams.length > 0) {
|
|
208
|
+
return toGraphQLInputType(S__namespace.make(typeParams[0]));
|
|
209
|
+
}
|
|
150
210
|
}
|
|
151
211
|
if (ast._tag === "Union") {
|
|
152
212
|
const types = ast.types;
|
|
213
|
+
const nonNullTypes = types.filter((t) => t._tag !== "Literal" || t.literal !== null).filter((t) => t._tag !== "UndefinedKeyword");
|
|
214
|
+
if (nonNullTypes.length > 0) {
|
|
215
|
+
return toGraphQLInputType(S__namespace.make(nonNullTypes[0]));
|
|
216
|
+
}
|
|
153
217
|
if (types.length > 0) {
|
|
154
|
-
return toGraphQLInputType(
|
|
218
|
+
return toGraphQLInputType(S__namespace.make(types[0]));
|
|
155
219
|
}
|
|
156
220
|
}
|
|
157
221
|
if (ast._tag === "Suspend") {
|
|
158
222
|
const innerAst = ast.f();
|
|
159
|
-
return toGraphQLInputType(
|
|
223
|
+
return toGraphQLInputType(S__namespace.make(innerAst));
|
|
160
224
|
}
|
|
161
225
|
return graphql.GraphQLString;
|
|
162
226
|
};
|
|
163
227
|
var toGraphQLObjectType = (name, schema, additionalFields) => {
|
|
164
|
-
|
|
228
|
+
let ast = schema.ast;
|
|
229
|
+
while (ast._tag === "Transformation") {
|
|
230
|
+
ast = ast.to;
|
|
231
|
+
}
|
|
232
|
+
if (ast._tag === "Declaration") {
|
|
233
|
+
const typeParams = ast.typeParameters;
|
|
234
|
+
if (typeParams && typeParams.length > 0) {
|
|
235
|
+
ast = typeParams[0];
|
|
236
|
+
while (ast._tag === "Transformation") {
|
|
237
|
+
ast = ast.to;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
165
241
|
if (ast._tag === "TypeLiteral") {
|
|
166
242
|
const fields = {};
|
|
167
243
|
for (const field2 of ast.propertySignatures) {
|
|
168
244
|
const fieldName = String(field2.name);
|
|
169
|
-
|
|
245
|
+
if (fieldName === "_tag") continue;
|
|
246
|
+
const fieldSchema = S__namespace.make(field2.type);
|
|
170
247
|
let fieldType = toGraphQLType(fieldSchema);
|
|
171
248
|
if (!field2.isOptional) {
|
|
172
249
|
fieldType = new graphql.GraphQLNonNull(fieldType);
|
|
@@ -197,7 +274,8 @@ var toGraphQLArgs = (schema) => {
|
|
|
197
274
|
const args = {};
|
|
198
275
|
for (const field2 of ast.propertySignatures) {
|
|
199
276
|
const fieldName = String(field2.name);
|
|
200
|
-
|
|
277
|
+
if (fieldName === "_tag") continue;
|
|
278
|
+
const fieldSchema = S__namespace.make(field2.type);
|
|
201
279
|
let fieldType = toGraphQLInputType(fieldSchema);
|
|
202
280
|
if (!field2.isOptional) {
|
|
203
281
|
fieldType = new graphql.GraphQLNonNull(fieldType);
|
|
@@ -297,9 +375,21 @@ function toGraphQLTypeWithRegistry(schema, ctx) {
|
|
|
297
375
|
if (ast._tag === "TupleType") {
|
|
298
376
|
return handleTupleTypeAST(ast, ctx);
|
|
299
377
|
}
|
|
378
|
+
if (ast._tag === "Declaration") {
|
|
379
|
+
if (isOptionDeclaration2(ast)) {
|
|
380
|
+
const innerType = getOptionInnerType2(ast);
|
|
381
|
+
if (innerType) {
|
|
382
|
+
return toGraphQLTypeWithRegistry(S__namespace.make(innerType), ctx);
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
const typeParams = ast.typeParameters;
|
|
386
|
+
if (typeParams && typeParams.length > 0) {
|
|
387
|
+
return toGraphQLTypeWithRegistry(S__namespace.make(typeParams[0]), ctx);
|
|
388
|
+
}
|
|
389
|
+
}
|
|
300
390
|
if (ast._tag === "Suspend") {
|
|
301
391
|
const innerAst = ast.f();
|
|
302
|
-
return toGraphQLTypeWithRegistry(
|
|
392
|
+
return toGraphQLTypeWithRegistry(S__namespace.make(innerAst), ctx);
|
|
303
393
|
}
|
|
304
394
|
return toGraphQLType(schema);
|
|
305
395
|
}
|
|
@@ -317,20 +407,48 @@ function findRegisteredInterface(schema, ast, ctx) {
|
|
|
317
407
|
}
|
|
318
408
|
return void 0;
|
|
319
409
|
}
|
|
410
|
+
function isOptionDeclaration2(ast) {
|
|
411
|
+
if (ast._tag === "Declaration") {
|
|
412
|
+
const annotations = ast.annotations;
|
|
413
|
+
if (annotations) {
|
|
414
|
+
const TypeConstructorSymbol = /* @__PURE__ */ Symbol.for("effect/annotation/TypeConstructor");
|
|
415
|
+
const typeConstructor = annotations[TypeConstructorSymbol];
|
|
416
|
+
if (typeConstructor && typeConstructor._tag === "effect/Option") {
|
|
417
|
+
return true;
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
return false;
|
|
422
|
+
}
|
|
423
|
+
function getOptionInnerType2(ast) {
|
|
424
|
+
if (ast._tag === "Declaration") {
|
|
425
|
+
const typeParams = ast.typeParameters;
|
|
426
|
+
if (typeParams && typeParams.length > 0) {
|
|
427
|
+
return typeParams[0];
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
return void 0;
|
|
431
|
+
}
|
|
320
432
|
function handleTransformationAST(ast, ctx) {
|
|
321
433
|
const toAst = ast.to;
|
|
434
|
+
if (isOptionDeclaration2(toAst)) {
|
|
435
|
+
const innerType = getOptionInnerType2(toAst);
|
|
436
|
+
if (innerType) {
|
|
437
|
+
return toGraphQLTypeWithRegistry(S__namespace.make(innerType), ctx);
|
|
438
|
+
}
|
|
439
|
+
}
|
|
322
440
|
if (toAst._tag === "TupleType") {
|
|
323
441
|
if (toAst.rest && toAst.rest.length > 0) {
|
|
324
|
-
const elementSchema =
|
|
442
|
+
const elementSchema = S__namespace.make(toAst.rest[0].type);
|
|
325
443
|
const elementType = toGraphQLTypeWithRegistry(elementSchema, ctx);
|
|
326
444
|
return new graphql.GraphQLList(elementType);
|
|
327
445
|
} else if (toAst.elements.length > 0) {
|
|
328
|
-
const elementSchema =
|
|
446
|
+
const elementSchema = S__namespace.make(toAst.elements[0].type);
|
|
329
447
|
const elementType = toGraphQLTypeWithRegistry(elementSchema, ctx);
|
|
330
448
|
return new graphql.GraphQLList(elementType);
|
|
331
449
|
}
|
|
332
450
|
}
|
|
333
|
-
return toGraphQLTypeWithRegistry(
|
|
451
|
+
return toGraphQLTypeWithRegistry(S__namespace.make(ast.to), ctx);
|
|
334
452
|
}
|
|
335
453
|
function handleUnionAST(ast, ctx) {
|
|
336
454
|
const allLiterals = ast.types.every((t) => t._tag === "Literal");
|
|
@@ -342,9 +460,9 @@ function handleUnionAST(ast, ctx) {
|
|
|
342
460
|
if (unionType2) return unionType2;
|
|
343
461
|
}
|
|
344
462
|
if (ast.types.length > 0) {
|
|
345
|
-
return toGraphQLTypeWithRegistry(
|
|
463
|
+
return toGraphQLTypeWithRegistry(S__namespace.make(ast.types[0]), ctx);
|
|
346
464
|
}
|
|
347
|
-
return toGraphQLType(
|
|
465
|
+
return toGraphQLType(S__namespace.make(ast));
|
|
348
466
|
}
|
|
349
467
|
function findEnumForLiteralUnion(types, ctx) {
|
|
350
468
|
const literalValues = types.map((t) => String(t.literal)).sort();
|
|
@@ -387,15 +505,15 @@ function findEnumForLiteral(ast, ctx) {
|
|
|
387
505
|
}
|
|
388
506
|
function handleTupleTypeAST(ast, ctx) {
|
|
389
507
|
if (ast.rest && ast.rest.length > 0) {
|
|
390
|
-
const elementSchema =
|
|
508
|
+
const elementSchema = S__namespace.make(ast.rest[0].type);
|
|
391
509
|
const elementType = toGraphQLTypeWithRegistry(elementSchema, ctx);
|
|
392
510
|
return new graphql.GraphQLList(elementType);
|
|
393
511
|
} else if (ast.elements && ast.elements.length > 0) {
|
|
394
|
-
const elementSchema =
|
|
512
|
+
const elementSchema = S__namespace.make(ast.elements[0].type);
|
|
395
513
|
const elementType = toGraphQLTypeWithRegistry(elementSchema, ctx);
|
|
396
514
|
return new graphql.GraphQLList(elementType);
|
|
397
515
|
}
|
|
398
|
-
return toGraphQLType(
|
|
516
|
+
return toGraphQLType(S__namespace.make(ast));
|
|
399
517
|
}
|
|
400
518
|
function schemaToFields(schema, ctx) {
|
|
401
519
|
let ast = schema.ast;
|
|
@@ -404,15 +522,22 @@ function schemaToFields(schema, ctx) {
|
|
|
404
522
|
}
|
|
405
523
|
if (ast._tag === "Declaration") {
|
|
406
524
|
const typeParams = ast.typeParameters;
|
|
407
|
-
if (typeParams && typeParams.length > 0
|
|
408
|
-
|
|
525
|
+
if (typeParams && typeParams.length > 0) {
|
|
526
|
+
let innerAst = typeParams[0];
|
|
527
|
+
while (innerAst._tag === "Transformation") {
|
|
528
|
+
innerAst = innerAst.to;
|
|
529
|
+
}
|
|
530
|
+
if (innerAst._tag === "TypeLiteral") {
|
|
531
|
+
ast = innerAst;
|
|
532
|
+
}
|
|
409
533
|
}
|
|
410
534
|
}
|
|
411
535
|
if (ast._tag === "TypeLiteral") {
|
|
412
536
|
const fields = {};
|
|
413
537
|
for (const field2 of ast.propertySignatures) {
|
|
414
538
|
const fieldName = String(field2.name);
|
|
415
|
-
|
|
539
|
+
if (fieldName === "_tag") continue;
|
|
540
|
+
const fieldSchema = S__namespace.make(field2.type);
|
|
416
541
|
let fieldType = toGraphQLTypeWithRegistry(fieldSchema, ctx);
|
|
417
542
|
if (!field2.isOptional) {
|
|
418
543
|
fieldType = getNonNull(fieldType);
|
|
@@ -424,12 +549,16 @@ function schemaToFields(schema, ctx) {
|
|
|
424
549
|
return {};
|
|
425
550
|
}
|
|
426
551
|
function schemaToInputFields(schema, enumRegistry, inputRegistry, inputs, enums, cache) {
|
|
427
|
-
|
|
552
|
+
let ast = schema.ast;
|
|
553
|
+
while (ast._tag === "Transformation") {
|
|
554
|
+
ast = ast.to;
|
|
555
|
+
}
|
|
428
556
|
if (ast._tag === "TypeLiteral") {
|
|
429
557
|
const fields = {};
|
|
430
558
|
for (const field2 of ast.propertySignatures) {
|
|
431
559
|
const fieldName = String(field2.name);
|
|
432
|
-
|
|
560
|
+
if (fieldName === "_tag") continue;
|
|
561
|
+
const fieldSchema = S__namespace.make(field2.type);
|
|
433
562
|
let fieldType = toGraphQLInputTypeWithRegistry(
|
|
434
563
|
fieldSchema,
|
|
435
564
|
enumRegistry,
|
|
@@ -468,17 +597,6 @@ function buildInputTypeLookupCache(inputs, enums) {
|
|
|
468
597
|
}
|
|
469
598
|
function toGraphQLInputTypeWithRegistry(schema, enumRegistry, inputRegistry, inputs, enums, cache) {
|
|
470
599
|
const ast = schema.ast;
|
|
471
|
-
if (ast._tag === "Transformation") {
|
|
472
|
-
const toAst = ast.to;
|
|
473
|
-
return toGraphQLInputTypeWithRegistry(
|
|
474
|
-
S2__namespace.make(toAst),
|
|
475
|
-
enumRegistry,
|
|
476
|
-
inputRegistry,
|
|
477
|
-
inputs,
|
|
478
|
-
enums,
|
|
479
|
-
cache
|
|
480
|
-
);
|
|
481
|
-
}
|
|
482
600
|
if (cache?.schemaToInputName || cache?.astToInputName) {
|
|
483
601
|
const inputName = cache.schemaToInputName?.get(schema) ?? cache.astToInputName?.get(ast);
|
|
484
602
|
if (inputName) {
|
|
@@ -493,12 +611,23 @@ function toGraphQLInputTypeWithRegistry(schema, enumRegistry, inputRegistry, inp
|
|
|
493
611
|
}
|
|
494
612
|
}
|
|
495
613
|
}
|
|
614
|
+
if (ast._tag === "Transformation") {
|
|
615
|
+
const toAst = ast.to;
|
|
616
|
+
return toGraphQLInputTypeWithRegistry(
|
|
617
|
+
S__namespace.make(toAst),
|
|
618
|
+
enumRegistry,
|
|
619
|
+
inputRegistry,
|
|
620
|
+
inputs,
|
|
621
|
+
enums,
|
|
622
|
+
cache
|
|
623
|
+
);
|
|
624
|
+
}
|
|
496
625
|
if (ast._tag === "Union") {
|
|
497
626
|
const unionAst = ast;
|
|
498
627
|
const nonUndefinedTypes = unionAst.types.filter((t) => t._tag !== "UndefinedKeyword");
|
|
499
628
|
if (nonUndefinedTypes.length === 1 && nonUndefinedTypes[0]._tag === "Union") {
|
|
500
629
|
return toGraphQLInputTypeWithRegistry(
|
|
501
|
-
|
|
630
|
+
S__namespace.make(nonUndefinedTypes[0]),
|
|
502
631
|
enumRegistry,
|
|
503
632
|
inputRegistry,
|
|
504
633
|
inputs,
|
|
@@ -508,7 +637,7 @@ function toGraphQLInputTypeWithRegistry(schema, enumRegistry, inputRegistry, inp
|
|
|
508
637
|
}
|
|
509
638
|
if (nonUndefinedTypes.length === 1 && nonUndefinedTypes[0]._tag === "TypeLiteral") {
|
|
510
639
|
return toGraphQLInputTypeWithRegistry(
|
|
511
|
-
|
|
640
|
+
S__namespace.make(nonUndefinedTypes[0]),
|
|
512
641
|
enumRegistry,
|
|
513
642
|
inputRegistry,
|
|
514
643
|
inputs,
|
|
@@ -548,7 +677,7 @@ function toGraphQLInputTypeWithRegistry(schema, enumRegistry, inputRegistry, inp
|
|
|
548
677
|
if (ast._tag === "Suspend") {
|
|
549
678
|
const innerAst = ast.f();
|
|
550
679
|
return toGraphQLInputTypeWithRegistry(
|
|
551
|
-
|
|
680
|
+
S__namespace.make(innerAst),
|
|
552
681
|
enumRegistry,
|
|
553
682
|
inputRegistry,
|
|
554
683
|
inputs,
|
|
@@ -564,7 +693,8 @@ function toGraphQLArgsWithRegistry(schema, enumRegistry, inputRegistry, inputs,
|
|
|
564
693
|
const args = {};
|
|
565
694
|
for (const field2 of ast.propertySignatures) {
|
|
566
695
|
const fieldName = String(field2.name);
|
|
567
|
-
|
|
696
|
+
if (fieldName === "_tag") continue;
|
|
697
|
+
const fieldSchema = S__namespace.make(field2.type);
|
|
568
698
|
let fieldType = toGraphQLInputTypeWithRegistry(
|
|
569
699
|
fieldSchema,
|
|
570
700
|
enumRegistry,
|
|
@@ -582,6 +712,29 @@ function toGraphQLArgsWithRegistry(schema, enumRegistry, inputRegistry, inputs,
|
|
|
582
712
|
}
|
|
583
713
|
return toGraphQLArgs(schema);
|
|
584
714
|
}
|
|
715
|
+
function isOptionSchema(schema) {
|
|
716
|
+
const ast = schema.ast;
|
|
717
|
+
if (ast._tag === "Transformation") {
|
|
718
|
+
const toAst = ast.to;
|
|
719
|
+
if (toAst._tag === "Declaration") {
|
|
720
|
+
const annotations = toAst.annotations;
|
|
721
|
+
if (annotations) {
|
|
722
|
+
const TypeConstructorSymbol = /* @__PURE__ */ Symbol.for("effect/annotation/TypeConstructor");
|
|
723
|
+
const typeConstructor = annotations[TypeConstructorSymbol];
|
|
724
|
+
if (typeConstructor && typeConstructor._tag === "effect/Option") {
|
|
725
|
+
return true;
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
return false;
|
|
731
|
+
}
|
|
732
|
+
function encodeResolverOutput(schema, value) {
|
|
733
|
+
if (isOptionSchema(schema)) {
|
|
734
|
+
return effect.Effect.orDie(S__namespace.encode(schema)(value));
|
|
735
|
+
}
|
|
736
|
+
return effect.Effect.succeed(value);
|
|
737
|
+
}
|
|
585
738
|
function applyDirectives(effect, directives, directiveRegistrations) {
|
|
586
739
|
if (!directives) return effect;
|
|
587
740
|
let wrapped = effect;
|
|
@@ -616,7 +769,8 @@ function buildField(config, ctx) {
|
|
|
616
769
|
);
|
|
617
770
|
const middlewareContext = { parent: _parent, args, info };
|
|
618
771
|
effect$1 = applyMiddleware(effect$1, middlewareContext, ctx.middlewares);
|
|
619
|
-
|
|
772
|
+
const result = await effect.Runtime.runPromise(context.runtime)(effect$1);
|
|
773
|
+
return await effect.Runtime.runPromise(context.runtime)(encodeResolverOutput(config.type, result));
|
|
620
774
|
}
|
|
621
775
|
};
|
|
622
776
|
if (config.args) {
|
|
@@ -645,7 +799,8 @@ function buildObjectField(config, ctx) {
|
|
|
645
799
|
);
|
|
646
800
|
const middlewareContext = { parent, args, info };
|
|
647
801
|
effect$1 = applyMiddleware(effect$1, middlewareContext, ctx.middlewares);
|
|
648
|
-
|
|
802
|
+
const result = await effect.Runtime.runPromise(context.runtime)(effect$1);
|
|
803
|
+
return await effect.Runtime.runPromise(context.runtime)(encodeResolverOutput(config.type, result));
|
|
649
804
|
}
|
|
650
805
|
};
|
|
651
806
|
if (config.args) {
|
|
@@ -680,13 +835,18 @@ function buildSubscriptionField(config, ctx) {
|
|
|
680
835
|
return streamToAsyncIterator(stream, context.runtime);
|
|
681
836
|
},
|
|
682
837
|
// The resolve function transforms each yielded value
|
|
683
|
-
// If no custom resolve is provided, return the payload directly
|
|
838
|
+
// If no custom resolve is provided, encode and return the payload directly
|
|
684
839
|
resolve: config.resolve ? async (value, args, context, info) => {
|
|
685
840
|
let effect$1 = config.resolve(value, args);
|
|
686
841
|
const middlewareContext = { parent: value, args, info };
|
|
687
842
|
effect$1 = applyMiddleware(effect$1, middlewareContext, ctx.middlewares);
|
|
688
|
-
|
|
689
|
-
|
|
843
|
+
const result = await effect.Runtime.runPromise(context.runtime)(effect$1);
|
|
844
|
+
return await effect.Runtime.runPromise(context.runtime)(
|
|
845
|
+
encodeResolverOutput(config.type, result)
|
|
846
|
+
);
|
|
847
|
+
} : async (value, _args, context) => {
|
|
848
|
+
return await effect.Runtime.runPromise(context.runtime)(encodeResolverOutput(config.type, value));
|
|
849
|
+
}
|
|
690
850
|
};
|
|
691
851
|
if (config.args) {
|
|
692
852
|
fieldConfig.args = toGraphQLArgsWithRegistry(
|