@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.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { GraphQLDirective, GraphQLEnumType, GraphQLInputObjectType, GraphQLInterfaceType, GraphQLObjectType, GraphQLUnionType, GraphQLSchema, GraphQLNonNull, GraphQLString, GraphQLFloat, GraphQLBoolean, GraphQLInt, GraphQLList, parse, GraphQLError, validate, execute as execute$1, Kind, specifiedRules, NoSchemaIntrospectionCustomRule, subscribe, GraphQLScalarType } from 'graphql';
2
2
  export { DirectiveLocation, GraphQLBoolean, GraphQLEnumType, GraphQLFloat, GraphQLID, GraphQLInputObjectType, GraphQLInt, GraphQLInterfaceType, GraphQLList, GraphQLNonNull, GraphQLObjectType, GraphQLScalarType, GraphQLSchema, GraphQLString, GraphQLUnionType, Kind, graphql, lexicographicSortSchema, printSchema } from 'graphql';
3
3
  import { Pipeable, Context, Data, Layer, Effect, Ref, HashMap, Config, Option, Schema, Runtime, Queue, Stream, Fiber, Deferred } from 'effect';
4
- import * as S from 'effect/Schema';
4
+ import * as S2 from 'effect/Schema';
5
5
  import * as AST from 'effect/SchemaAST';
6
6
  import DataLoader from 'dataloader';
7
7
  import { HttpIncomingMessage, HttpServerResponse, HttpServerRequest, HttpRouter } from '@effect/platform';
@@ -58,7 +58,7 @@ var toGraphQLType = (schema) => {
58
58
  if (isIntegerType(ast)) {
59
59
  return GraphQLInt;
60
60
  }
61
- return toGraphQLType(S.make(ast.from));
61
+ return toGraphQLType(S2.make(ast.from));
62
62
  }
63
63
  if (ast._tag === "Literal") {
64
64
  if (typeof ast.literal === "string") return GraphQLString;
@@ -70,7 +70,7 @@ var toGraphQLType = (schema) => {
70
70
  if (ast._tag === "TupleType") {
71
71
  const elements = ast.elements;
72
72
  if (elements.length > 0) {
73
- const elementSchema = S.make(elements[0].type);
73
+ const elementSchema = S2.make(elements[0].type);
74
74
  return new GraphQLList(toGraphQLType(elementSchema));
75
75
  }
76
76
  }
@@ -79,7 +79,7 @@ var toGraphQLType = (schema) => {
79
79
  for (const field2 of ast.propertySignatures) {
80
80
  const fieldName = String(field2.name);
81
81
  if (fieldName === "_tag") continue;
82
- const fieldSchema = S.make(field2.type);
82
+ const fieldSchema = S2.make(field2.type);
83
83
  let fieldType = toGraphQLType(fieldSchema);
84
84
  if (!field2.isOptional) {
85
85
  fieldType = new GraphQLNonNull(fieldType);
@@ -96,32 +96,32 @@ var toGraphQLType = (schema) => {
96
96
  if (isOptionTransformation(ast)) {
97
97
  const innerType = getOptionInnerType(ast.to);
98
98
  if (innerType) {
99
- return toGraphQLType(S.make(innerType));
99
+ return toGraphQLType(S2.make(innerType));
100
100
  }
101
101
  }
102
- return toGraphQLType(S.make(ast.to));
102
+ return toGraphQLType(S2.make(ast.to));
103
103
  }
104
104
  if (ast._tag === "Declaration") {
105
105
  if (isOptionDeclaration(ast)) {
106
106
  const innerType = getOptionInnerType(ast);
107
107
  if (innerType) {
108
- return toGraphQLType(S.make(innerType));
108
+ return toGraphQLType(S2.make(innerType));
109
109
  }
110
110
  }
111
111
  const typeParams = ast.typeParameters;
112
112
  if (typeParams && typeParams.length > 0) {
113
- return toGraphQLType(S.make(typeParams[0]));
113
+ return toGraphQLType(S2.make(typeParams[0]));
114
114
  }
115
115
  }
116
116
  if (ast._tag === "Union") {
117
117
  const types = ast.types;
118
118
  if (types.length > 0) {
119
- return toGraphQLType(S.make(types[0]));
119
+ return toGraphQLType(S2.make(types[0]));
120
120
  }
121
121
  }
122
122
  if (ast._tag === "Suspend") {
123
123
  const innerAst = ast.f();
124
- return toGraphQLType(S.make(innerAst));
124
+ return toGraphQLType(S2.make(innerAst));
125
125
  }
126
126
  return GraphQLString;
127
127
  };
@@ -134,7 +134,7 @@ var toGraphQLInputType = (schema) => {
134
134
  if (isIntegerType(ast)) {
135
135
  return GraphQLInt;
136
136
  }
137
- return toGraphQLInputType(S.make(ast.from));
137
+ return toGraphQLInputType(S2.make(ast.from));
138
138
  }
139
139
  if (ast._tag === "Literal") {
140
140
  if (typeof ast.literal === "string") return GraphQLString;
@@ -146,7 +146,7 @@ var toGraphQLInputType = (schema) => {
146
146
  if (ast._tag === "TupleType") {
147
147
  const elements = ast.elements;
148
148
  if (elements.length > 0) {
149
- const elementSchema = S.make(elements[0].type);
149
+ const elementSchema = S2.make(elements[0].type);
150
150
  return new GraphQLList(toGraphQLInputType(elementSchema));
151
151
  }
152
152
  }
@@ -155,7 +155,7 @@ var toGraphQLInputType = (schema) => {
155
155
  for (const field2 of ast.propertySignatures) {
156
156
  const fieldName = String(field2.name);
157
157
  if (fieldName === "_tag") continue;
158
- const fieldSchema = S.make(field2.type);
158
+ const fieldSchema = S2.make(field2.type);
159
159
  let fieldType = toGraphQLInputType(fieldSchema);
160
160
  if (!field2.isOptional) {
161
161
  fieldType = new GraphQLNonNull(fieldType);
@@ -169,33 +169,33 @@ var toGraphQLInputType = (schema) => {
169
169
  });
170
170
  }
171
171
  if (ast._tag === "Transformation") {
172
- return toGraphQLInputType(S.make(ast.from));
172
+ return toGraphQLInputType(S2.make(ast.from));
173
173
  }
174
174
  if (ast._tag === "Declaration") {
175
175
  if (isOptionDeclaration(ast)) {
176
176
  const innerType = getOptionInnerType(ast);
177
177
  if (innerType) {
178
- return toGraphQLInputType(S.make(innerType));
178
+ return toGraphQLInputType(S2.make(innerType));
179
179
  }
180
180
  }
181
181
  const typeParams = ast.typeParameters;
182
182
  if (typeParams && typeParams.length > 0) {
183
- return toGraphQLInputType(S.make(typeParams[0]));
183
+ return toGraphQLInputType(S2.make(typeParams[0]));
184
184
  }
185
185
  }
186
186
  if (ast._tag === "Union") {
187
187
  const types = ast.types;
188
188
  const nonNullTypes = types.filter((t) => t._tag !== "Literal" || t.literal !== null).filter((t) => t._tag !== "UndefinedKeyword");
189
189
  if (nonNullTypes.length > 0) {
190
- return toGraphQLInputType(S.make(nonNullTypes[0]));
190
+ return toGraphQLInputType(S2.make(nonNullTypes[0]));
191
191
  }
192
192
  if (types.length > 0) {
193
- return toGraphQLInputType(S.make(types[0]));
193
+ return toGraphQLInputType(S2.make(types[0]));
194
194
  }
195
195
  }
196
196
  if (ast._tag === "Suspend") {
197
197
  const innerAst = ast.f();
198
- return toGraphQLInputType(S.make(innerAst));
198
+ return toGraphQLInputType(S2.make(innerAst));
199
199
  }
200
200
  return GraphQLString;
201
201
  };
@@ -218,7 +218,7 @@ var toGraphQLObjectType = (name, schema, additionalFields) => {
218
218
  for (const field2 of ast.propertySignatures) {
219
219
  const fieldName = String(field2.name);
220
220
  if (fieldName === "_tag") continue;
221
- const fieldSchema = S.make(field2.type);
221
+ const fieldSchema = S2.make(field2.type);
222
222
  let fieldType = toGraphQLType(fieldSchema);
223
223
  if (!field2.isOptional) {
224
224
  fieldType = new GraphQLNonNull(fieldType);
@@ -250,7 +250,7 @@ var toGraphQLArgs = (schema) => {
250
250
  for (const field2 of ast.propertySignatures) {
251
251
  const fieldName = String(field2.name);
252
252
  if (fieldName === "_tag") continue;
253
- const fieldSchema = S.make(field2.type);
253
+ const fieldSchema = S2.make(field2.type);
254
254
  let fieldType = toGraphQLInputType(fieldSchema);
255
255
  if (!field2.isOptional) {
256
256
  fieldType = new GraphQLNonNull(fieldType);
@@ -286,6 +286,14 @@ function buildReverseLookups(ctx) {
286
286
  for (const [typeName, typeReg] of ctx.types) {
287
287
  ctx.schemaToTypeName.set(typeReg.schema, typeName);
288
288
  ctx.astToTypeName.set(typeReg.schema.ast, typeName);
289
+ let ast = typeReg.schema.ast;
290
+ while (ast._tag === "Transformation") {
291
+ ast = ast.to;
292
+ ctx.astToTypeName.set(ast, typeName);
293
+ }
294
+ if (ast._tag === "Declaration" && ast.typeParameters?.[0]) {
295
+ ctx.astToTypeName.set(ast.typeParameters[0], typeName);
296
+ }
289
297
  }
290
298
  }
291
299
  if (!ctx.schemaToInterfaceName) {
@@ -294,6 +302,14 @@ function buildReverseLookups(ctx) {
294
302
  for (const [interfaceName, interfaceReg] of ctx.interfaces) {
295
303
  ctx.schemaToInterfaceName.set(interfaceReg.schema, interfaceName);
296
304
  ctx.astToInterfaceName.set(interfaceReg.schema.ast, interfaceName);
305
+ let ast = interfaceReg.schema.ast;
306
+ while (ast._tag === "Transformation") {
307
+ ast = ast.to;
308
+ ctx.astToInterfaceName.set(ast, interfaceName);
309
+ }
310
+ if (ast._tag === "Declaration" && ast.typeParameters?.[0]) {
311
+ ctx.astToInterfaceName.set(ast.typeParameters[0], interfaceName);
312
+ }
297
313
  }
298
314
  }
299
315
  if (!ctx.schemaToInputName) {
@@ -302,6 +318,14 @@ function buildReverseLookups(ctx) {
302
318
  for (const [inputName, inputReg] of ctx.inputs) {
303
319
  ctx.schemaToInputName.set(inputReg.schema, inputName);
304
320
  ctx.astToInputName.set(inputReg.schema.ast, inputName);
321
+ let ast = inputReg.schema.ast;
322
+ while (ast._tag === "Transformation") {
323
+ ast = ast.to;
324
+ ctx.astToInputName.set(ast, inputName);
325
+ }
326
+ if (ast._tag === "Declaration" && ast.typeParameters?.[0]) {
327
+ ctx.astToInputName.set(ast.typeParameters[0], inputName);
328
+ }
305
329
  }
306
330
  }
307
331
  if (!ctx.enumSortedValues) {
@@ -354,17 +378,17 @@ function toGraphQLTypeWithRegistry(schema, ctx) {
354
378
  if (isOptionDeclaration2(ast)) {
355
379
  const innerType = getOptionInnerType2(ast);
356
380
  if (innerType) {
357
- return toGraphQLTypeWithRegistry(S.make(innerType), ctx);
381
+ return toGraphQLTypeWithRegistry(S2.make(innerType), ctx);
358
382
  }
359
383
  }
360
384
  const typeParams = ast.typeParameters;
361
385
  if (typeParams && typeParams.length > 0) {
362
- return toGraphQLTypeWithRegistry(S.make(typeParams[0]), ctx);
386
+ return toGraphQLTypeWithRegistry(S2.make(typeParams[0]), ctx);
363
387
  }
364
388
  }
365
389
  if (ast._tag === "Suspend") {
366
390
  const innerAst = ast.f();
367
- return toGraphQLTypeWithRegistry(S.make(innerAst), ctx);
391
+ return toGraphQLTypeWithRegistry(S2.make(innerAst), ctx);
368
392
  }
369
393
  return toGraphQLType(schema);
370
394
  }
@@ -429,21 +453,21 @@ function handleTransformationAST(ast, ctx) {
429
453
  }
430
454
  const innerType = getOptionInnerType2(toAst);
431
455
  if (innerType) {
432
- return toGraphQLTypeWithRegistry(S.make(innerType), ctx);
456
+ return toGraphQLTypeWithRegistry(S2.make(innerType), ctx);
433
457
  }
434
458
  }
435
459
  if (toAst._tag === "TupleType") {
436
460
  if (toAst.rest && toAst.rest.length > 0) {
437
- const elementSchema = S.make(toAst.rest[0].type);
461
+ const elementSchema = S2.make(toAst.rest[0].type);
438
462
  const elementType = toGraphQLTypeWithRegistry(elementSchema, ctx);
439
463
  return new GraphQLList(elementType);
440
464
  } else if (toAst.elements.length > 0) {
441
- const elementSchema = S.make(toAst.elements[0].type);
465
+ const elementSchema = S2.make(toAst.elements[0].type);
442
466
  const elementType = toGraphQLTypeWithRegistry(elementSchema, ctx);
443
467
  return new GraphQLList(elementType);
444
468
  }
445
469
  }
446
- return toGraphQLTypeWithRegistry(S.make(ast.to), ctx);
470
+ return toGraphQLTypeWithRegistry(S2.make(ast.to), ctx);
447
471
  }
448
472
  function handleUnionAST(ast, ctx) {
449
473
  const allLiterals = ast.types.every((t) => t._tag === "Literal");
@@ -468,11 +492,22 @@ function handleUnionAST(ast, ctx) {
468
492
  if (result) return result;
469
493
  }
470
494
  }
495
+ if (memberAst._tag === "TypeLiteral") {
496
+ const valueField = memberAst.propertySignatures?.find(
497
+ (p) => String(p.name) === "value"
498
+ );
499
+ if (valueField) {
500
+ const innerResult = toGraphQLTypeWithRegistry(S2.make(valueField.type), ctx);
501
+ if (innerResult) {
502
+ return innerResult;
503
+ }
504
+ }
505
+ }
471
506
  }
472
507
  if (ast.types.length > 0) {
473
- return toGraphQLTypeWithRegistry(S.make(ast.types[0]), ctx);
508
+ return toGraphQLTypeWithRegistry(S2.make(ast.types[0]), ctx);
474
509
  }
475
- return toGraphQLType(S.make(ast));
510
+ return toGraphQLType(S2.make(ast));
476
511
  }
477
512
  function findEnumForLiteralUnion(types, ctx) {
478
513
  const literalValues = types.map((t) => String(t.literal)).sort();
@@ -515,15 +550,15 @@ function findEnumForLiteral(ast, ctx) {
515
550
  }
516
551
  function handleTupleTypeAST(ast, ctx) {
517
552
  if (ast.rest && ast.rest.length > 0) {
518
- const elementSchema = S.make(ast.rest[0].type);
553
+ const elementSchema = S2.make(ast.rest[0].type);
519
554
  const elementType = toGraphQLTypeWithRegistry(elementSchema, ctx);
520
555
  return new GraphQLList(elementType);
521
556
  } else if (ast.elements && ast.elements.length > 0) {
522
- const elementSchema = S.make(ast.elements[0].type);
557
+ const elementSchema = S2.make(ast.elements[0].type);
523
558
  const elementType = toGraphQLTypeWithRegistry(elementSchema, ctx);
524
559
  return new GraphQLList(elementType);
525
560
  }
526
- return toGraphQLType(S.make(ast));
561
+ return toGraphQLType(S2.make(ast));
527
562
  }
528
563
  function schemaToFields(schema, ctx) {
529
564
  let ast = schema.ast;
@@ -547,7 +582,7 @@ function schemaToFields(schema, ctx) {
547
582
  for (const field2 of ast.propertySignatures) {
548
583
  const fieldName = String(field2.name);
549
584
  if (fieldName === "_tag") continue;
550
- const fieldSchema = S.make(field2.type);
585
+ const fieldSchema = S2.make(field2.type);
551
586
  let fieldType = toGraphQLTypeWithRegistry(fieldSchema, ctx);
552
587
  if (!field2.isOptional) {
553
588
  fieldType = getNonNull(fieldType);
@@ -568,7 +603,7 @@ function schemaToInputFields(schema, enumRegistry, inputRegistry, inputs, enums,
568
603
  for (const field2 of ast.propertySignatures) {
569
604
  const fieldName = String(field2.name);
570
605
  if (fieldName === "_tag") continue;
571
- const fieldSchema = S.make(field2.type);
606
+ const fieldSchema = S2.make(field2.type);
572
607
  let fieldType = toGraphQLInputTypeWithRegistry(
573
608
  fieldSchema,
574
609
  enumRegistry,
@@ -596,6 +631,14 @@ function buildInputTypeLookupCache(inputs, enums) {
596
631
  for (const [inputName, inputReg] of inputs) {
597
632
  cache.schemaToInputName.set(inputReg.schema, inputName);
598
633
  cache.astToInputName.set(inputReg.schema.ast, inputName);
634
+ let ast = inputReg.schema.ast;
635
+ while (ast._tag === "Transformation") {
636
+ ast = ast.to;
637
+ cache.astToInputName.set(ast, inputName);
638
+ }
639
+ if (ast._tag === "Declaration" && ast.typeParameters?.[0]) {
640
+ cache.astToInputName.set(ast.typeParameters[0], inputName);
641
+ }
599
642
  }
600
643
  for (const [enumName, enumReg] of enums) {
601
644
  cache.enumSortedValues.set(enumName, [...enumReg.values].sort());
@@ -641,10 +684,28 @@ function toGraphQLInputTypeWithRegistry(schema, enumRegistry, inputRegistry, inp
641
684
  if (result) return result;
642
685
  }
643
686
  }
687
+ if (memberAst._tag === "TypeLiteral") {
688
+ const valueField = memberAst.propertySignatures?.find(
689
+ (p) => String(p.name) === "value"
690
+ );
691
+ if (valueField) {
692
+ const innerResult = toGraphQLInputTypeWithRegistry(
693
+ S2.make(valueField.type),
694
+ enumRegistry,
695
+ inputRegistry,
696
+ inputs,
697
+ enums,
698
+ cache
699
+ );
700
+ if (innerResult) {
701
+ return innerResult;
702
+ }
703
+ }
704
+ }
644
705
  }
645
706
  }
646
707
  return toGraphQLInputTypeWithRegistry(
647
- S.make(toAst),
708
+ S2.make(toAst),
648
709
  enumRegistry,
649
710
  inputRegistry,
650
711
  inputs,
@@ -657,7 +718,7 @@ function toGraphQLInputTypeWithRegistry(schema, enumRegistry, inputRegistry, inp
657
718
  const nonUndefinedTypes = unionAst.types.filter((t) => t._tag !== "UndefinedKeyword");
658
719
  if (nonUndefinedTypes.length === 1 && nonUndefinedTypes[0]._tag === "Union") {
659
720
  return toGraphQLInputTypeWithRegistry(
660
- S.make(nonUndefinedTypes[0]),
721
+ S2.make(nonUndefinedTypes[0]),
661
722
  enumRegistry,
662
723
  inputRegistry,
663
724
  inputs,
@@ -667,7 +728,7 @@ function toGraphQLInputTypeWithRegistry(schema, enumRegistry, inputRegistry, inp
667
728
  }
668
729
  if (nonUndefinedTypes.length === 1 && nonUndefinedTypes[0]._tag === "TypeLiteral") {
669
730
  return toGraphQLInputTypeWithRegistry(
670
- S.make(nonUndefinedTypes[0]),
731
+ S2.make(nonUndefinedTypes[0]),
671
732
  enumRegistry,
672
733
  inputRegistry,
673
734
  inputs,
@@ -689,6 +750,24 @@ function toGraphQLInputTypeWithRegistry(schema, enumRegistry, inputRegistry, inp
689
750
  if (result) return result;
690
751
  }
691
752
  }
753
+ if (memberAst._tag === "TypeLiteral") {
754
+ const valueField = memberAst.propertySignatures?.find(
755
+ (p) => String(p.name) === "value"
756
+ );
757
+ if (valueField) {
758
+ const innerResult = toGraphQLInputTypeWithRegistry(
759
+ S2.make(valueField.type),
760
+ enumRegistry,
761
+ inputRegistry,
762
+ inputs,
763
+ enums,
764
+ cache
765
+ );
766
+ if (innerResult) {
767
+ return innerResult;
768
+ }
769
+ }
770
+ }
692
771
  }
693
772
  const allLiterals = unionAst.types.every((t) => t._tag === "Literal");
694
773
  if (allLiterals) {
@@ -722,7 +801,7 @@ function toGraphQLInputTypeWithRegistry(schema, enumRegistry, inputRegistry, inp
722
801
  if (ast._tag === "Suspend") {
723
802
  const innerAst = ast.f();
724
803
  return toGraphQLInputTypeWithRegistry(
725
- S.make(innerAst),
804
+ S2.make(innerAst),
726
805
  enumRegistry,
727
806
  inputRegistry,
728
807
  inputs,
@@ -739,7 +818,7 @@ function toGraphQLArgsWithRegistry(schema, enumRegistry, inputRegistry, inputs,
739
818
  for (const field2 of ast.propertySignatures) {
740
819
  const fieldName = String(field2.name);
741
820
  if (fieldName === "_tag") continue;
742
- const fieldSchema = S.make(field2.type);
821
+ const fieldSchema = S2.make(field2.type);
743
822
  let fieldType = toGraphQLInputTypeWithRegistry(
744
823
  fieldSchema,
745
824
  enumRegistry,
@@ -776,7 +855,7 @@ function isOptionSchema(schema) {
776
855
  }
777
856
  function encodeResolverOutput(schema, value) {
778
857
  if (isOptionSchema(schema)) {
779
- return Effect.orDie(S.encode(schema)(value));
858
+ return Effect.orDie(S2.encode(schema)(value));
780
859
  }
781
860
  return Effect.succeed(value);
782
861
  }