@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/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
  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 S__namespace = /*#__PURE__*/_interopNamespace(S);
30
+ var S2__namespace = /*#__PURE__*/_interopNamespace(S2);
31
31
  var AST__namespace = /*#__PURE__*/_interopNamespace(AST);
32
32
  var DataLoader__default = /*#__PURE__*/_interopDefault(DataLoader);
33
33
 
@@ -83,7 +83,7 @@ var toGraphQLType = (schema) => {
83
83
  if (isIntegerType(ast)) {
84
84
  return graphql.GraphQLInt;
85
85
  }
86
- return toGraphQLType(S__namespace.make(ast.from));
86
+ return toGraphQLType(S2__namespace.make(ast.from));
87
87
  }
88
88
  if (ast._tag === "Literal") {
89
89
  if (typeof ast.literal === "string") return graphql.GraphQLString;
@@ -95,7 +95,7 @@ var toGraphQLType = (schema) => {
95
95
  if (ast._tag === "TupleType") {
96
96
  const elements = ast.elements;
97
97
  if (elements.length > 0) {
98
- const elementSchema = S__namespace.make(elements[0].type);
98
+ const elementSchema = S2__namespace.make(elements[0].type);
99
99
  return new graphql.GraphQLList(toGraphQLType(elementSchema));
100
100
  }
101
101
  }
@@ -104,7 +104,7 @@ var toGraphQLType = (schema) => {
104
104
  for (const field2 of ast.propertySignatures) {
105
105
  const fieldName = String(field2.name);
106
106
  if (fieldName === "_tag") continue;
107
- const fieldSchema = S__namespace.make(field2.type);
107
+ const fieldSchema = S2__namespace.make(field2.type);
108
108
  let fieldType = toGraphQLType(fieldSchema);
109
109
  if (!field2.isOptional) {
110
110
  fieldType = new graphql.GraphQLNonNull(fieldType);
@@ -121,32 +121,32 @@ var toGraphQLType = (schema) => {
121
121
  if (isOptionTransformation(ast)) {
122
122
  const innerType = getOptionInnerType(ast.to);
123
123
  if (innerType) {
124
- return toGraphQLType(S__namespace.make(innerType));
124
+ return toGraphQLType(S2__namespace.make(innerType));
125
125
  }
126
126
  }
127
- return toGraphQLType(S__namespace.make(ast.to));
127
+ return toGraphQLType(S2__namespace.make(ast.to));
128
128
  }
129
129
  if (ast._tag === "Declaration") {
130
130
  if (isOptionDeclaration(ast)) {
131
131
  const innerType = getOptionInnerType(ast);
132
132
  if (innerType) {
133
- return toGraphQLType(S__namespace.make(innerType));
133
+ return toGraphQLType(S2__namespace.make(innerType));
134
134
  }
135
135
  }
136
136
  const typeParams = ast.typeParameters;
137
137
  if (typeParams && typeParams.length > 0) {
138
- return toGraphQLType(S__namespace.make(typeParams[0]));
138
+ return toGraphQLType(S2__namespace.make(typeParams[0]));
139
139
  }
140
140
  }
141
141
  if (ast._tag === "Union") {
142
142
  const types = ast.types;
143
143
  if (types.length > 0) {
144
- return toGraphQLType(S__namespace.make(types[0]));
144
+ return toGraphQLType(S2__namespace.make(types[0]));
145
145
  }
146
146
  }
147
147
  if (ast._tag === "Suspend") {
148
148
  const innerAst = ast.f();
149
- return toGraphQLType(S__namespace.make(innerAst));
149
+ return toGraphQLType(S2__namespace.make(innerAst));
150
150
  }
151
151
  return graphql.GraphQLString;
152
152
  };
@@ -159,7 +159,7 @@ var toGraphQLInputType = (schema) => {
159
159
  if (isIntegerType(ast)) {
160
160
  return graphql.GraphQLInt;
161
161
  }
162
- return toGraphQLInputType(S__namespace.make(ast.from));
162
+ return toGraphQLInputType(S2__namespace.make(ast.from));
163
163
  }
164
164
  if (ast._tag === "Literal") {
165
165
  if (typeof ast.literal === "string") return graphql.GraphQLString;
@@ -171,7 +171,7 @@ var toGraphQLInputType = (schema) => {
171
171
  if (ast._tag === "TupleType") {
172
172
  const elements = ast.elements;
173
173
  if (elements.length > 0) {
174
- const elementSchema = S__namespace.make(elements[0].type);
174
+ const elementSchema = S2__namespace.make(elements[0].type);
175
175
  return new graphql.GraphQLList(toGraphQLInputType(elementSchema));
176
176
  }
177
177
  }
@@ -180,7 +180,7 @@ var toGraphQLInputType = (schema) => {
180
180
  for (const field2 of ast.propertySignatures) {
181
181
  const fieldName = String(field2.name);
182
182
  if (fieldName === "_tag") continue;
183
- const fieldSchema = S__namespace.make(field2.type);
183
+ const fieldSchema = S2__namespace.make(field2.type);
184
184
  let fieldType = toGraphQLInputType(fieldSchema);
185
185
  if (!field2.isOptional) {
186
186
  fieldType = new graphql.GraphQLNonNull(fieldType);
@@ -194,33 +194,33 @@ var toGraphQLInputType = (schema) => {
194
194
  });
195
195
  }
196
196
  if (ast._tag === "Transformation") {
197
- return toGraphQLInputType(S__namespace.make(ast.from));
197
+ return toGraphQLInputType(S2__namespace.make(ast.from));
198
198
  }
199
199
  if (ast._tag === "Declaration") {
200
200
  if (isOptionDeclaration(ast)) {
201
201
  const innerType = getOptionInnerType(ast);
202
202
  if (innerType) {
203
- return toGraphQLInputType(S__namespace.make(innerType));
203
+ return toGraphQLInputType(S2__namespace.make(innerType));
204
204
  }
205
205
  }
206
206
  const typeParams = ast.typeParameters;
207
207
  if (typeParams && typeParams.length > 0) {
208
- return toGraphQLInputType(S__namespace.make(typeParams[0]));
208
+ return toGraphQLInputType(S2__namespace.make(typeParams[0]));
209
209
  }
210
210
  }
211
211
  if (ast._tag === "Union") {
212
212
  const types = ast.types;
213
213
  const nonNullTypes = types.filter((t) => t._tag !== "Literal" || t.literal !== null).filter((t) => t._tag !== "UndefinedKeyword");
214
214
  if (nonNullTypes.length > 0) {
215
- return toGraphQLInputType(S__namespace.make(nonNullTypes[0]));
215
+ return toGraphQLInputType(S2__namespace.make(nonNullTypes[0]));
216
216
  }
217
217
  if (types.length > 0) {
218
- return toGraphQLInputType(S__namespace.make(types[0]));
218
+ return toGraphQLInputType(S2__namespace.make(types[0]));
219
219
  }
220
220
  }
221
221
  if (ast._tag === "Suspend") {
222
222
  const innerAst = ast.f();
223
- return toGraphQLInputType(S__namespace.make(innerAst));
223
+ return toGraphQLInputType(S2__namespace.make(innerAst));
224
224
  }
225
225
  return graphql.GraphQLString;
226
226
  };
@@ -243,7 +243,7 @@ var toGraphQLObjectType = (name, schema, additionalFields) => {
243
243
  for (const field2 of ast.propertySignatures) {
244
244
  const fieldName = String(field2.name);
245
245
  if (fieldName === "_tag") continue;
246
- const fieldSchema = S__namespace.make(field2.type);
246
+ const fieldSchema = S2__namespace.make(field2.type);
247
247
  let fieldType = toGraphQLType(fieldSchema);
248
248
  if (!field2.isOptional) {
249
249
  fieldType = new graphql.GraphQLNonNull(fieldType);
@@ -275,7 +275,7 @@ var toGraphQLArgs = (schema) => {
275
275
  for (const field2 of ast.propertySignatures) {
276
276
  const fieldName = String(field2.name);
277
277
  if (fieldName === "_tag") continue;
278
- const fieldSchema = S__namespace.make(field2.type);
278
+ const fieldSchema = S2__namespace.make(field2.type);
279
279
  let fieldType = toGraphQLInputType(fieldSchema);
280
280
  if (!field2.isOptional) {
281
281
  fieldType = new graphql.GraphQLNonNull(fieldType);
@@ -311,6 +311,14 @@ function buildReverseLookups(ctx) {
311
311
  for (const [typeName, typeReg] of ctx.types) {
312
312
  ctx.schemaToTypeName.set(typeReg.schema, typeName);
313
313
  ctx.astToTypeName.set(typeReg.schema.ast, typeName);
314
+ let ast = typeReg.schema.ast;
315
+ while (ast._tag === "Transformation") {
316
+ ast = ast.to;
317
+ ctx.astToTypeName.set(ast, typeName);
318
+ }
319
+ if (ast._tag === "Declaration" && ast.typeParameters?.[0]) {
320
+ ctx.astToTypeName.set(ast.typeParameters[0], typeName);
321
+ }
314
322
  }
315
323
  }
316
324
  if (!ctx.schemaToInterfaceName) {
@@ -319,6 +327,14 @@ function buildReverseLookups(ctx) {
319
327
  for (const [interfaceName, interfaceReg] of ctx.interfaces) {
320
328
  ctx.schemaToInterfaceName.set(interfaceReg.schema, interfaceName);
321
329
  ctx.astToInterfaceName.set(interfaceReg.schema.ast, interfaceName);
330
+ let ast = interfaceReg.schema.ast;
331
+ while (ast._tag === "Transformation") {
332
+ ast = ast.to;
333
+ ctx.astToInterfaceName.set(ast, interfaceName);
334
+ }
335
+ if (ast._tag === "Declaration" && ast.typeParameters?.[0]) {
336
+ ctx.astToInterfaceName.set(ast.typeParameters[0], interfaceName);
337
+ }
322
338
  }
323
339
  }
324
340
  if (!ctx.schemaToInputName) {
@@ -327,6 +343,14 @@ function buildReverseLookups(ctx) {
327
343
  for (const [inputName, inputReg] of ctx.inputs) {
328
344
  ctx.schemaToInputName.set(inputReg.schema, inputName);
329
345
  ctx.astToInputName.set(inputReg.schema.ast, inputName);
346
+ let ast = inputReg.schema.ast;
347
+ while (ast._tag === "Transformation") {
348
+ ast = ast.to;
349
+ ctx.astToInputName.set(ast, inputName);
350
+ }
351
+ if (ast._tag === "Declaration" && ast.typeParameters?.[0]) {
352
+ ctx.astToInputName.set(ast.typeParameters[0], inputName);
353
+ }
330
354
  }
331
355
  }
332
356
  if (!ctx.enumSortedValues) {
@@ -379,17 +403,17 @@ function toGraphQLTypeWithRegistry(schema, ctx) {
379
403
  if (isOptionDeclaration2(ast)) {
380
404
  const innerType = getOptionInnerType2(ast);
381
405
  if (innerType) {
382
- return toGraphQLTypeWithRegistry(S__namespace.make(innerType), ctx);
406
+ return toGraphQLTypeWithRegistry(S2__namespace.make(innerType), ctx);
383
407
  }
384
408
  }
385
409
  const typeParams = ast.typeParameters;
386
410
  if (typeParams && typeParams.length > 0) {
387
- return toGraphQLTypeWithRegistry(S__namespace.make(typeParams[0]), ctx);
411
+ return toGraphQLTypeWithRegistry(S2__namespace.make(typeParams[0]), ctx);
388
412
  }
389
413
  }
390
414
  if (ast._tag === "Suspend") {
391
415
  const innerAst = ast.f();
392
- return toGraphQLTypeWithRegistry(S__namespace.make(innerAst), ctx);
416
+ return toGraphQLTypeWithRegistry(S2__namespace.make(innerAst), ctx);
393
417
  }
394
418
  return toGraphQLType(schema);
395
419
  }
@@ -454,21 +478,21 @@ function handleTransformationAST(ast, ctx) {
454
478
  }
455
479
  const innerType = getOptionInnerType2(toAst);
456
480
  if (innerType) {
457
- return toGraphQLTypeWithRegistry(S__namespace.make(innerType), ctx);
481
+ return toGraphQLTypeWithRegistry(S2__namespace.make(innerType), ctx);
458
482
  }
459
483
  }
460
484
  if (toAst._tag === "TupleType") {
461
485
  if (toAst.rest && toAst.rest.length > 0) {
462
- const elementSchema = S__namespace.make(toAst.rest[0].type);
486
+ const elementSchema = S2__namespace.make(toAst.rest[0].type);
463
487
  const elementType = toGraphQLTypeWithRegistry(elementSchema, ctx);
464
488
  return new graphql.GraphQLList(elementType);
465
489
  } else if (toAst.elements.length > 0) {
466
- const elementSchema = S__namespace.make(toAst.elements[0].type);
490
+ const elementSchema = S2__namespace.make(toAst.elements[0].type);
467
491
  const elementType = toGraphQLTypeWithRegistry(elementSchema, ctx);
468
492
  return new graphql.GraphQLList(elementType);
469
493
  }
470
494
  }
471
- return toGraphQLTypeWithRegistry(S__namespace.make(ast.to), ctx);
495
+ return toGraphQLTypeWithRegistry(S2__namespace.make(ast.to), ctx);
472
496
  }
473
497
  function handleUnionAST(ast, ctx) {
474
498
  const allLiterals = ast.types.every((t) => t._tag === "Literal");
@@ -493,11 +517,22 @@ function handleUnionAST(ast, ctx) {
493
517
  if (result) return result;
494
518
  }
495
519
  }
520
+ if (memberAst._tag === "TypeLiteral") {
521
+ const valueField = memberAst.propertySignatures?.find(
522
+ (p) => String(p.name) === "value"
523
+ );
524
+ if (valueField) {
525
+ const innerResult = toGraphQLTypeWithRegistry(S2__namespace.make(valueField.type), ctx);
526
+ if (innerResult) {
527
+ return innerResult;
528
+ }
529
+ }
530
+ }
496
531
  }
497
532
  if (ast.types.length > 0) {
498
- return toGraphQLTypeWithRegistry(S__namespace.make(ast.types[0]), ctx);
533
+ return toGraphQLTypeWithRegistry(S2__namespace.make(ast.types[0]), ctx);
499
534
  }
500
- return toGraphQLType(S__namespace.make(ast));
535
+ return toGraphQLType(S2__namespace.make(ast));
501
536
  }
502
537
  function findEnumForLiteralUnion(types, ctx) {
503
538
  const literalValues = types.map((t) => String(t.literal)).sort();
@@ -540,15 +575,15 @@ function findEnumForLiteral(ast, ctx) {
540
575
  }
541
576
  function handleTupleTypeAST(ast, ctx) {
542
577
  if (ast.rest && ast.rest.length > 0) {
543
- const elementSchema = S__namespace.make(ast.rest[0].type);
578
+ const elementSchema = S2__namespace.make(ast.rest[0].type);
544
579
  const elementType = toGraphQLTypeWithRegistry(elementSchema, ctx);
545
580
  return new graphql.GraphQLList(elementType);
546
581
  } else if (ast.elements && ast.elements.length > 0) {
547
- const elementSchema = S__namespace.make(ast.elements[0].type);
582
+ const elementSchema = S2__namespace.make(ast.elements[0].type);
548
583
  const elementType = toGraphQLTypeWithRegistry(elementSchema, ctx);
549
584
  return new graphql.GraphQLList(elementType);
550
585
  }
551
- return toGraphQLType(S__namespace.make(ast));
586
+ return toGraphQLType(S2__namespace.make(ast));
552
587
  }
553
588
  function schemaToFields(schema, ctx) {
554
589
  let ast = schema.ast;
@@ -572,7 +607,7 @@ function schemaToFields(schema, ctx) {
572
607
  for (const field2 of ast.propertySignatures) {
573
608
  const fieldName = String(field2.name);
574
609
  if (fieldName === "_tag") continue;
575
- const fieldSchema = S__namespace.make(field2.type);
610
+ const fieldSchema = S2__namespace.make(field2.type);
576
611
  let fieldType = toGraphQLTypeWithRegistry(fieldSchema, ctx);
577
612
  if (!field2.isOptional) {
578
613
  fieldType = getNonNull(fieldType);
@@ -593,7 +628,7 @@ function schemaToInputFields(schema, enumRegistry, inputRegistry, inputs, enums,
593
628
  for (const field2 of ast.propertySignatures) {
594
629
  const fieldName = String(field2.name);
595
630
  if (fieldName === "_tag") continue;
596
- const fieldSchema = S__namespace.make(field2.type);
631
+ const fieldSchema = S2__namespace.make(field2.type);
597
632
  let fieldType = toGraphQLInputTypeWithRegistry(
598
633
  fieldSchema,
599
634
  enumRegistry,
@@ -621,6 +656,14 @@ function buildInputTypeLookupCache(inputs, enums) {
621
656
  for (const [inputName, inputReg] of inputs) {
622
657
  cache.schemaToInputName.set(inputReg.schema, inputName);
623
658
  cache.astToInputName.set(inputReg.schema.ast, inputName);
659
+ let ast = inputReg.schema.ast;
660
+ while (ast._tag === "Transformation") {
661
+ ast = ast.to;
662
+ cache.astToInputName.set(ast, inputName);
663
+ }
664
+ if (ast._tag === "Declaration" && ast.typeParameters?.[0]) {
665
+ cache.astToInputName.set(ast.typeParameters[0], inputName);
666
+ }
624
667
  }
625
668
  for (const [enumName, enumReg] of enums) {
626
669
  cache.enumSortedValues.set(enumName, [...enumReg.values].sort());
@@ -666,10 +709,28 @@ function toGraphQLInputTypeWithRegistry(schema, enumRegistry, inputRegistry, inp
666
709
  if (result) return result;
667
710
  }
668
711
  }
712
+ if (memberAst._tag === "TypeLiteral") {
713
+ const valueField = memberAst.propertySignatures?.find(
714
+ (p) => String(p.name) === "value"
715
+ );
716
+ if (valueField) {
717
+ const innerResult = toGraphQLInputTypeWithRegistry(
718
+ S2__namespace.make(valueField.type),
719
+ enumRegistry,
720
+ inputRegistry,
721
+ inputs,
722
+ enums,
723
+ cache
724
+ );
725
+ if (innerResult) {
726
+ return innerResult;
727
+ }
728
+ }
729
+ }
669
730
  }
670
731
  }
671
732
  return toGraphQLInputTypeWithRegistry(
672
- S__namespace.make(toAst),
733
+ S2__namespace.make(toAst),
673
734
  enumRegistry,
674
735
  inputRegistry,
675
736
  inputs,
@@ -682,7 +743,7 @@ function toGraphQLInputTypeWithRegistry(schema, enumRegistry, inputRegistry, inp
682
743
  const nonUndefinedTypes = unionAst.types.filter((t) => t._tag !== "UndefinedKeyword");
683
744
  if (nonUndefinedTypes.length === 1 && nonUndefinedTypes[0]._tag === "Union") {
684
745
  return toGraphQLInputTypeWithRegistry(
685
- S__namespace.make(nonUndefinedTypes[0]),
746
+ S2__namespace.make(nonUndefinedTypes[0]),
686
747
  enumRegistry,
687
748
  inputRegistry,
688
749
  inputs,
@@ -692,7 +753,7 @@ function toGraphQLInputTypeWithRegistry(schema, enumRegistry, inputRegistry, inp
692
753
  }
693
754
  if (nonUndefinedTypes.length === 1 && nonUndefinedTypes[0]._tag === "TypeLiteral") {
694
755
  return toGraphQLInputTypeWithRegistry(
695
- S__namespace.make(nonUndefinedTypes[0]),
756
+ S2__namespace.make(nonUndefinedTypes[0]),
696
757
  enumRegistry,
697
758
  inputRegistry,
698
759
  inputs,
@@ -714,6 +775,24 @@ function toGraphQLInputTypeWithRegistry(schema, enumRegistry, inputRegistry, inp
714
775
  if (result) return result;
715
776
  }
716
777
  }
778
+ if (memberAst._tag === "TypeLiteral") {
779
+ const valueField = memberAst.propertySignatures?.find(
780
+ (p) => String(p.name) === "value"
781
+ );
782
+ if (valueField) {
783
+ const innerResult = toGraphQLInputTypeWithRegistry(
784
+ S2__namespace.make(valueField.type),
785
+ enumRegistry,
786
+ inputRegistry,
787
+ inputs,
788
+ enums,
789
+ cache
790
+ );
791
+ if (innerResult) {
792
+ return innerResult;
793
+ }
794
+ }
795
+ }
717
796
  }
718
797
  const allLiterals = unionAst.types.every((t) => t._tag === "Literal");
719
798
  if (allLiterals) {
@@ -747,7 +826,7 @@ function toGraphQLInputTypeWithRegistry(schema, enumRegistry, inputRegistry, inp
747
826
  if (ast._tag === "Suspend") {
748
827
  const innerAst = ast.f();
749
828
  return toGraphQLInputTypeWithRegistry(
750
- S__namespace.make(innerAst),
829
+ S2__namespace.make(innerAst),
751
830
  enumRegistry,
752
831
  inputRegistry,
753
832
  inputs,
@@ -764,7 +843,7 @@ function toGraphQLArgsWithRegistry(schema, enumRegistry, inputRegistry, inputs,
764
843
  for (const field2 of ast.propertySignatures) {
765
844
  const fieldName = String(field2.name);
766
845
  if (fieldName === "_tag") continue;
767
- const fieldSchema = S__namespace.make(field2.type);
846
+ const fieldSchema = S2__namespace.make(field2.type);
768
847
  let fieldType = toGraphQLInputTypeWithRegistry(
769
848
  fieldSchema,
770
849
  enumRegistry,
@@ -801,7 +880,7 @@ function isOptionSchema(schema) {
801
880
  }
802
881
  function encodeResolverOutput(schema, value) {
803
882
  if (isOptionSchema(schema)) {
804
- return effect.Effect.orDie(S__namespace.encode(schema)(value));
883
+ return effect.Effect.orDie(S2__namespace.encode(schema)(value));
805
884
  }
806
885
  return effect.Effect.succeed(value);
807
886
  }