@effect-gql/core 0.1.0 → 1.0.0

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.
Files changed (164) hide show
  1. package/README.md +100 -0
  2. package/builder/index.cjs +1431 -0
  3. package/builder/index.cjs.map +1 -0
  4. package/builder/index.d.cts +259 -0
  5. package/{dist/builder/pipe-api.d.ts → builder/index.d.ts} +49 -21
  6. package/builder/index.js +1390 -0
  7. package/builder/index.js.map +1 -0
  8. package/index.cjs +3419 -0
  9. package/index.cjs.map +1 -0
  10. package/index.d.cts +523 -0
  11. package/index.d.ts +523 -0
  12. package/index.js +3242 -0
  13. package/index.js.map +1 -0
  14. package/package.json +19 -28
  15. package/schema-builder-Cvdq7Kz_.d.cts +963 -0
  16. package/schema-builder-Cvdq7Kz_.d.ts +963 -0
  17. package/server/index.cjs +1555 -0
  18. package/server/index.cjs.map +1 -0
  19. package/server/index.d.cts +680 -0
  20. package/server/index.d.ts +680 -0
  21. package/server/index.js +1524 -0
  22. package/server/index.js.map +1 -0
  23. package/dist/analyzer-extension.d.ts +0 -105
  24. package/dist/analyzer-extension.d.ts.map +0 -1
  25. package/dist/analyzer-extension.js +0 -137
  26. package/dist/analyzer-extension.js.map +0 -1
  27. package/dist/builder/execute.d.ts +0 -26
  28. package/dist/builder/execute.d.ts.map +0 -1
  29. package/dist/builder/execute.js +0 -104
  30. package/dist/builder/execute.js.map +0 -1
  31. package/dist/builder/field-builders.d.ts +0 -30
  32. package/dist/builder/field-builders.d.ts.map +0 -1
  33. package/dist/builder/field-builders.js +0 -200
  34. package/dist/builder/field-builders.js.map +0 -1
  35. package/dist/builder/index.d.ts +0 -7
  36. package/dist/builder/index.d.ts.map +0 -1
  37. package/dist/builder/index.js +0 -31
  38. package/dist/builder/index.js.map +0 -1
  39. package/dist/builder/pipe-api.d.ts.map +0 -1
  40. package/dist/builder/pipe-api.js +0 -151
  41. package/dist/builder/pipe-api.js.map +0 -1
  42. package/dist/builder/schema-builder.d.ts +0 -301
  43. package/dist/builder/schema-builder.d.ts.map +0 -1
  44. package/dist/builder/schema-builder.js +0 -566
  45. package/dist/builder/schema-builder.js.map +0 -1
  46. package/dist/builder/type-registry.d.ts +0 -80
  47. package/dist/builder/type-registry.d.ts.map +0 -1
  48. package/dist/builder/type-registry.js +0 -505
  49. package/dist/builder/type-registry.js.map +0 -1
  50. package/dist/builder/types.d.ts +0 -283
  51. package/dist/builder/types.d.ts.map +0 -1
  52. package/dist/builder/types.js +0 -3
  53. package/dist/builder/types.js.map +0 -1
  54. package/dist/cli/generate-schema.d.ts +0 -29
  55. package/dist/cli/generate-schema.d.ts.map +0 -1
  56. package/dist/cli/generate-schema.js +0 -233
  57. package/dist/cli/generate-schema.js.map +0 -1
  58. package/dist/cli/index.d.ts +0 -19
  59. package/dist/cli/index.d.ts.map +0 -1
  60. package/dist/cli/index.js +0 -24
  61. package/dist/cli/index.js.map +0 -1
  62. package/dist/context.d.ts +0 -18
  63. package/dist/context.d.ts.map +0 -1
  64. package/dist/context.js +0 -11
  65. package/dist/context.js.map +0 -1
  66. package/dist/error.d.ts +0 -45
  67. package/dist/error.d.ts.map +0 -1
  68. package/dist/error.js +0 -29
  69. package/dist/error.js.map +0 -1
  70. package/dist/extensions.d.ts +0 -130
  71. package/dist/extensions.d.ts.map +0 -1
  72. package/dist/extensions.js +0 -78
  73. package/dist/extensions.js.map +0 -1
  74. package/dist/index.d.ts +0 -12
  75. package/dist/index.d.ts.map +0 -1
  76. package/dist/index.js +0 -47
  77. package/dist/index.js.map +0 -1
  78. package/dist/loader.d.ts +0 -169
  79. package/dist/loader.d.ts.map +0 -1
  80. package/dist/loader.js +0 -237
  81. package/dist/loader.js.map +0 -1
  82. package/dist/resolver-context.d.ts +0 -154
  83. package/dist/resolver-context.d.ts.map +0 -1
  84. package/dist/resolver-context.js +0 -184
  85. package/dist/resolver-context.js.map +0 -1
  86. package/dist/schema-mapping.d.ts +0 -30
  87. package/dist/schema-mapping.d.ts.map +0 -1
  88. package/dist/schema-mapping.js +0 -280
  89. package/dist/schema-mapping.js.map +0 -1
  90. package/dist/server/cache-control.d.ts +0 -96
  91. package/dist/server/cache-control.d.ts.map +0 -1
  92. package/dist/server/cache-control.js +0 -308
  93. package/dist/server/cache-control.js.map +0 -1
  94. package/dist/server/complexity.d.ts +0 -165
  95. package/dist/server/complexity.d.ts.map +0 -1
  96. package/dist/server/complexity.js +0 -433
  97. package/dist/server/complexity.js.map +0 -1
  98. package/dist/server/config.d.ts +0 -66
  99. package/dist/server/config.d.ts.map +0 -1
  100. package/dist/server/config.js +0 -104
  101. package/dist/server/config.js.map +0 -1
  102. package/dist/server/graphiql.d.ts +0 -5
  103. package/dist/server/graphiql.d.ts.map +0 -1
  104. package/dist/server/graphiql.js +0 -43
  105. package/dist/server/graphiql.js.map +0 -1
  106. package/dist/server/index.d.ts +0 -18
  107. package/dist/server/index.d.ts.map +0 -1
  108. package/dist/server/index.js +0 -48
  109. package/dist/server/index.js.map +0 -1
  110. package/dist/server/router.d.ts +0 -79
  111. package/dist/server/router.d.ts.map +0 -1
  112. package/dist/server/router.js +0 -232
  113. package/dist/server/router.js.map +0 -1
  114. package/dist/server/schema-builder-extensions.d.ts +0 -42
  115. package/dist/server/schema-builder-extensions.d.ts.map +0 -1
  116. package/dist/server/schema-builder-extensions.js +0 -48
  117. package/dist/server/schema-builder-extensions.js.map +0 -1
  118. package/dist/server/sse-adapter.d.ts +0 -64
  119. package/dist/server/sse-adapter.d.ts.map +0 -1
  120. package/dist/server/sse-adapter.js +0 -227
  121. package/dist/server/sse-adapter.js.map +0 -1
  122. package/dist/server/sse-types.d.ts +0 -192
  123. package/dist/server/sse-types.d.ts.map +0 -1
  124. package/dist/server/sse-types.js +0 -63
  125. package/dist/server/sse-types.js.map +0 -1
  126. package/dist/server/ws-adapter.d.ts +0 -39
  127. package/dist/server/ws-adapter.d.ts.map +0 -1
  128. package/dist/server/ws-adapter.js +0 -247
  129. package/dist/server/ws-adapter.js.map +0 -1
  130. package/dist/server/ws-types.d.ts +0 -169
  131. package/dist/server/ws-types.d.ts.map +0 -1
  132. package/dist/server/ws-types.js +0 -11
  133. package/dist/server/ws-types.js.map +0 -1
  134. package/dist/server/ws-utils.d.ts +0 -42
  135. package/dist/server/ws-utils.d.ts.map +0 -1
  136. package/dist/server/ws-utils.js +0 -99
  137. package/dist/server/ws-utils.js.map +0 -1
  138. package/src/analyzer-extension.ts +0 -254
  139. package/src/builder/execute.ts +0 -153
  140. package/src/builder/field-builders.ts +0 -322
  141. package/src/builder/index.ts +0 -48
  142. package/src/builder/pipe-api.ts +0 -312
  143. package/src/builder/schema-builder.ts +0 -970
  144. package/src/builder/type-registry.ts +0 -670
  145. package/src/builder/types.ts +0 -305
  146. package/src/context.ts +0 -23
  147. package/src/error.ts +0 -32
  148. package/src/extensions.ts +0 -240
  149. package/src/index.ts +0 -32
  150. package/src/loader.ts +0 -363
  151. package/src/resolver-context.ts +0 -253
  152. package/src/schema-mapping.ts +0 -307
  153. package/src/server/cache-control.ts +0 -590
  154. package/src/server/complexity.ts +0 -774
  155. package/src/server/config.ts +0 -174
  156. package/src/server/graphiql.ts +0 -38
  157. package/src/server/index.ts +0 -96
  158. package/src/server/router.ts +0 -432
  159. package/src/server/schema-builder-extensions.ts +0 -51
  160. package/src/server/sse-adapter.ts +0 -327
  161. package/src/server/sse-types.ts +0 -234
  162. package/src/server/ws-adapter.ts +0 -355
  163. package/src/server/ws-types.ts +0 -192
  164. package/src/server/ws-utils.ts +0 -136
package/dist/error.d.ts DELETED
@@ -1,45 +0,0 @@
1
- declare const GraphQLError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & {
2
- readonly _tag: "GraphQLError";
3
- } & Readonly<A>;
4
- /**
5
- * Base class for GraphQL errors in Effect
6
- */
7
- export declare class GraphQLError extends GraphQLError_base<{
8
- message: string;
9
- extensions?: Record<string, unknown>;
10
- }> {
11
- }
12
- declare const ValidationError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & {
13
- readonly _tag: "ValidationError";
14
- } & Readonly<A>;
15
- /**
16
- * Validation error for input validation failures
17
- */
18
- export declare class ValidationError extends ValidationError_base<{
19
- message: string;
20
- field?: string;
21
- }> {
22
- }
23
- declare const AuthorizationError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & {
24
- readonly _tag: "AuthorizationError";
25
- } & Readonly<A>;
26
- /**
27
- * Authorization error for access control failures
28
- */
29
- export declare class AuthorizationError extends AuthorizationError_base<{
30
- message: string;
31
- }> {
32
- }
33
- declare const NotFoundError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & {
34
- readonly _tag: "NotFoundError";
35
- } & Readonly<A>;
36
- /**
37
- * Not found error for missing resources
38
- */
39
- export declare class NotFoundError extends NotFoundError_base<{
40
- message: string;
41
- resource?: string;
42
- }> {
43
- }
44
- export {};
45
- //# sourceMappingURL=error.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":";;;AAEA;;GAEG;AACH,qBAAa,YAAa,SAAQ,kBAAiC;IACjE,OAAO,EAAE,MAAM,CAAA;IACf,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CACrC,CAAC;CAAG;;;;AAEL;;GAEG;AACH,qBAAa,eAAgB,SAAQ,qBAAoC;IACvE,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,CAAC,EAAE,MAAM,CAAA;CACf,CAAC;CAAG;;;;AAEL;;GAEG;AACH,qBAAa,kBAAmB,SAAQ,wBAAuC;IAC7E,OAAO,EAAE,MAAM,CAAA;CAChB,CAAC;CAAG;;;;AAEL;;GAEG;AACH,qBAAa,aAAc,SAAQ,mBAAkC;IACnE,OAAO,EAAE,MAAM,CAAA;IACf,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB,CAAC;CAAG"}
package/dist/error.js DELETED
@@ -1,29 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.NotFoundError = exports.AuthorizationError = exports.ValidationError = exports.GraphQLError = void 0;
4
- const effect_1 = require("effect");
5
- /**
6
- * Base class for GraphQL errors in Effect
7
- */
8
- class GraphQLError extends effect_1.Data.TaggedError("GraphQLError") {
9
- }
10
- exports.GraphQLError = GraphQLError;
11
- /**
12
- * Validation error for input validation failures
13
- */
14
- class ValidationError extends effect_1.Data.TaggedError("ValidationError") {
15
- }
16
- exports.ValidationError = ValidationError;
17
- /**
18
- * Authorization error for access control failures
19
- */
20
- class AuthorizationError extends effect_1.Data.TaggedError("AuthorizationError") {
21
- }
22
- exports.AuthorizationError = AuthorizationError;
23
- /**
24
- * Not found error for missing resources
25
- */
26
- class NotFoundError extends effect_1.Data.TaggedError("NotFoundError") {
27
- }
28
- exports.NotFoundError = NotFoundError;
29
- //# sourceMappingURL=error.js.map
package/dist/error.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"error.js","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":";;;AAAA,mCAA6B;AAE7B;;GAEG;AACH,MAAa,YAAa,SAAQ,aAAI,CAAC,WAAW,CAAC,cAAc,CAG/D;CAAG;AAHL,oCAGK;AAEL;;GAEG;AACH,MAAa,eAAgB,SAAQ,aAAI,CAAC,WAAW,CAAC,iBAAiB,CAGrE;CAAG;AAHL,0CAGK;AAEL;;GAEG;AACH,MAAa,kBAAmB,SAAQ,aAAI,CAAC,WAAW,CAAC,oBAAoB,CAE3E;CAAG;AAFL,gDAEK;AAEL;;GAEG;AACH,MAAa,aAAc,SAAQ,aAAI,CAAC,WAAW,CAAC,eAAe,CAGjE;CAAG;AAHL,sCAGK"}
@@ -1,130 +0,0 @@
1
- import { Context, Effect } from "effect";
2
- import type { DocumentNode, ExecutionResult, GraphQLError, GraphQLSchema } from "graphql";
3
- import type { FieldComplexityMap } from "./server/complexity";
4
- /**
5
- * Execution arguments passed to onExecuteStart hook
6
- */
7
- export interface ExecutionArgs {
8
- readonly source: string;
9
- readonly document: DocumentNode;
10
- readonly variableValues?: Record<string, unknown>;
11
- readonly operationName?: string;
12
- /** The GraphQL schema being executed against */
13
- readonly schema: GraphQLSchema;
14
- /** Field complexity definitions from the schema builder */
15
- readonly fieldComplexities: FieldComplexityMap;
16
- }
17
- /**
18
- * Configuration for a GraphQL extension
19
- *
20
- * Extensions provide lifecycle hooks that run at each phase of request processing,
21
- * and can contribute data to the response's `extensions` field.
22
- *
23
- * @example
24
- * ```typescript
25
- * // Tracing extension
26
- * extension({
27
- * name: "tracing",
28
- * onExecuteStart: () => Effect.gen(function*() {
29
- * const ext = yield* ExtensionsService
30
- * yield* ext.set("tracing", { startTime: Date.now() })
31
- * }),
32
- * onExecuteEnd: () => Effect.gen(function*() {
33
- * const ext = yield* ExtensionsService
34
- * yield* ext.merge("tracing", { endTime: Date.now() })
35
- * }),
36
- * })
37
- * ```
38
- */
39
- export interface GraphQLExtension<R = never> {
40
- readonly name: string;
41
- readonly description?: string;
42
- /**
43
- * Called after the query source is parsed into a DocumentNode.
44
- * Useful for query analysis, caching parsed documents, etc.
45
- */
46
- readonly onParse?: (source: string, document: DocumentNode) => Effect.Effect<void, never, R>;
47
- /**
48
- * Called after validation completes.
49
- * Receives the document and any validation errors.
50
- * Useful for complexity analysis, query whitelisting, etc.
51
- */
52
- readonly onValidate?: (document: DocumentNode, errors: readonly GraphQLError[]) => Effect.Effect<void, never, R>;
53
- /**
54
- * Called before execution begins.
55
- * Receives the full execution arguments.
56
- * Useful for setting up tracing, logging, etc.
57
- */
58
- readonly onExecuteStart?: (args: ExecutionArgs) => Effect.Effect<void, never, R>;
59
- /**
60
- * Called after execution completes.
61
- * Receives the execution result (including data and errors).
62
- * Useful for recording metrics, finalizing traces, etc.
63
- */
64
- readonly onExecuteEnd?: (result: ExecutionResult) => Effect.Effect<void, never, R>;
65
- }
66
- /**
67
- * Service for accumulating extension data during request processing.
68
- *
69
- * This service is automatically provided for each request and allows
70
- * extensions, middleware, and resolvers to contribute to the response
71
- * extensions field.
72
- *
73
- * @example
74
- * ```typescript
75
- * Effect.gen(function*() {
76
- * const ext = yield* ExtensionsService
77
- *
78
- * // Set a value (overwrites existing)
79
- * yield* ext.set("complexity", { score: 42 })
80
- *
81
- * // Merge into existing value
82
- * yield* ext.merge("tracing", { endTime: Date.now() })
83
- *
84
- * // Get all accumulated extensions
85
- * const all = yield* ext.get()
86
- * })
87
- * ```
88
- */
89
- export interface ExtensionsService {
90
- /**
91
- * Set a key-value pair in the extensions.
92
- * Overwrites any existing value for this key.
93
- */
94
- readonly set: (key: string, value: unknown) => Effect.Effect<void>;
95
- /**
96
- * Deep merge an object into an existing key's value.
97
- * If the key doesn't exist, sets the value.
98
- * If the existing value is not an object, overwrites it.
99
- */
100
- readonly merge: (key: string, value: Record<string, unknown>) => Effect.Effect<void>;
101
- /**
102
- * Get all accumulated extensions as a record.
103
- */
104
- readonly get: () => Effect.Effect<Record<string, unknown>>;
105
- }
106
- /**
107
- * Tag for the ExtensionsService
108
- */
109
- export declare const ExtensionsService: Context.Tag<ExtensionsService, ExtensionsService>;
110
- /**
111
- * Create a new ExtensionsService backed by a Ref
112
- */
113
- export declare const makeExtensionsService: () => Effect.Effect<ExtensionsService, never, never>;
114
- /**
115
- * Run all onParse hooks for registered extensions
116
- */
117
- export declare const runParseHooks: <R>(extensions: readonly GraphQLExtension<R>[], source: string, document: DocumentNode) => Effect.Effect<void, never, R>;
118
- /**
119
- * Run all onValidate hooks for registered extensions
120
- */
121
- export declare const runValidateHooks: <R>(extensions: readonly GraphQLExtension<R>[], document: DocumentNode, errors: readonly GraphQLError[]) => Effect.Effect<void, never, R>;
122
- /**
123
- * Run all onExecuteStart hooks for registered extensions
124
- */
125
- export declare const runExecuteStartHooks: <R>(extensions: readonly GraphQLExtension<R>[], args: ExecutionArgs) => Effect.Effect<void, never, R>;
126
- /**
127
- * Run all onExecuteEnd hooks for registered extensions
128
- */
129
- export declare const runExecuteEndHooks: <R>(extensions: readonly GraphQLExtension<R>[], result: ExecutionResult) => Effect.Effect<void, never, R>;
130
- //# sourceMappingURL=extensions.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"extensions.d.ts","sourceRoot":"","sources":["../src/extensions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAO,MAAM,QAAQ,CAAA;AAC7C,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AACzF,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAE7D;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,QAAQ,EAAE,YAAY,CAAA;IAC/B,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACjD,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAA;IAC/B,gDAAgD;IAChD,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAA;IAC9B,2DAA2D;IAC3D,QAAQ,CAAC,iBAAiB,EAAE,kBAAkB,CAAA;CAC/C;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,WAAW,gBAAgB,CAAC,CAAC,GAAG,KAAK;IACzC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CA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;GAEG;AACH,eAAO,MAAM,qBAAqB,QAAO,MAAM,CAAC,MAAM,CAAC,iBAAiB,EAAE,KAAK,EAAE,KAAK,CAqBlF,CAAA;AAuBJ;;GAEG;AACH,eAAO,MAAM,aAAa,GAAI,CAAC,EAC7B,YAAY,SAAS,gBAAgB,CAAC,CAAC,CAAC,EAAE,EAC1C,QAAQ,MAAM,EACd,UAAU,YAAY,KACrB,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,CACoD,CAAA;AAEnF;;GAEG;AACH,eAAO,MAAM,gBAAgB,GAAI,CAAC,EAChC,YAAY,SAAS,gBAAgB,CAAC,CAAC,CAAC,EAAE,EAC1C,UAAU,YAAY,EACtB,QAAQ,SAAS,YAAY,EAAE,KAC9B,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,CAC0D,CAAA;AAEzF;;GAEG;AACH,eAAO,MAAM,oBAAoB,GAAI,CAAC,EACpC,YAAY,SAAS,gBAAgB,CAAC,CAAC,CAAC,EAAE,EAC1C,MAAM,aAAa,KAClB,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,CACsD,CAAA;AAErF;;GAEG;AACH,eAAO,MAAM,kBAAkB,GAAI,CAAC,EAClC,YAAY,SAAS,gBAAgB,CAAC,CAAC,CAAC,EAAE,EAC1C,QAAQ,eAAe,KACtB,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,CACoD,CAAA"}
@@ -1,78 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.runExecuteEndHooks = exports.runExecuteStartHooks = exports.runValidateHooks = exports.runParseHooks = exports.makeExtensionsService = exports.ExtensionsService = void 0;
4
- const effect_1 = require("effect");
5
- /**
6
- * Tag for the ExtensionsService
7
- */
8
- exports.ExtensionsService = effect_1.Context.GenericTag("@effect-gql/ExtensionsService");
9
- /**
10
- * Deep merge two objects
11
- */
12
- function deepMerge(target, source) {
13
- const result = { ...target };
14
- for (const key of Object.keys(source)) {
15
- const sourceValue = source[key];
16
- const targetValue = result[key];
17
- if (typeof sourceValue === "object" &&
18
- sourceValue !== null &&
19
- !Array.isArray(sourceValue) &&
20
- typeof targetValue === "object" &&
21
- targetValue !== null &&
22
- !Array.isArray(targetValue)) {
23
- result[key] = deepMerge(targetValue, sourceValue);
24
- }
25
- else {
26
- result[key] = sourceValue;
27
- }
28
- }
29
- return result;
30
- }
31
- /**
32
- * Create a new ExtensionsService backed by a Ref
33
- */
34
- const makeExtensionsService = () => effect_1.Effect.gen(function* () {
35
- const ref = yield* effect_1.Ref.make({});
36
- return exports.ExtensionsService.of({
37
- set: (key, value) => effect_1.Ref.update(ref, (current) => ({ ...current, [key]: value })),
38
- merge: (key, value) => effect_1.Ref.update(ref, (current) => {
39
- const existing = current[key];
40
- if (typeof existing === "object" && existing !== null && !Array.isArray(existing)) {
41
- return {
42
- ...current,
43
- [key]: deepMerge(existing, value),
44
- };
45
- }
46
- return { ...current, [key]: value };
47
- }),
48
- get: () => effect_1.Ref.get(ref),
49
- });
50
- });
51
- exports.makeExtensionsService = makeExtensionsService;
52
- /**
53
- * Generic helper to run extension hooks with error handling.
54
- * Filters extensions that have the specified hook, runs them,
55
- * and logs warnings if any hook fails.
56
- */
57
- const runExtensionHooks = (extensions, hookName, getHookEffect) => effect_1.Effect.forEach(extensions.filter((ext) => ext[hookName] !== undefined), (ext) => getHookEffect(ext).pipe(effect_1.Effect.catchAllCause((cause) => effect_1.Effect.logWarning(`Extension "${ext.name}" ${String(hookName)} hook failed`, cause))), { discard: true });
58
- /**
59
- * Run all onParse hooks for registered extensions
60
- */
61
- const runParseHooks = (extensions, source, document) => runExtensionHooks(extensions, "onParse", (ext) => ext.onParse(source, document));
62
- exports.runParseHooks = runParseHooks;
63
- /**
64
- * Run all onValidate hooks for registered extensions
65
- */
66
- const runValidateHooks = (extensions, document, errors) => runExtensionHooks(extensions, "onValidate", (ext) => ext.onValidate(document, errors));
67
- exports.runValidateHooks = runValidateHooks;
68
- /**
69
- * Run all onExecuteStart hooks for registered extensions
70
- */
71
- const runExecuteStartHooks = (extensions, args) => runExtensionHooks(extensions, "onExecuteStart", (ext) => ext.onExecuteStart(args));
72
- exports.runExecuteStartHooks = runExecuteStartHooks;
73
- /**
74
- * Run all onExecuteEnd hooks for registered extensions
75
- */
76
- const runExecuteEndHooks = (extensions, result) => runExtensionHooks(extensions, "onExecuteEnd", (ext) => ext.onExecuteEnd(result));
77
- exports.runExecuteEndHooks = runExecuteEndHooks;
78
- //# sourceMappingURL=extensions.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"extensions.js","sourceRoot":"","sources":["../src/extensions.ts"],"names":[],"mappings":";;;AAAA,mCAA6C;AAsH7C;;GAEG;AACU,QAAA,iBAAiB,GAAG,gBAAO,CAAC,UAAU,CACjD,+BAA+B,CAChC,CAAA;AAED;;GAEG;AACH,SAAS,SAAS,CAChB,MAA+B,EAC/B,MAA+B;IAE/B,MAAM,MAAM,GAAG,EAAE,GAAG,MAAM,EAAE,CAAA;IAC5B,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;QACtC,MAAM,WAAW,GAAG,MAAM,CAAC,GAAG,CAAC,CAAA;QAC/B,MAAM,WAAW,GAAG,MAAM,CAAC,GAAG,CAAC,CAAA;QAE/B,IACE,OAAO,WAAW,KAAK,QAAQ;YAC/B,WAAW,KAAK,IAAI;YACpB,CAAC,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC;YAC3B,OAAO,WAAW,KAAK,QAAQ;YAC/B,WAAW,KAAK,IAAI;YACpB,CAAC,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC,EAC3B,CAAC;YACD,MAAM,CAAC,GAAG,CAAC,GAAG,SAAS,CACrB,WAAsC,EACtC,WAAsC,CACvC,CAAA;QACH,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,GAAG,CAAC,GA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ChC,UAA0C,EAC1C,MAAuB,EACQ,EAAE,CACjC,iBAAiB,CAAC,UAAU,EAAE,cAAc,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,YAAa,CAAC,MAAM,CAAC,CAAC,CAAA;AAJtE,QAAA,kBAAkB,sBAIoD"}
package/dist/index.d.ts DELETED
@@ -1,12 +0,0 @@
1
- export * from "./builder";
2
- export * from "./schema-mapping";
3
- export * from "./error";
4
- export * from "./context";
5
- export * from "./loader";
6
- export * from "./resolver-context";
7
- export * from "./server";
8
- export * from "./extensions";
9
- export * from "./analyzer-extension";
10
- export { GraphQLSchema, GraphQLObjectType, GraphQLScalarType, GraphQLInterfaceType, GraphQLUnionType, GraphQLEnumType, GraphQLInputObjectType, GraphQLList, GraphQLNonNull, GraphQLString, GraphQLInt, GraphQLFloat, GraphQLBoolean, GraphQLID, printSchema, lexicographicSortSchema, graphql, Kind, } from "graphql";
11
- export type { ValueNode, GraphQLFieldConfigMap } from "graphql";
12
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA;AACzB,cAAc,kBAAkB,CAAA;AAChC,cAAc,SAAS,CAAA;AACvB,cAAc,WAAW,CAAA;AACzB,cAAc,UAAU,CAAA;AACxB,cAAc,oBAAoB,CAAA;AAClC,cAAc,UAAU,CAAA;AACxB,cAAc,cAAc,CAAA;AAC5B,cAAc,sBAAsB,CAAA;AAGpC,OAAO,EACL,aAAa,EACb,iBAAiB,EACjB,iBAAiB,EACjB,oBAAoB,EACpB,gBAAgB,EAChB,eAAe,EACf,sBAAsB,EACtB,WAAW,EACX,cAAc,EACd,aAAa,EACb,UAAU,EACV,YAAY,EACZ,cAAc,EACd,SAAS,EACT,WAAW,EACX,uBAAuB,EACvB,OAAO,EACP,IAAI,GACL,MAAM,SAAS,CAAA;AAChB,YAAY,EAAE,SAAS,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAA"}
package/dist/index.js DELETED
@@ -1,47 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.Kind = exports.graphql = exports.lexicographicSortSchema = exports.printSchema = exports.GraphQLID = exports.GraphQLBoolean = exports.GraphQLFloat = exports.GraphQLInt = exports.GraphQLString = exports.GraphQLNonNull = exports.GraphQLList = exports.GraphQLInputObjectType = exports.GraphQLEnumType = exports.GraphQLUnionType = exports.GraphQLInterfaceType = exports.GraphQLScalarType = exports.GraphQLObjectType = exports.GraphQLSchema = void 0;
18
- __exportStar(require("./builder"), exports);
19
- __exportStar(require("./schema-mapping"), exports);
20
- __exportStar(require("./error"), exports);
21
- __exportStar(require("./context"), exports);
22
- __exportStar(require("./loader"), exports);
23
- __exportStar(require("./resolver-context"), exports);
24
- __exportStar(require("./server"), exports);
25
- __exportStar(require("./extensions"), exports);
26
- __exportStar(require("./analyzer-extension"), exports);
27
- // Re-export commonly used graphql types to ensure single instance
28
- var graphql_1 = require("graphql");
29
- Object.defineProperty(exports, "GraphQLSchema", { enumerable: true, get: function () { return graphql_1.GraphQLSchema; } });
30
- Object.defineProperty(exports, "GraphQLObjectType", { enumerable: true, get: function () { return graphql_1.GraphQLObjectType; } });
31
- Object.defineProperty(exports, "GraphQLScalarType", { enumerable: true, get: function () { return graphql_1.GraphQLScalarType; } });
32
- Object.defineProperty(exports, "GraphQLInterfaceType", { enumerable: true, get: function () { return graphql_1.GraphQLInterfaceType; } });
33
- Object.defineProperty(exports, "GraphQLUnionType", { enumerable: true, get: function () { return graphql_1.GraphQLUnionType; } });
34
- Object.defineProperty(exports, "GraphQLEnumType", { enumerable: true, get: function () { return graphql_1.GraphQLEnumType; } });
35
- Object.defineProperty(exports, "GraphQLInputObjectType", { enumerable: true, get: function () { return graphql_1.GraphQLInputObjectType; } });
36
- Object.defineProperty(exports, "GraphQLList", { enumerable: true, get: function () { return graphql_1.GraphQLList; } });
37
- Object.defineProperty(exports, "GraphQLNonNull", { enumerable: true, get: function () { return graphql_1.GraphQLNonNull; } });
38
- Object.defineProperty(exports, "GraphQLString", { enumerable: true, get: function () { return graphql_1.GraphQLString; } });
39
- Object.defineProperty(exports, "GraphQLInt", { enumerable: true, get: function () { return graphql_1.GraphQLInt; } });
40
- Object.defineProperty(exports, "GraphQLFloat", { enumerable: true, get: function () { return graphql_1.GraphQLFloat; } });
41
- Object.defineProperty(exports, "GraphQLBoolean", { enumerable: true, get: function () { return graphql_1.GraphQLBoolean; } });
42
- Object.defineProperty(exports, "GraphQLID", { enumerable: true, get: function () { return graphql_1.GraphQLID; } });
43
- Object.defineProperty(exports, "printSchema", { enumerable: true, get: function () { return graphql_1.printSchema; } });
44
- Object.defineProperty(exports, "lexicographicSortSchema", { enumerable: true, get: function () { return graphql_1.lexicographicSortSchema; } });
45
- Object.defineProperty(exports, "graphql", { enumerable: true, get: function () { return graphql_1.graphql; } });
46
- Object.defineProperty(exports, "Kind", { enumerable: true, get: function () { return graphql_1.Kind; } });
47
- //# sourceMappingURL=index.js.map
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,4CAAyB;AACzB,mDAAgC;AAChC,0CAAuB;AACvB,4CAAyB;AACzB,2CAAwB;AACxB,qDAAkC;AAClC,2CAAwB;AACxB,+CAA4B;AAC5B,uDAAoC;AAEpC,kEAAkE;AAClE,mCAmBgB;AAlBd,wGAAA,aAAa,OAAA;AACb,4GAAA,iBAAiB,OAAA;AACjB,4GAAA,iBAAiB,OAAA;AACjB,+GAAA,oBAAoB,OAAA;AACpB,2GAAA,gBAAgB,OAAA;AAChB,0GAAA,eAAe,OAAA;AACf,iHAAA,sBAAsB,OAAA;AACtB,sGAAA,WAAW,OAAA;AACX,yGAAA,cAAc,OAAA;AACd,wGAAA,aAAa,OAAA;AACb,qGAAA,UAAU,OAAA;AACV,uGAAA,YAAY,OAAA;AACZ,yGAAA,cAAc,OAAA;AACd,oGAAA,SAAS,OAAA;AACT,sGAAA,WAAW,OAAA;AACX,kHAAA,uBAAuB,OAAA;AACvB,kGAAA,OAAO,OAAA;AACP,+FAAA,IAAI,OAAA"}
package/dist/loader.d.ts DELETED
@@ -1,169 +0,0 @@
1
- import { Effect, Context, Layer } from "effect";
2
- import DataLoader from "dataloader";
3
- /**
4
- * Ergonomic DataLoader helpers for Effect-based GraphQL
5
- *
6
- * This module provides a type-safe, declarative way to define DataLoaders
7
- * that integrate seamlessly with Effect's service system.
8
- *
9
- * @example
10
- * ```typescript
11
- * // Define loaders
12
- * const loaders = Loader.define({
13
- * UserById: Loader.single<string, User>({
14
- * batch: (ids) => db.getUsersByIds(ids),
15
- * key: (user) => user.id,
16
- * }),
17
- *
18
- * PostsByAuthorId: Loader.grouped<string, Post>({
19
- * batch: (ids) => db.getPostsForAuthors(ids),
20
- * groupBy: (post) => post.authorId,
21
- * }),
22
- * })
23
- *
24
- * // Use in resolvers
25
- * resolve: (parent) => loaders.load("UserById", parent.authorId)
26
- * ```
27
- */
28
- /**
29
- * Configuration for a single-value loader (one key -> one value)
30
- */
31
- interface SingleLoaderDef<K, V, R> {
32
- readonly _tag: "single";
33
- readonly batch: (keys: readonly K[]) => Effect.Effect<readonly V[], Error, R>;
34
- readonly key: (value: V) => K;
35
- }
36
- /**
37
- * Configuration for a grouped loader (one key -> many values)
38
- */
39
- interface GroupedLoaderDef<K, V, R> {
40
- readonly _tag: "grouped";
41
- readonly batch: (keys: readonly K[]) => Effect.Effect<readonly V[], Error, R>;
42
- readonly groupBy: (value: V) => K;
43
- }
44
- type LoaderDef<K, V, R> = SingleLoaderDef<K, V, R> | GroupedLoaderDef<K, V, R>;
45
- /**
46
- * Runtime DataLoader instances
47
- */
48
- type LoaderInstances<Defs extends Record<string, LoaderDef<any, any, any>>> = {
49
- [Name in keyof Defs]: Defs[Name] extends SingleLoaderDef<infer K, infer V, any> ? DataLoader<K, V> : Defs[Name] extends GroupedLoaderDef<infer K, infer V, any> ? DataLoader<K, V[]> : never;
50
- };
51
- /**
52
- * Extract the value type for a loader (accounting for grouped loaders)
53
- */
54
- type LoaderValue<Def> = Def extends SingleLoaderDef<any, infer V, any> ? V : Def extends GroupedLoaderDef<any, infer V, any> ? V[] : never;
55
- /**
56
- * Extract the key type for a loader
57
- */
58
- type LoaderKey<Def> = Def extends LoaderDef<infer K, any, any> ? K : never;
59
- /**
60
- * Extract combined requirements from all loaders
61
- */
62
- type LoaderRequirements<Defs extends Record<string, LoaderDef<any, any, any>>> = {
63
- [K in keyof Defs]: Defs[K] extends LoaderDef<any, any, infer R> ? R : never;
64
- }[keyof Defs];
65
- /**
66
- * Create a single-value loader definition.
67
- * One key maps to one value.
68
- *
69
- * @example
70
- * ```typescript
71
- * Loader.single<string, User>({
72
- * batch: (ids) => db.getUsersByIds(ids),
73
- * key: (user) => user.id,
74
- * })
75
- * ```
76
- */
77
- declare function single<K, V, R = never>(config: {
78
- batch: (keys: readonly K[]) => Effect.Effect<readonly V[], Error, R>;
79
- key: (value: V) => K;
80
- }): SingleLoaderDef<K, V, R>;
81
- /**
82
- * Create a grouped loader definition.
83
- * One key maps to many values.
84
- *
85
- * @example
86
- * ```typescript
87
- * Loader.grouped<string, Post>({
88
- * batch: (authorIds) => db.getPostsForAuthors(authorIds),
89
- * groupBy: (post) => post.authorId,
90
- * })
91
- * ```
92
- */
93
- declare function grouped<K, V, R = never>(config: {
94
- batch: (keys: readonly K[]) => Effect.Effect<readonly V[], Error, R>;
95
- groupBy: (value: V) => K;
96
- }): GroupedLoaderDef<K, V, R>;
97
- /**
98
- * A registry of loader definitions with methods to create instances and layers
99
- */
100
- declare class LoaderRegistry<Defs extends Record<string, LoaderDef<any, any, any>>> {
101
- readonly definitions: Defs;
102
- readonly _tag = "LoaderRegistry";
103
- /**
104
- * The Effect service tag for this loader registry
105
- */
106
- readonly Service: Context.Tag<LoaderInstances<Defs>, LoaderInstances<Defs>>;
107
- constructor(definitions: Defs);
108
- /**
109
- * Create a Layer that provides fresh DataLoader instances.
110
- * Call this once per request to get request-scoped loaders.
111
- */
112
- toLayer(): Layer.Layer<LoaderInstances<Defs>, never, LoaderRequirements<Defs>>;
113
- /**
114
- * Helper to use loaders in a resolver with a callback.
115
- */
116
- use<A>(fn: (loaders: LoaderInstances<Defs>) => Promise<A>): Effect.Effect<A, Error, LoaderInstances<Defs>>;
117
- /**
118
- * Load a single value by key.
119
- * This is the most common operation in resolvers.
120
- */
121
- load<Name extends keyof Defs & string>(name: Name, key: LoaderKey<Defs[Name]>): Effect.Effect<LoaderValue<Defs[Name]>, Error, LoaderInstances<Defs>>;
122
- /**
123
- * Load multiple values by keys.
124
- * All keys are batched into a single request.
125
- */
126
- loadMany<Name extends keyof Defs & string>(name: Name, keys: readonly LoaderKey<Defs[Name]>[]): Effect.Effect<readonly LoaderValue<Defs[Name]>[], Error, LoaderInstances<Defs>>;
127
- }
128
- /**
129
- * Define a set of loaders.
130
- *
131
- * @example
132
- * ```typescript
133
- * const loaders = Loader.define({
134
- * UserById: Loader.single<string, User>({
135
- * batch: (ids) => db.getUsersByIds(ids),
136
- * key: (user) => user.id,
137
- * }),
138
- * PostsByAuthorId: Loader.grouped<string, Post>({
139
- * batch: (ids) => db.getPostsForAuthors(ids),
140
- * groupBy: (post) => post.authorId,
141
- * }),
142
- * })
143
- *
144
- * // In resolvers:
145
- * loaders.load("UserById", "123")
146
- * loaders.loadMany("UserById", ["1", "2", "3"])
147
- * ```
148
- */
149
- declare function define<Defs extends Record<string, LoaderDef<any, any, any>>>(definitions: Defs): LoaderRegistry<Defs>;
150
- /**
151
- * Map an array of items to match requested keys.
152
- * Returns items in the same order as keys, with errors for missing items.
153
- */
154
- declare function mapByKey<K, V>(keys: readonly K[], items: readonly V[], keyFn: (item: V) => K): (V | Error)[];
155
- /**
156
- * Group an array of items by a key function.
157
- * Returns a Map from key to array of matching items.
158
- * Guarantees an entry (possibly empty) for each requested key.
159
- */
160
- declare function groupByKey<K, V>(keys: readonly K[], items: readonly V[], keyFn: (item: V) => K): Map<K, V[]>;
161
- export declare const Loader: {
162
- readonly define: typeof define;
163
- readonly single: typeof single;
164
- readonly grouped: typeof grouped;
165
- readonly mapByKey: typeof mapByKey;
166
- readonly groupByKey: typeof groupByKey;
167
- };
168
- export type { LoaderRegistry, LoaderDef, LoaderInstances };
169
- //# sourceMappingURL=loader.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAA;AAC/C,OAAO,UAAU,MAAM,YAAY,CAAA;AAEnC;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAMH;;GAEG;AACH,UAAU,eAAe,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC;IAC/B,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAA;IACvB,QAAQ,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,SAAS,CAAC,EAAE,KAAK,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC,CAAA;IAC7E,QAAQ,CAAC,GAAG,EAAE,CAAC,KAAK,EAAE,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