@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.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 } from 'graphql';
2
2
  export { DirectiveLocation } from 'graphql';
3
3
  import { Pipeable, Context, Runtime, Effect, Queue, Option, Stream, Fiber, Ref } 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
 
7
7
  // src/builder/index.ts
@@ -56,7 +56,7 @@ var toGraphQLType = (schema) => {
56
56
  if (isIntegerType(ast)) {
57
57
  return GraphQLInt;
58
58
  }
59
- return toGraphQLType(S.make(ast.from));
59
+ return toGraphQLType(S2.make(ast.from));
60
60
  }
61
61
  if (ast._tag === "Literal") {
62
62
  if (typeof ast.literal === "string") return GraphQLString;
@@ -68,7 +68,7 @@ var toGraphQLType = (schema) => {
68
68
  if (ast._tag === "TupleType") {
69
69
  const elements = ast.elements;
70
70
  if (elements.length > 0) {
71
- const elementSchema = S.make(elements[0].type);
71
+ const elementSchema = S2.make(elements[0].type);
72
72
  return new GraphQLList(toGraphQLType(elementSchema));
73
73
  }
74
74
  }
@@ -77,7 +77,7 @@ var toGraphQLType = (schema) => {
77
77
  for (const field2 of ast.propertySignatures) {
78
78
  const fieldName = String(field2.name);
79
79
  if (fieldName === "_tag") continue;
80
- const fieldSchema = S.make(field2.type);
80
+ const fieldSchema = S2.make(field2.type);
81
81
  let fieldType = toGraphQLType(fieldSchema);
82
82
  if (!field2.isOptional) {
83
83
  fieldType = new GraphQLNonNull(fieldType);
@@ -94,32 +94,32 @@ var toGraphQLType = (schema) => {
94
94
  if (isOptionTransformation(ast)) {
95
95
  const innerType = getOptionInnerType(ast.to);
96
96
  if (innerType) {
97
- return toGraphQLType(S.make(innerType));
97
+ return toGraphQLType(S2.make(innerType));
98
98
  }
99
99
  }
100
- return toGraphQLType(S.make(ast.to));
100
+ return toGraphQLType(S2.make(ast.to));
101
101
  }
102
102
  if (ast._tag === "Declaration") {
103
103
  if (isOptionDeclaration(ast)) {
104
104
  const innerType = getOptionInnerType(ast);
105
105
  if (innerType) {
106
- return toGraphQLType(S.make(innerType));
106
+ return toGraphQLType(S2.make(innerType));
107
107
  }
108
108
  }
109
109
  const typeParams = ast.typeParameters;
110
110
  if (typeParams && typeParams.length > 0) {
111
- return toGraphQLType(S.make(typeParams[0]));
111
+ return toGraphQLType(S2.make(typeParams[0]));
112
112
  }
113
113
  }
114
114
  if (ast._tag === "Union") {
115
115
  const types = ast.types;
116
116
  if (types.length > 0) {
117
- return toGraphQLType(S.make(types[0]));
117
+ return toGraphQLType(S2.make(types[0]));
118
118
  }
119
119
  }
120
120
  if (ast._tag === "Suspend") {
121
121
  const innerAst = ast.f();
122
- return toGraphQLType(S.make(innerAst));
122
+ return toGraphQLType(S2.make(innerAst));
123
123
  }
124
124
  return GraphQLString;
125
125
  };
@@ -132,7 +132,7 @@ var toGraphQLInputType = (schema) => {
132
132
  if (isIntegerType(ast)) {
133
133
  return GraphQLInt;
134
134
  }
135
- return toGraphQLInputType(S.make(ast.from));
135
+ return toGraphQLInputType(S2.make(ast.from));
136
136
  }
137
137
  if (ast._tag === "Literal") {
138
138
  if (typeof ast.literal === "string") return GraphQLString;
@@ -144,7 +144,7 @@ var toGraphQLInputType = (schema) => {
144
144
  if (ast._tag === "TupleType") {
145
145
  const elements = ast.elements;
146
146
  if (elements.length > 0) {
147
- const elementSchema = S.make(elements[0].type);
147
+ const elementSchema = S2.make(elements[0].type);
148
148
  return new GraphQLList(toGraphQLInputType(elementSchema));
149
149
  }
150
150
  }
@@ -153,7 +153,7 @@ var toGraphQLInputType = (schema) => {
153
153
  for (const field2 of ast.propertySignatures) {
154
154
  const fieldName = String(field2.name);
155
155
  if (fieldName === "_tag") continue;
156
- const fieldSchema = S.make(field2.type);
156
+ const fieldSchema = S2.make(field2.type);
157
157
  let fieldType = toGraphQLInputType(fieldSchema);
158
158
  if (!field2.isOptional) {
159
159
  fieldType = new GraphQLNonNull(fieldType);
@@ -167,33 +167,33 @@ var toGraphQLInputType = (schema) => {
167
167
  });
168
168
  }
169
169
  if (ast._tag === "Transformation") {
170
- return toGraphQLInputType(S.make(ast.from));
170
+ return toGraphQLInputType(S2.make(ast.from));
171
171
  }
172
172
  if (ast._tag === "Declaration") {
173
173
  if (isOptionDeclaration(ast)) {
174
174
  const innerType = getOptionInnerType(ast);
175
175
  if (innerType) {
176
- return toGraphQLInputType(S.make(innerType));
176
+ return toGraphQLInputType(S2.make(innerType));
177
177
  }
178
178
  }
179
179
  const typeParams = ast.typeParameters;
180
180
  if (typeParams && typeParams.length > 0) {
181
- return toGraphQLInputType(S.make(typeParams[0]));
181
+ return toGraphQLInputType(S2.make(typeParams[0]));
182
182
  }
183
183
  }
184
184
  if (ast._tag === "Union") {
185
185
  const types = ast.types;
186
186
  const nonNullTypes = types.filter((t) => t._tag !== "Literal" || t.literal !== null).filter((t) => t._tag !== "UndefinedKeyword");
187
187
  if (nonNullTypes.length > 0) {
188
- return toGraphQLInputType(S.make(nonNullTypes[0]));
188
+ return toGraphQLInputType(S2.make(nonNullTypes[0]));
189
189
  }
190
190
  if (types.length > 0) {
191
- return toGraphQLInputType(S.make(types[0]));
191
+ return toGraphQLInputType(S2.make(types[0]));
192
192
  }
193
193
  }
194
194
  if (ast._tag === "Suspend") {
195
195
  const innerAst = ast.f();
196
- return toGraphQLInputType(S.make(innerAst));
196
+ return toGraphQLInputType(S2.make(innerAst));
197
197
  }
198
198
  return GraphQLString;
199
199
  };
@@ -204,7 +204,7 @@ var toGraphQLArgs = (schema) => {
204
204
  for (const field2 of ast.propertySignatures) {
205
205
  const fieldName = String(field2.name);
206
206
  if (fieldName === "_tag") continue;
207
- const fieldSchema = S.make(field2.type);
207
+ const fieldSchema = S2.make(field2.type);
208
208
  let fieldType = toGraphQLInputType(fieldSchema);
209
209
  if (!field2.isOptional) {
210
210
  fieldType = new GraphQLNonNull(fieldType);
@@ -240,6 +240,14 @@ function buildReverseLookups(ctx) {
240
240
  for (const [typeName, typeReg] of ctx.types) {
241
241
  ctx.schemaToTypeName.set(typeReg.schema, typeName);
242
242
  ctx.astToTypeName.set(typeReg.schema.ast, typeName);
243
+ let ast = typeReg.schema.ast;
244
+ while (ast._tag === "Transformation") {
245
+ ast = ast.to;
246
+ ctx.astToTypeName.set(ast, typeName);
247
+ }
248
+ if (ast._tag === "Declaration" && ast.typeParameters?.[0]) {
249
+ ctx.astToTypeName.set(ast.typeParameters[0], typeName);
250
+ }
243
251
  }
244
252
  }
245
253
  if (!ctx.schemaToInterfaceName) {
@@ -248,6 +256,14 @@ function buildReverseLookups(ctx) {
248
256
  for (const [interfaceName, interfaceReg] of ctx.interfaces) {
249
257
  ctx.schemaToInterfaceName.set(interfaceReg.schema, interfaceName);
250
258
  ctx.astToInterfaceName.set(interfaceReg.schema.ast, interfaceName);
259
+ let ast = interfaceReg.schema.ast;
260
+ while (ast._tag === "Transformation") {
261
+ ast = ast.to;
262
+ ctx.astToInterfaceName.set(ast, interfaceName);
263
+ }
264
+ if (ast._tag === "Declaration" && ast.typeParameters?.[0]) {
265
+ ctx.astToInterfaceName.set(ast.typeParameters[0], interfaceName);
266
+ }
251
267
  }
252
268
  }
253
269
  if (!ctx.schemaToInputName) {
@@ -256,6 +272,14 @@ function buildReverseLookups(ctx) {
256
272
  for (const [inputName, inputReg] of ctx.inputs) {
257
273
  ctx.schemaToInputName.set(inputReg.schema, inputName);
258
274
  ctx.astToInputName.set(inputReg.schema.ast, inputName);
275
+ let ast = inputReg.schema.ast;
276
+ while (ast._tag === "Transformation") {
277
+ ast = ast.to;
278
+ ctx.astToInputName.set(ast, inputName);
279
+ }
280
+ if (ast._tag === "Declaration" && ast.typeParameters?.[0]) {
281
+ ctx.astToInputName.set(ast.typeParameters[0], inputName);
282
+ }
259
283
  }
260
284
  }
261
285
  if (!ctx.enumSortedValues) {
@@ -308,17 +332,17 @@ function toGraphQLTypeWithRegistry(schema, ctx) {
308
332
  if (isOptionDeclaration2(ast)) {
309
333
  const innerType = getOptionInnerType2(ast);
310
334
  if (innerType) {
311
- return toGraphQLTypeWithRegistry(S.make(innerType), ctx);
335
+ return toGraphQLTypeWithRegistry(S2.make(innerType), ctx);
312
336
  }
313
337
  }
314
338
  const typeParams = ast.typeParameters;
315
339
  if (typeParams && typeParams.length > 0) {
316
- return toGraphQLTypeWithRegistry(S.make(typeParams[0]), ctx);
340
+ return toGraphQLTypeWithRegistry(S2.make(typeParams[0]), ctx);
317
341
  }
318
342
  }
319
343
  if (ast._tag === "Suspend") {
320
344
  const innerAst = ast.f();
321
- return toGraphQLTypeWithRegistry(S.make(innerAst), ctx);
345
+ return toGraphQLTypeWithRegistry(S2.make(innerAst), ctx);
322
346
  }
323
347
  return toGraphQLType(schema);
324
348
  }
@@ -383,21 +407,21 @@ function handleTransformationAST(ast, ctx) {
383
407
  }
384
408
  const innerType = getOptionInnerType2(toAst);
385
409
  if (innerType) {
386
- return toGraphQLTypeWithRegistry(S.make(innerType), ctx);
410
+ return toGraphQLTypeWithRegistry(S2.make(innerType), ctx);
387
411
  }
388
412
  }
389
413
  if (toAst._tag === "TupleType") {
390
414
  if (toAst.rest && toAst.rest.length > 0) {
391
- const elementSchema = S.make(toAst.rest[0].type);
415
+ const elementSchema = S2.make(toAst.rest[0].type);
392
416
  const elementType = toGraphQLTypeWithRegistry(elementSchema, ctx);
393
417
  return new GraphQLList(elementType);
394
418
  } else if (toAst.elements.length > 0) {
395
- const elementSchema = S.make(toAst.elements[0].type);
419
+ const elementSchema = S2.make(toAst.elements[0].type);
396
420
  const elementType = toGraphQLTypeWithRegistry(elementSchema, ctx);
397
421
  return new GraphQLList(elementType);
398
422
  }
399
423
  }
400
- return toGraphQLTypeWithRegistry(S.make(ast.to), ctx);
424
+ return toGraphQLTypeWithRegistry(S2.make(ast.to), ctx);
401
425
  }
402
426
  function handleUnionAST(ast, ctx) {
403
427
  const allLiterals = ast.types.every((t) => t._tag === "Literal");
@@ -422,11 +446,22 @@ function handleUnionAST(ast, ctx) {
422
446
  if (result) return result;
423
447
  }
424
448
  }
449
+ if (memberAst._tag === "TypeLiteral") {
450
+ const valueField = memberAst.propertySignatures?.find(
451
+ (p) => String(p.name) === "value"
452
+ );
453
+ if (valueField) {
454
+ const innerResult = toGraphQLTypeWithRegistry(S2.make(valueField.type), ctx);
455
+ if (innerResult) {
456
+ return innerResult;
457
+ }
458
+ }
459
+ }
425
460
  }
426
461
  if (ast.types.length > 0) {
427
- return toGraphQLTypeWithRegistry(S.make(ast.types[0]), ctx);
462
+ return toGraphQLTypeWithRegistry(S2.make(ast.types[0]), ctx);
428
463
  }
429
- return toGraphQLType(S.make(ast));
464
+ return toGraphQLType(S2.make(ast));
430
465
  }
431
466
  function findEnumForLiteralUnion(types, ctx) {
432
467
  const literalValues = types.map((t) => String(t.literal)).sort();
@@ -469,15 +504,15 @@ function findEnumForLiteral(ast, ctx) {
469
504
  }
470
505
  function handleTupleTypeAST(ast, ctx) {
471
506
  if (ast.rest && ast.rest.length > 0) {
472
- const elementSchema = S.make(ast.rest[0].type);
507
+ const elementSchema = S2.make(ast.rest[0].type);
473
508
  const elementType = toGraphQLTypeWithRegistry(elementSchema, ctx);
474
509
  return new GraphQLList(elementType);
475
510
  } else if (ast.elements && ast.elements.length > 0) {
476
- const elementSchema = S.make(ast.elements[0].type);
511
+ const elementSchema = S2.make(ast.elements[0].type);
477
512
  const elementType = toGraphQLTypeWithRegistry(elementSchema, ctx);
478
513
  return new GraphQLList(elementType);
479
514
  }
480
- return toGraphQLType(S.make(ast));
515
+ return toGraphQLType(S2.make(ast));
481
516
  }
482
517
  function schemaToFields(schema, ctx) {
483
518
  let ast = schema.ast;
@@ -501,7 +536,7 @@ function schemaToFields(schema, ctx) {
501
536
  for (const field2 of ast.propertySignatures) {
502
537
  const fieldName = String(field2.name);
503
538
  if (fieldName === "_tag") continue;
504
- const fieldSchema = S.make(field2.type);
539
+ const fieldSchema = S2.make(field2.type);
505
540
  let fieldType = toGraphQLTypeWithRegistry(fieldSchema, ctx);
506
541
  if (!field2.isOptional) {
507
542
  fieldType = getNonNull(fieldType);
@@ -522,7 +557,7 @@ function schemaToInputFields(schema, enumRegistry, inputRegistry, inputs, enums,
522
557
  for (const field2 of ast.propertySignatures) {
523
558
  const fieldName = String(field2.name);
524
559
  if (fieldName === "_tag") continue;
525
- const fieldSchema = S.make(field2.type);
560
+ const fieldSchema = S2.make(field2.type);
526
561
  let fieldType = toGraphQLInputTypeWithRegistry(
527
562
  fieldSchema,
528
563
  enumRegistry,
@@ -550,6 +585,14 @@ function buildInputTypeLookupCache(inputs, enums) {
550
585
  for (const [inputName, inputReg] of inputs) {
551
586
  cache.schemaToInputName.set(inputReg.schema, inputName);
552
587
  cache.astToInputName.set(inputReg.schema.ast, inputName);
588
+ let ast = inputReg.schema.ast;
589
+ while (ast._tag === "Transformation") {
590
+ ast = ast.to;
591
+ cache.astToInputName.set(ast, inputName);
592
+ }
593
+ if (ast._tag === "Declaration" && ast.typeParameters?.[0]) {
594
+ cache.astToInputName.set(ast.typeParameters[0], inputName);
595
+ }
553
596
  }
554
597
  for (const [enumName, enumReg] of enums) {
555
598
  cache.enumSortedValues.set(enumName, [...enumReg.values].sort());
@@ -595,10 +638,28 @@ function toGraphQLInputTypeWithRegistry(schema, enumRegistry, inputRegistry, inp
595
638
  if (result) return result;
596
639
  }
597
640
  }
641
+ if (memberAst._tag === "TypeLiteral") {
642
+ const valueField = memberAst.propertySignatures?.find(
643
+ (p) => String(p.name) === "value"
644
+ );
645
+ if (valueField) {
646
+ const innerResult = toGraphQLInputTypeWithRegistry(
647
+ S2.make(valueField.type),
648
+ enumRegistry,
649
+ inputRegistry,
650
+ inputs,
651
+ enums,
652
+ cache
653
+ );
654
+ if (innerResult) {
655
+ return innerResult;
656
+ }
657
+ }
658
+ }
598
659
  }
599
660
  }
600
661
  return toGraphQLInputTypeWithRegistry(
601
- S.make(toAst),
662
+ S2.make(toAst),
602
663
  enumRegistry,
603
664
  inputRegistry,
604
665
  inputs,
@@ -611,7 +672,7 @@ function toGraphQLInputTypeWithRegistry(schema, enumRegistry, inputRegistry, inp
611
672
  const nonUndefinedTypes = unionAst.types.filter((t) => t._tag !== "UndefinedKeyword");
612
673
  if (nonUndefinedTypes.length === 1 && nonUndefinedTypes[0]._tag === "Union") {
613
674
  return toGraphQLInputTypeWithRegistry(
614
- S.make(nonUndefinedTypes[0]),
675
+ S2.make(nonUndefinedTypes[0]),
615
676
  enumRegistry,
616
677
  inputRegistry,
617
678
  inputs,
@@ -621,7 +682,7 @@ function toGraphQLInputTypeWithRegistry(schema, enumRegistry, inputRegistry, inp
621
682
  }
622
683
  if (nonUndefinedTypes.length === 1 && nonUndefinedTypes[0]._tag === "TypeLiteral") {
623
684
  return toGraphQLInputTypeWithRegistry(
624
- S.make(nonUndefinedTypes[0]),
685
+ S2.make(nonUndefinedTypes[0]),
625
686
  enumRegistry,
626
687
  inputRegistry,
627
688
  inputs,
@@ -643,6 +704,24 @@ function toGraphQLInputTypeWithRegistry(schema, enumRegistry, inputRegistry, inp
643
704
  if (result) return result;
644
705
  }
645
706
  }
707
+ if (memberAst._tag === "TypeLiteral") {
708
+ const valueField = memberAst.propertySignatures?.find(
709
+ (p) => String(p.name) === "value"
710
+ );
711
+ if (valueField) {
712
+ const innerResult = toGraphQLInputTypeWithRegistry(
713
+ S2.make(valueField.type),
714
+ enumRegistry,
715
+ inputRegistry,
716
+ inputs,
717
+ enums,
718
+ cache
719
+ );
720
+ if (innerResult) {
721
+ return innerResult;
722
+ }
723
+ }
724
+ }
646
725
  }
647
726
  const allLiterals = unionAst.types.every((t) => t._tag === "Literal");
648
727
  if (allLiterals) {
@@ -676,7 +755,7 @@ function toGraphQLInputTypeWithRegistry(schema, enumRegistry, inputRegistry, inp
676
755
  if (ast._tag === "Suspend") {
677
756
  const innerAst = ast.f();
678
757
  return toGraphQLInputTypeWithRegistry(
679
- S.make(innerAst),
758
+ S2.make(innerAst),
680
759
  enumRegistry,
681
760
  inputRegistry,
682
761
  inputs,
@@ -693,7 +772,7 @@ function toGraphQLArgsWithRegistry(schema, enumRegistry, inputRegistry, inputs,
693
772
  for (const field2 of ast.propertySignatures) {
694
773
  const fieldName = String(field2.name);
695
774
  if (fieldName === "_tag") continue;
696
- const fieldSchema = S.make(field2.type);
775
+ const fieldSchema = S2.make(field2.type);
697
776
  let fieldType = toGraphQLInputTypeWithRegistry(
698
777
  fieldSchema,
699
778
  enumRegistry,
@@ -730,7 +809,7 @@ function isOptionSchema(schema) {
730
809
  }
731
810
  function encodeResolverOutput(schema, value) {
732
811
  if (isOptionSchema(schema)) {
733
- return Effect.orDie(S.encode(schema)(value));
812
+ return Effect.orDie(S2.encode(schema)(value));
734
813
  }
735
814
  return Effect.succeed(value);
736
815
  }