@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/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 S = 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 S__namespace = /*#__PURE__*/_interopNamespace(S);
|
|
27
27
|
var AST__namespace = /*#__PURE__*/_interopNamespace(AST);
|
|
28
28
|
|
|
29
29
|
// src/builder/index.ts
|
|
@@ -41,6 +41,34 @@ var isIntegerType = (ast) => {
|
|
|
41
41
|
}
|
|
42
42
|
return false;
|
|
43
43
|
};
|
|
44
|
+
var isOptionDeclaration = (ast) => {
|
|
45
|
+
if (ast._tag === "Declaration") {
|
|
46
|
+
const annotations = ast.annotations;
|
|
47
|
+
if (annotations) {
|
|
48
|
+
const TypeConstructorSymbol = /* @__PURE__ */ Symbol.for("effect/annotation/TypeConstructor");
|
|
49
|
+
const typeConstructor = annotations[TypeConstructorSymbol];
|
|
50
|
+
if (typeConstructor && typeConstructor._tag === "effect/Option") {
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return false;
|
|
56
|
+
};
|
|
57
|
+
var isOptionTransformation = (ast) => {
|
|
58
|
+
if (ast._tag === "Transformation") {
|
|
59
|
+
return isOptionDeclaration(ast.to);
|
|
60
|
+
}
|
|
61
|
+
return false;
|
|
62
|
+
};
|
|
63
|
+
var getOptionInnerType = (ast) => {
|
|
64
|
+
if (ast._tag === "Declaration") {
|
|
65
|
+
const typeParams = ast.typeParameters;
|
|
66
|
+
if (typeParams && typeParams.length > 0) {
|
|
67
|
+
return typeParams[0];
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return void 0;
|
|
71
|
+
};
|
|
44
72
|
var toGraphQLType = (schema) => {
|
|
45
73
|
const ast = schema.ast;
|
|
46
74
|
if (ast._tag === "StringKeyword") return graphql.GraphQLString;
|
|
@@ -50,7 +78,7 @@ var toGraphQLType = (schema) => {
|
|
|
50
78
|
if (isIntegerType(ast)) {
|
|
51
79
|
return graphql.GraphQLInt;
|
|
52
80
|
}
|
|
53
|
-
return toGraphQLType(
|
|
81
|
+
return toGraphQLType(S__namespace.make(ast.from));
|
|
54
82
|
}
|
|
55
83
|
if (ast._tag === "Literal") {
|
|
56
84
|
if (typeof ast.literal === "string") return graphql.GraphQLString;
|
|
@@ -62,7 +90,7 @@ var toGraphQLType = (schema) => {
|
|
|
62
90
|
if (ast._tag === "TupleType") {
|
|
63
91
|
const elements = ast.elements;
|
|
64
92
|
if (elements.length > 0) {
|
|
65
|
-
const elementSchema =
|
|
93
|
+
const elementSchema = S__namespace.make(elements[0].type);
|
|
66
94
|
return new graphql.GraphQLList(toGraphQLType(elementSchema));
|
|
67
95
|
}
|
|
68
96
|
}
|
|
@@ -70,7 +98,8 @@ var toGraphQLType = (schema) => {
|
|
|
70
98
|
const fields = {};
|
|
71
99
|
for (const field2 of ast.propertySignatures) {
|
|
72
100
|
const fieldName = String(field2.name);
|
|
73
|
-
|
|
101
|
+
if (fieldName === "_tag") continue;
|
|
102
|
+
const fieldSchema = S__namespace.make(field2.type);
|
|
74
103
|
let fieldType = toGraphQLType(fieldSchema);
|
|
75
104
|
if (!field2.isOptional) {
|
|
76
105
|
fieldType = new graphql.GraphQLNonNull(fieldType);
|
|
@@ -84,17 +113,35 @@ var toGraphQLType = (schema) => {
|
|
|
84
113
|
});
|
|
85
114
|
}
|
|
86
115
|
if (ast._tag === "Transformation") {
|
|
87
|
-
|
|
116
|
+
if (isOptionTransformation(ast)) {
|
|
117
|
+
const innerType = getOptionInnerType(ast.to);
|
|
118
|
+
if (innerType) {
|
|
119
|
+
return toGraphQLType(S__namespace.make(innerType));
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return toGraphQLType(S__namespace.make(ast.to));
|
|
123
|
+
}
|
|
124
|
+
if (ast._tag === "Declaration") {
|
|
125
|
+
if (isOptionDeclaration(ast)) {
|
|
126
|
+
const innerType = getOptionInnerType(ast);
|
|
127
|
+
if (innerType) {
|
|
128
|
+
return toGraphQLType(S__namespace.make(innerType));
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
const typeParams = ast.typeParameters;
|
|
132
|
+
if (typeParams && typeParams.length > 0) {
|
|
133
|
+
return toGraphQLType(S__namespace.make(typeParams[0]));
|
|
134
|
+
}
|
|
88
135
|
}
|
|
89
136
|
if (ast._tag === "Union") {
|
|
90
137
|
const types = ast.types;
|
|
91
138
|
if (types.length > 0) {
|
|
92
|
-
return toGraphQLType(
|
|
139
|
+
return toGraphQLType(S__namespace.make(types[0]));
|
|
93
140
|
}
|
|
94
141
|
}
|
|
95
142
|
if (ast._tag === "Suspend") {
|
|
96
143
|
const innerAst = ast.f();
|
|
97
|
-
return toGraphQLType(
|
|
144
|
+
return toGraphQLType(S__namespace.make(innerAst));
|
|
98
145
|
}
|
|
99
146
|
return graphql.GraphQLString;
|
|
100
147
|
};
|
|
@@ -107,7 +154,7 @@ var toGraphQLInputType = (schema) => {
|
|
|
107
154
|
if (isIntegerType(ast)) {
|
|
108
155
|
return graphql.GraphQLInt;
|
|
109
156
|
}
|
|
110
|
-
return toGraphQLInputType(
|
|
157
|
+
return toGraphQLInputType(S__namespace.make(ast.from));
|
|
111
158
|
}
|
|
112
159
|
if (ast._tag === "Literal") {
|
|
113
160
|
if (typeof ast.literal === "string") return graphql.GraphQLString;
|
|
@@ -119,7 +166,7 @@ var toGraphQLInputType = (schema) => {
|
|
|
119
166
|
if (ast._tag === "TupleType") {
|
|
120
167
|
const elements = ast.elements;
|
|
121
168
|
if (elements.length > 0) {
|
|
122
|
-
const elementSchema =
|
|
169
|
+
const elementSchema = S__namespace.make(elements[0].type);
|
|
123
170
|
return new graphql.GraphQLList(toGraphQLInputType(elementSchema));
|
|
124
171
|
}
|
|
125
172
|
}
|
|
@@ -127,7 +174,8 @@ var toGraphQLInputType = (schema) => {
|
|
|
127
174
|
const fields = {};
|
|
128
175
|
for (const field2 of ast.propertySignatures) {
|
|
129
176
|
const fieldName = String(field2.name);
|
|
130
|
-
|
|
177
|
+
if (fieldName === "_tag") continue;
|
|
178
|
+
const fieldSchema = S__namespace.make(field2.type);
|
|
131
179
|
let fieldType = toGraphQLInputType(fieldSchema);
|
|
132
180
|
if (!field2.isOptional) {
|
|
133
181
|
fieldType = new graphql.GraphQLNonNull(fieldType);
|
|
@@ -141,17 +189,33 @@ var toGraphQLInputType = (schema) => {
|
|
|
141
189
|
});
|
|
142
190
|
}
|
|
143
191
|
if (ast._tag === "Transformation") {
|
|
144
|
-
return toGraphQLInputType(
|
|
192
|
+
return toGraphQLInputType(S__namespace.make(ast.from));
|
|
193
|
+
}
|
|
194
|
+
if (ast._tag === "Declaration") {
|
|
195
|
+
if (isOptionDeclaration(ast)) {
|
|
196
|
+
const innerType = getOptionInnerType(ast);
|
|
197
|
+
if (innerType) {
|
|
198
|
+
return toGraphQLInputType(S__namespace.make(innerType));
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
const typeParams = ast.typeParameters;
|
|
202
|
+
if (typeParams && typeParams.length > 0) {
|
|
203
|
+
return toGraphQLInputType(S__namespace.make(typeParams[0]));
|
|
204
|
+
}
|
|
145
205
|
}
|
|
146
206
|
if (ast._tag === "Union") {
|
|
147
207
|
const types = ast.types;
|
|
208
|
+
const nonNullTypes = types.filter((t) => t._tag !== "Literal" || t.literal !== null).filter((t) => t._tag !== "UndefinedKeyword");
|
|
209
|
+
if (nonNullTypes.length > 0) {
|
|
210
|
+
return toGraphQLInputType(S__namespace.make(nonNullTypes[0]));
|
|
211
|
+
}
|
|
148
212
|
if (types.length > 0) {
|
|
149
|
-
return toGraphQLInputType(
|
|
213
|
+
return toGraphQLInputType(S__namespace.make(types[0]));
|
|
150
214
|
}
|
|
151
215
|
}
|
|
152
216
|
if (ast._tag === "Suspend") {
|
|
153
217
|
const innerAst = ast.f();
|
|
154
|
-
return toGraphQLInputType(
|
|
218
|
+
return toGraphQLInputType(S__namespace.make(innerAst));
|
|
155
219
|
}
|
|
156
220
|
return graphql.GraphQLString;
|
|
157
221
|
};
|
|
@@ -161,7 +225,8 @@ var toGraphQLArgs = (schema) => {
|
|
|
161
225
|
const args = {};
|
|
162
226
|
for (const field2 of ast.propertySignatures) {
|
|
163
227
|
const fieldName = String(field2.name);
|
|
164
|
-
|
|
228
|
+
if (fieldName === "_tag") continue;
|
|
229
|
+
const fieldSchema = S__namespace.make(field2.type);
|
|
165
230
|
let fieldType = toGraphQLInputType(fieldSchema);
|
|
166
231
|
if (!field2.isOptional) {
|
|
167
232
|
fieldType = new graphql.GraphQLNonNull(fieldType);
|
|
@@ -261,9 +326,21 @@ function toGraphQLTypeWithRegistry(schema, ctx) {
|
|
|
261
326
|
if (ast._tag === "TupleType") {
|
|
262
327
|
return handleTupleTypeAST(ast, ctx);
|
|
263
328
|
}
|
|
329
|
+
if (ast._tag === "Declaration") {
|
|
330
|
+
if (isOptionDeclaration2(ast)) {
|
|
331
|
+
const innerType = getOptionInnerType2(ast);
|
|
332
|
+
if (innerType) {
|
|
333
|
+
return toGraphQLTypeWithRegistry(S__namespace.make(innerType), ctx);
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
const typeParams = ast.typeParameters;
|
|
337
|
+
if (typeParams && typeParams.length > 0) {
|
|
338
|
+
return toGraphQLTypeWithRegistry(S__namespace.make(typeParams[0]), ctx);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
264
341
|
if (ast._tag === "Suspend") {
|
|
265
342
|
const innerAst = ast.f();
|
|
266
|
-
return toGraphQLTypeWithRegistry(
|
|
343
|
+
return toGraphQLTypeWithRegistry(S__namespace.make(innerAst), ctx);
|
|
267
344
|
}
|
|
268
345
|
return toGraphQLType(schema);
|
|
269
346
|
}
|
|
@@ -281,20 +358,48 @@ function findRegisteredInterface(schema, ast, ctx) {
|
|
|
281
358
|
}
|
|
282
359
|
return void 0;
|
|
283
360
|
}
|
|
361
|
+
function isOptionDeclaration2(ast) {
|
|
362
|
+
if (ast._tag === "Declaration") {
|
|
363
|
+
const annotations = ast.annotations;
|
|
364
|
+
if (annotations) {
|
|
365
|
+
const TypeConstructorSymbol = /* @__PURE__ */ Symbol.for("effect/annotation/TypeConstructor");
|
|
366
|
+
const typeConstructor = annotations[TypeConstructorSymbol];
|
|
367
|
+
if (typeConstructor && typeConstructor._tag === "effect/Option") {
|
|
368
|
+
return true;
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
return false;
|
|
373
|
+
}
|
|
374
|
+
function getOptionInnerType2(ast) {
|
|
375
|
+
if (ast._tag === "Declaration") {
|
|
376
|
+
const typeParams = ast.typeParameters;
|
|
377
|
+
if (typeParams && typeParams.length > 0) {
|
|
378
|
+
return typeParams[0];
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
return void 0;
|
|
382
|
+
}
|
|
284
383
|
function handleTransformationAST(ast, ctx) {
|
|
285
384
|
const toAst = ast.to;
|
|
385
|
+
if (isOptionDeclaration2(toAst)) {
|
|
386
|
+
const innerType = getOptionInnerType2(toAst);
|
|
387
|
+
if (innerType) {
|
|
388
|
+
return toGraphQLTypeWithRegistry(S__namespace.make(innerType), ctx);
|
|
389
|
+
}
|
|
390
|
+
}
|
|
286
391
|
if (toAst._tag === "TupleType") {
|
|
287
392
|
if (toAst.rest && toAst.rest.length > 0) {
|
|
288
|
-
const elementSchema =
|
|
393
|
+
const elementSchema = S__namespace.make(toAst.rest[0].type);
|
|
289
394
|
const elementType = toGraphQLTypeWithRegistry(elementSchema, ctx);
|
|
290
395
|
return new graphql.GraphQLList(elementType);
|
|
291
396
|
} else if (toAst.elements.length > 0) {
|
|
292
|
-
const elementSchema =
|
|
397
|
+
const elementSchema = S__namespace.make(toAst.elements[0].type);
|
|
293
398
|
const elementType = toGraphQLTypeWithRegistry(elementSchema, ctx);
|
|
294
399
|
return new graphql.GraphQLList(elementType);
|
|
295
400
|
}
|
|
296
401
|
}
|
|
297
|
-
return toGraphQLTypeWithRegistry(
|
|
402
|
+
return toGraphQLTypeWithRegistry(S__namespace.make(ast.to), ctx);
|
|
298
403
|
}
|
|
299
404
|
function handleUnionAST(ast, ctx) {
|
|
300
405
|
const allLiterals = ast.types.every((t) => t._tag === "Literal");
|
|
@@ -306,9 +411,9 @@ function handleUnionAST(ast, ctx) {
|
|
|
306
411
|
if (unionType2) return unionType2;
|
|
307
412
|
}
|
|
308
413
|
if (ast.types.length > 0) {
|
|
309
|
-
return toGraphQLTypeWithRegistry(
|
|
414
|
+
return toGraphQLTypeWithRegistry(S__namespace.make(ast.types[0]), ctx);
|
|
310
415
|
}
|
|
311
|
-
return toGraphQLType(
|
|
416
|
+
return toGraphQLType(S__namespace.make(ast));
|
|
312
417
|
}
|
|
313
418
|
function findEnumForLiteralUnion(types, ctx) {
|
|
314
419
|
const literalValues = types.map((t) => String(t.literal)).sort();
|
|
@@ -351,15 +456,15 @@ function findEnumForLiteral(ast, ctx) {
|
|
|
351
456
|
}
|
|
352
457
|
function handleTupleTypeAST(ast, ctx) {
|
|
353
458
|
if (ast.rest && ast.rest.length > 0) {
|
|
354
|
-
const elementSchema =
|
|
459
|
+
const elementSchema = S__namespace.make(ast.rest[0].type);
|
|
355
460
|
const elementType = toGraphQLTypeWithRegistry(elementSchema, ctx);
|
|
356
461
|
return new graphql.GraphQLList(elementType);
|
|
357
462
|
} else if (ast.elements && ast.elements.length > 0) {
|
|
358
|
-
const elementSchema =
|
|
463
|
+
const elementSchema = S__namespace.make(ast.elements[0].type);
|
|
359
464
|
const elementType = toGraphQLTypeWithRegistry(elementSchema, ctx);
|
|
360
465
|
return new graphql.GraphQLList(elementType);
|
|
361
466
|
}
|
|
362
|
-
return toGraphQLType(
|
|
467
|
+
return toGraphQLType(S__namespace.make(ast));
|
|
363
468
|
}
|
|
364
469
|
function schemaToFields(schema, ctx) {
|
|
365
470
|
let ast = schema.ast;
|
|
@@ -368,15 +473,22 @@ function schemaToFields(schema, ctx) {
|
|
|
368
473
|
}
|
|
369
474
|
if (ast._tag === "Declaration") {
|
|
370
475
|
const typeParams = ast.typeParameters;
|
|
371
|
-
if (typeParams && typeParams.length > 0
|
|
372
|
-
|
|
476
|
+
if (typeParams && typeParams.length > 0) {
|
|
477
|
+
let innerAst = typeParams[0];
|
|
478
|
+
while (innerAst._tag === "Transformation") {
|
|
479
|
+
innerAst = innerAst.to;
|
|
480
|
+
}
|
|
481
|
+
if (innerAst._tag === "TypeLiteral") {
|
|
482
|
+
ast = innerAst;
|
|
483
|
+
}
|
|
373
484
|
}
|
|
374
485
|
}
|
|
375
486
|
if (ast._tag === "TypeLiteral") {
|
|
376
487
|
const fields = {};
|
|
377
488
|
for (const field2 of ast.propertySignatures) {
|
|
378
489
|
const fieldName = String(field2.name);
|
|
379
|
-
|
|
490
|
+
if (fieldName === "_tag") continue;
|
|
491
|
+
const fieldSchema = S__namespace.make(field2.type);
|
|
380
492
|
let fieldType = toGraphQLTypeWithRegistry(fieldSchema, ctx);
|
|
381
493
|
if (!field2.isOptional) {
|
|
382
494
|
fieldType = getNonNull(fieldType);
|
|
@@ -388,12 +500,16 @@ function schemaToFields(schema, ctx) {
|
|
|
388
500
|
return {};
|
|
389
501
|
}
|
|
390
502
|
function schemaToInputFields(schema, enumRegistry, inputRegistry, inputs, enums, cache) {
|
|
391
|
-
|
|
503
|
+
let ast = schema.ast;
|
|
504
|
+
while (ast._tag === "Transformation") {
|
|
505
|
+
ast = ast.to;
|
|
506
|
+
}
|
|
392
507
|
if (ast._tag === "TypeLiteral") {
|
|
393
508
|
const fields = {};
|
|
394
509
|
for (const field2 of ast.propertySignatures) {
|
|
395
510
|
const fieldName = String(field2.name);
|
|
396
|
-
|
|
511
|
+
if (fieldName === "_tag") continue;
|
|
512
|
+
const fieldSchema = S__namespace.make(field2.type);
|
|
397
513
|
let fieldType = toGraphQLInputTypeWithRegistry(
|
|
398
514
|
fieldSchema,
|
|
399
515
|
enumRegistry,
|
|
@@ -432,17 +548,6 @@ function buildInputTypeLookupCache(inputs, enums) {
|
|
|
432
548
|
}
|
|
433
549
|
function toGraphQLInputTypeWithRegistry(schema, enumRegistry, inputRegistry, inputs, enums, cache) {
|
|
434
550
|
const ast = schema.ast;
|
|
435
|
-
if (ast._tag === "Transformation") {
|
|
436
|
-
const toAst = ast.to;
|
|
437
|
-
return toGraphQLInputTypeWithRegistry(
|
|
438
|
-
S2__namespace.make(toAst),
|
|
439
|
-
enumRegistry,
|
|
440
|
-
inputRegistry,
|
|
441
|
-
inputs,
|
|
442
|
-
enums,
|
|
443
|
-
cache
|
|
444
|
-
);
|
|
445
|
-
}
|
|
446
551
|
if (cache?.schemaToInputName || cache?.astToInputName) {
|
|
447
552
|
const inputName = cache.schemaToInputName?.get(schema) ?? cache.astToInputName?.get(ast);
|
|
448
553
|
if (inputName) {
|
|
@@ -457,12 +562,23 @@ function toGraphQLInputTypeWithRegistry(schema, enumRegistry, inputRegistry, inp
|
|
|
457
562
|
}
|
|
458
563
|
}
|
|
459
564
|
}
|
|
565
|
+
if (ast._tag === "Transformation") {
|
|
566
|
+
const toAst = ast.to;
|
|
567
|
+
return toGraphQLInputTypeWithRegistry(
|
|
568
|
+
S__namespace.make(toAst),
|
|
569
|
+
enumRegistry,
|
|
570
|
+
inputRegistry,
|
|
571
|
+
inputs,
|
|
572
|
+
enums,
|
|
573
|
+
cache
|
|
574
|
+
);
|
|
575
|
+
}
|
|
460
576
|
if (ast._tag === "Union") {
|
|
461
577
|
const unionAst = ast;
|
|
462
578
|
const nonUndefinedTypes = unionAst.types.filter((t) => t._tag !== "UndefinedKeyword");
|
|
463
579
|
if (nonUndefinedTypes.length === 1 && nonUndefinedTypes[0]._tag === "Union") {
|
|
464
580
|
return toGraphQLInputTypeWithRegistry(
|
|
465
|
-
|
|
581
|
+
S__namespace.make(nonUndefinedTypes[0]),
|
|
466
582
|
enumRegistry,
|
|
467
583
|
inputRegistry,
|
|
468
584
|
inputs,
|
|
@@ -472,7 +588,7 @@ function toGraphQLInputTypeWithRegistry(schema, enumRegistry, inputRegistry, inp
|
|
|
472
588
|
}
|
|
473
589
|
if (nonUndefinedTypes.length === 1 && nonUndefinedTypes[0]._tag === "TypeLiteral") {
|
|
474
590
|
return toGraphQLInputTypeWithRegistry(
|
|
475
|
-
|
|
591
|
+
S__namespace.make(nonUndefinedTypes[0]),
|
|
476
592
|
enumRegistry,
|
|
477
593
|
inputRegistry,
|
|
478
594
|
inputs,
|
|
@@ -512,7 +628,7 @@ function toGraphQLInputTypeWithRegistry(schema, enumRegistry, inputRegistry, inp
|
|
|
512
628
|
if (ast._tag === "Suspend") {
|
|
513
629
|
const innerAst = ast.f();
|
|
514
630
|
return toGraphQLInputTypeWithRegistry(
|
|
515
|
-
|
|
631
|
+
S__namespace.make(innerAst),
|
|
516
632
|
enumRegistry,
|
|
517
633
|
inputRegistry,
|
|
518
634
|
inputs,
|
|
@@ -528,7 +644,8 @@ function toGraphQLArgsWithRegistry(schema, enumRegistry, inputRegistry, inputs,
|
|
|
528
644
|
const args = {};
|
|
529
645
|
for (const field2 of ast.propertySignatures) {
|
|
530
646
|
const fieldName = String(field2.name);
|
|
531
|
-
|
|
647
|
+
if (fieldName === "_tag") continue;
|
|
648
|
+
const fieldSchema = S__namespace.make(field2.type);
|
|
532
649
|
let fieldType = toGraphQLInputTypeWithRegistry(
|
|
533
650
|
fieldSchema,
|
|
534
651
|
enumRegistry,
|
|
@@ -546,6 +663,29 @@ function toGraphQLArgsWithRegistry(schema, enumRegistry, inputRegistry, inputs,
|
|
|
546
663
|
}
|
|
547
664
|
return toGraphQLArgs(schema);
|
|
548
665
|
}
|
|
666
|
+
function isOptionSchema(schema) {
|
|
667
|
+
const ast = schema.ast;
|
|
668
|
+
if (ast._tag === "Transformation") {
|
|
669
|
+
const toAst = ast.to;
|
|
670
|
+
if (toAst._tag === "Declaration") {
|
|
671
|
+
const annotations = toAst.annotations;
|
|
672
|
+
if (annotations) {
|
|
673
|
+
const TypeConstructorSymbol = /* @__PURE__ */ Symbol.for("effect/annotation/TypeConstructor");
|
|
674
|
+
const typeConstructor = annotations[TypeConstructorSymbol];
|
|
675
|
+
if (typeConstructor && typeConstructor._tag === "effect/Option") {
|
|
676
|
+
return true;
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
return false;
|
|
682
|
+
}
|
|
683
|
+
function encodeResolverOutput(schema, value) {
|
|
684
|
+
if (isOptionSchema(schema)) {
|
|
685
|
+
return effect.Effect.orDie(S__namespace.encode(schema)(value));
|
|
686
|
+
}
|
|
687
|
+
return effect.Effect.succeed(value);
|
|
688
|
+
}
|
|
549
689
|
function applyDirectives(effect, directives, directiveRegistrations) {
|
|
550
690
|
if (!directives) return effect;
|
|
551
691
|
let wrapped = effect;
|
|
@@ -580,7 +720,8 @@ function buildField(config, ctx) {
|
|
|
580
720
|
);
|
|
581
721
|
const middlewareContext = { parent: _parent, args, info };
|
|
582
722
|
effect$1 = applyMiddleware(effect$1, middlewareContext, ctx.middlewares);
|
|
583
|
-
|
|
723
|
+
const result = await effect.Runtime.runPromise(context.runtime)(effect$1);
|
|
724
|
+
return await effect.Runtime.runPromise(context.runtime)(encodeResolverOutput(config.type, result));
|
|
584
725
|
}
|
|
585
726
|
};
|
|
586
727
|
if (config.args) {
|
|
@@ -609,7 +750,8 @@ function buildObjectField(config, ctx) {
|
|
|
609
750
|
);
|
|
610
751
|
const middlewareContext = { parent, args, info };
|
|
611
752
|
effect$1 = applyMiddleware(effect$1, middlewareContext, ctx.middlewares);
|
|
612
|
-
|
|
753
|
+
const result = await effect.Runtime.runPromise(context.runtime)(effect$1);
|
|
754
|
+
return await effect.Runtime.runPromise(context.runtime)(encodeResolverOutput(config.type, result));
|
|
613
755
|
}
|
|
614
756
|
};
|
|
615
757
|
if (config.args) {
|
|
@@ -644,13 +786,18 @@ function buildSubscriptionField(config, ctx) {
|
|
|
644
786
|
return streamToAsyncIterator(stream, context.runtime);
|
|
645
787
|
},
|
|
646
788
|
// The resolve function transforms each yielded value
|
|
647
|
-
// If no custom resolve is provided, return the payload directly
|
|
789
|
+
// If no custom resolve is provided, encode and return the payload directly
|
|
648
790
|
resolve: config.resolve ? async (value, args, context, info) => {
|
|
649
791
|
let effect$1 = config.resolve(value, args);
|
|
650
792
|
const middlewareContext = { parent: value, args, info };
|
|
651
793
|
effect$1 = applyMiddleware(effect$1, middlewareContext, ctx.middlewares);
|
|
652
|
-
|
|
653
|
-
|
|
794
|
+
const result = await effect.Runtime.runPromise(context.runtime)(effect$1);
|
|
795
|
+
return await effect.Runtime.runPromise(context.runtime)(
|
|
796
|
+
encodeResolverOutput(config.type, result)
|
|
797
|
+
);
|
|
798
|
+
} : async (value, _args, context) => {
|
|
799
|
+
return await effect.Runtime.runPromise(context.runtime)(encodeResolverOutput(config.type, value));
|
|
800
|
+
}
|
|
654
801
|
};
|
|
655
802
|
if (config.args) {
|
|
656
803
|
fieldConfig.args = toGraphQLArgsWithRegistry(
|