@effect-gql/core 1.4.2 → 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 CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  var graphql = require('graphql');
4
4
  var effect = require('effect');
5
- var S = require('effect/Schema');
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 S__namespace = /*#__PURE__*/_interopNamespace(S);
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(S__namespace.make(ast.from));
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 = S__namespace.make(elements[0].type);
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 = S__namespace.make(field2.type);
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(S__namespace.make(innerType));
119
+ return toGraphQLType(S2__namespace.make(innerType));
120
120
  }
121
121
  }
122
- return toGraphQLType(S__namespace.make(ast.to));
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(S__namespace.make(innerType));
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(S__namespace.make(typeParams[0]));
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(S__namespace.make(types[0]));
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(S__namespace.make(innerAst));
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(S__namespace.make(ast.from));
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 = S__namespace.make(elements[0].type);
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 = S__namespace.make(field2.type);
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(S__namespace.make(ast.from));
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(S__namespace.make(innerType));
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(S__namespace.make(typeParams[0]));
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(S__namespace.make(nonNullTypes[0]));
210
+ return toGraphQLInputType(S2__namespace.make(nonNullTypes[0]));
211
211
  }
212
212
  if (types.length > 0) {
213
- return toGraphQLInputType(S__namespace.make(types[0]));
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(S__namespace.make(innerAst));
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 = S__namespace.make(field2.type);
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);
@@ -262,6 +262,14 @@ function buildReverseLookups(ctx) {
262
262
  for (const [typeName, typeReg] of ctx.types) {
263
263
  ctx.schemaToTypeName.set(typeReg.schema, typeName);
264
264
  ctx.astToTypeName.set(typeReg.schema.ast, typeName);
265
+ let ast = typeReg.schema.ast;
266
+ while (ast._tag === "Transformation") {
267
+ ast = ast.to;
268
+ ctx.astToTypeName.set(ast, typeName);
269
+ }
270
+ if (ast._tag === "Declaration" && ast.typeParameters?.[0]) {
271
+ ctx.astToTypeName.set(ast.typeParameters[0], typeName);
272
+ }
265
273
  }
266
274
  }
267
275
  if (!ctx.schemaToInterfaceName) {
@@ -270,6 +278,14 @@ function buildReverseLookups(ctx) {
270
278
  for (const [interfaceName, interfaceReg] of ctx.interfaces) {
271
279
  ctx.schemaToInterfaceName.set(interfaceReg.schema, interfaceName);
272
280
  ctx.astToInterfaceName.set(interfaceReg.schema.ast, interfaceName);
281
+ let ast = interfaceReg.schema.ast;
282
+ while (ast._tag === "Transformation") {
283
+ ast = ast.to;
284
+ ctx.astToInterfaceName.set(ast, interfaceName);
285
+ }
286
+ if (ast._tag === "Declaration" && ast.typeParameters?.[0]) {
287
+ ctx.astToInterfaceName.set(ast.typeParameters[0], interfaceName);
288
+ }
273
289
  }
274
290
  }
275
291
  if (!ctx.schemaToInputName) {
@@ -278,6 +294,14 @@ function buildReverseLookups(ctx) {
278
294
  for (const [inputName, inputReg] of ctx.inputs) {
279
295
  ctx.schemaToInputName.set(inputReg.schema, inputName);
280
296
  ctx.astToInputName.set(inputReg.schema.ast, inputName);
297
+ let ast = inputReg.schema.ast;
298
+ while (ast._tag === "Transformation") {
299
+ ast = ast.to;
300
+ ctx.astToInputName.set(ast, inputName);
301
+ }
302
+ if (ast._tag === "Declaration" && ast.typeParameters?.[0]) {
303
+ ctx.astToInputName.set(ast.typeParameters[0], inputName);
304
+ }
281
305
  }
282
306
  }
283
307
  if (!ctx.enumSortedValues) {
@@ -330,17 +354,17 @@ function toGraphQLTypeWithRegistry(schema, ctx) {
330
354
  if (isOptionDeclaration2(ast)) {
331
355
  const innerType = getOptionInnerType2(ast);
332
356
  if (innerType) {
333
- return toGraphQLTypeWithRegistry(S__namespace.make(innerType), ctx);
357
+ return toGraphQLTypeWithRegistry(S2__namespace.make(innerType), ctx);
334
358
  }
335
359
  }
336
360
  const typeParams = ast.typeParameters;
337
361
  if (typeParams && typeParams.length > 0) {
338
- return toGraphQLTypeWithRegistry(S__namespace.make(typeParams[0]), ctx);
362
+ return toGraphQLTypeWithRegistry(S2__namespace.make(typeParams[0]), ctx);
339
363
  }
340
364
  }
341
365
  if (ast._tag === "Suspend") {
342
366
  const innerAst = ast.f();
343
- return toGraphQLTypeWithRegistry(S__namespace.make(innerAst), ctx);
367
+ return toGraphQLTypeWithRegistry(S2__namespace.make(innerAst), ctx);
344
368
  }
345
369
  return toGraphQLType(schema);
346
370
  }
@@ -405,21 +429,21 @@ function handleTransformationAST(ast, ctx) {
405
429
  }
406
430
  const innerType = getOptionInnerType2(toAst);
407
431
  if (innerType) {
408
- return toGraphQLTypeWithRegistry(S__namespace.make(innerType), ctx);
432
+ return toGraphQLTypeWithRegistry(S2__namespace.make(innerType), ctx);
409
433
  }
410
434
  }
411
435
  if (toAst._tag === "TupleType") {
412
436
  if (toAst.rest && toAst.rest.length > 0) {
413
- const elementSchema = S__namespace.make(toAst.rest[0].type);
437
+ const elementSchema = S2__namespace.make(toAst.rest[0].type);
414
438
  const elementType = toGraphQLTypeWithRegistry(elementSchema, ctx);
415
439
  return new graphql.GraphQLList(elementType);
416
440
  } else if (toAst.elements.length > 0) {
417
- const elementSchema = S__namespace.make(toAst.elements[0].type);
441
+ const elementSchema = S2__namespace.make(toAst.elements[0].type);
418
442
  const elementType = toGraphQLTypeWithRegistry(elementSchema, ctx);
419
443
  return new graphql.GraphQLList(elementType);
420
444
  }
421
445
  }
422
- return toGraphQLTypeWithRegistry(S__namespace.make(ast.to), ctx);
446
+ return toGraphQLTypeWithRegistry(S2__namespace.make(ast.to), ctx);
423
447
  }
424
448
  function handleUnionAST(ast, ctx) {
425
449
  const allLiterals = ast.types.every((t) => t._tag === "Literal");
@@ -444,11 +468,22 @@ function handleUnionAST(ast, ctx) {
444
468
  if (result) return result;
445
469
  }
446
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
+ }
447
482
  }
448
483
  if (ast.types.length > 0) {
449
- return toGraphQLTypeWithRegistry(S__namespace.make(ast.types[0]), ctx);
484
+ return toGraphQLTypeWithRegistry(S2__namespace.make(ast.types[0]), ctx);
450
485
  }
451
- return toGraphQLType(S__namespace.make(ast));
486
+ return toGraphQLType(S2__namespace.make(ast));
452
487
  }
453
488
  function findEnumForLiteralUnion(types, ctx) {
454
489
  const literalValues = types.map((t) => String(t.literal)).sort();
@@ -491,15 +526,15 @@ function findEnumForLiteral(ast, ctx) {
491
526
  }
492
527
  function handleTupleTypeAST(ast, ctx) {
493
528
  if (ast.rest && ast.rest.length > 0) {
494
- const elementSchema = S__namespace.make(ast.rest[0].type);
529
+ const elementSchema = S2__namespace.make(ast.rest[0].type);
495
530
  const elementType = toGraphQLTypeWithRegistry(elementSchema, ctx);
496
531
  return new graphql.GraphQLList(elementType);
497
532
  } else if (ast.elements && ast.elements.length > 0) {
498
- const elementSchema = S__namespace.make(ast.elements[0].type);
533
+ const elementSchema = S2__namespace.make(ast.elements[0].type);
499
534
  const elementType = toGraphQLTypeWithRegistry(elementSchema, ctx);
500
535
  return new graphql.GraphQLList(elementType);
501
536
  }
502
- return toGraphQLType(S__namespace.make(ast));
537
+ return toGraphQLType(S2__namespace.make(ast));
503
538
  }
504
539
  function schemaToFields(schema, ctx) {
505
540
  let ast = schema.ast;
@@ -523,7 +558,7 @@ function schemaToFields(schema, ctx) {
523
558
  for (const field2 of ast.propertySignatures) {
524
559
  const fieldName = String(field2.name);
525
560
  if (fieldName === "_tag") continue;
526
- const fieldSchema = S__namespace.make(field2.type);
561
+ const fieldSchema = S2__namespace.make(field2.type);
527
562
  let fieldType = toGraphQLTypeWithRegistry(fieldSchema, ctx);
528
563
  if (!field2.isOptional) {
529
564
  fieldType = getNonNull(fieldType);
@@ -544,7 +579,7 @@ function schemaToInputFields(schema, enumRegistry, inputRegistry, inputs, enums,
544
579
  for (const field2 of ast.propertySignatures) {
545
580
  const fieldName = String(field2.name);
546
581
  if (fieldName === "_tag") continue;
547
- const fieldSchema = S__namespace.make(field2.type);
582
+ const fieldSchema = S2__namespace.make(field2.type);
548
583
  let fieldType = toGraphQLInputTypeWithRegistry(
549
584
  fieldSchema,
550
585
  enumRegistry,
@@ -572,6 +607,14 @@ function buildInputTypeLookupCache(inputs, enums) {
572
607
  for (const [inputName, inputReg] of inputs) {
573
608
  cache.schemaToInputName.set(inputReg.schema, inputName);
574
609
  cache.astToInputName.set(inputReg.schema.ast, inputName);
610
+ let ast = inputReg.schema.ast;
611
+ while (ast._tag === "Transformation") {
612
+ ast = ast.to;
613
+ cache.astToInputName.set(ast, inputName);
614
+ }
615
+ if (ast._tag === "Declaration" && ast.typeParameters?.[0]) {
616
+ cache.astToInputName.set(ast.typeParameters[0], inputName);
617
+ }
575
618
  }
576
619
  for (const [enumName, enumReg] of enums) {
577
620
  cache.enumSortedValues.set(enumName, [...enumReg.values].sort());
@@ -617,10 +660,28 @@ function toGraphQLInputTypeWithRegistry(schema, enumRegistry, inputRegistry, inp
617
660
  if (result) return result;
618
661
  }
619
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
+ }
620
681
  }
621
682
  }
622
683
  return toGraphQLInputTypeWithRegistry(
623
- S__namespace.make(toAst),
684
+ S2__namespace.make(toAst),
624
685
  enumRegistry,
625
686
  inputRegistry,
626
687
  inputs,
@@ -633,7 +694,7 @@ function toGraphQLInputTypeWithRegistry(schema, enumRegistry, inputRegistry, inp
633
694
  const nonUndefinedTypes = unionAst.types.filter((t) => t._tag !== "UndefinedKeyword");
634
695
  if (nonUndefinedTypes.length === 1 && nonUndefinedTypes[0]._tag === "Union") {
635
696
  return toGraphQLInputTypeWithRegistry(
636
- S__namespace.make(nonUndefinedTypes[0]),
697
+ S2__namespace.make(nonUndefinedTypes[0]),
637
698
  enumRegistry,
638
699
  inputRegistry,
639
700
  inputs,
@@ -643,7 +704,7 @@ function toGraphQLInputTypeWithRegistry(schema, enumRegistry, inputRegistry, inp
643
704
  }
644
705
  if (nonUndefinedTypes.length === 1 && nonUndefinedTypes[0]._tag === "TypeLiteral") {
645
706
  return toGraphQLInputTypeWithRegistry(
646
- S__namespace.make(nonUndefinedTypes[0]),
707
+ S2__namespace.make(nonUndefinedTypes[0]),
647
708
  enumRegistry,
648
709
  inputRegistry,
649
710
  inputs,
@@ -665,6 +726,24 @@ function toGraphQLInputTypeWithRegistry(schema, enumRegistry, inputRegistry, inp
665
726
  if (result) return result;
666
727
  }
667
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
+ }
668
747
  }
669
748
  const allLiterals = unionAst.types.every((t) => t._tag === "Literal");
670
749
  if (allLiterals) {
@@ -698,7 +777,7 @@ function toGraphQLInputTypeWithRegistry(schema, enumRegistry, inputRegistry, inp
698
777
  if (ast._tag === "Suspend") {
699
778
  const innerAst = ast.f();
700
779
  return toGraphQLInputTypeWithRegistry(
701
- S__namespace.make(innerAst),
780
+ S2__namespace.make(innerAst),
702
781
  enumRegistry,
703
782
  inputRegistry,
704
783
  inputs,
@@ -715,7 +794,7 @@ function toGraphQLArgsWithRegistry(schema, enumRegistry, inputRegistry, inputs,
715
794
  for (const field2 of ast.propertySignatures) {
716
795
  const fieldName = String(field2.name);
717
796
  if (fieldName === "_tag") continue;
718
- const fieldSchema = S__namespace.make(field2.type);
797
+ const fieldSchema = S2__namespace.make(field2.type);
719
798
  let fieldType = toGraphQLInputTypeWithRegistry(
720
799
  fieldSchema,
721
800
  enumRegistry,
@@ -752,7 +831,7 @@ function isOptionSchema(schema) {
752
831
  }
753
832
  function encodeResolverOutput(schema, value) {
754
833
  if (isOptionSchema(schema)) {
755
- return effect.Effect.orDie(S__namespace.encode(schema)(value));
834
+ return effect.Effect.orDie(S2__namespace.encode(schema)(value));
756
835
  }
757
836
  return effect.Effect.succeed(value);
758
837
  }