@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
@@ -1,227 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.makeGraphQLSSEHandler = exports.makeSSESubscriptionStream = void 0;
4
- const effect_1 = require("effect");
5
- const graphql_1 = require("graphql");
6
- const sse_types_1 = require("./sse-types");
7
- const complexity_1 = require("./complexity");
8
- /**
9
- * Create a subscription event stream for SSE.
10
- *
11
- * This function handles the GraphQL subscription lifecycle:
12
- * 1. Parse and validate the query
13
- * 2. Check complexity limits if configured
14
- * 3. Execute the subscription
15
- * 4. Stream results as SSE events
16
- *
17
- * @param schema - The GraphQL schema with subscription definitions
18
- * @param layer - Effect layer providing services required by resolvers
19
- * @param request - The subscription request (query, variables, operationName)
20
- * @param headers - HTTP headers from the request (for auth)
21
- * @param options - Optional lifecycle hooks and configuration
22
- * @returns A Stream of SSE events to send to the client
23
- *
24
- * @example
25
- * ```typescript
26
- * const eventStream = makeSSESubscriptionStream(
27
- * schema,
28
- * serviceLayer,
29
- * { query: "subscription { tick { count } }" },
30
- * new Headers(),
31
- * { onConnect: (req, headers) => Effect.succeed({ user: "alice" }) }
32
- * )
33
- *
34
- * // In platform-specific code, consume and send events:
35
- * Stream.runForEach(eventStream, (event) =>
36
- * Effect.sync(() => res.write(formatSSEMessage(event)))
37
- * )
38
- * ```
39
- */
40
- const makeSSESubscriptionStream = (schema, layer, request, headers, options) => {
41
- const complexityConfig = options?.complexity;
42
- const fieldComplexities = options?.fieldComplexities ?? new Map();
43
- return effect_1.Stream.unwrap(effect_1.Effect.gen(function* () {
44
- // Create a runtime from the layer
45
- const runtime = yield* effect_1.Effect.provide(effect_1.Effect.runtime(), layer);
46
- // Run onConnect hook if provided
47
- let connectionContext = {};
48
- if (options?.onConnect) {
49
- try {
50
- connectionContext = yield* effect_1.Effect.provide(options.onConnect(request, headers), layer);
51
- }
52
- catch {
53
- // Connection rejected
54
- return effect_1.Stream.make((0, sse_types_1.formatErrorEvent)([
55
- new graphql_1.GraphQLError("Subscription connection rejected", {
56
- extensions: { code: "CONNECTION_REJECTED" },
57
- }),
58
- ]), (0, sse_types_1.formatCompleteEvent)());
59
- }
60
- }
61
- // Parse the query
62
- let document;
63
- try {
64
- document = (0, graphql_1.parse)(request.query);
65
- }
66
- catch (syntaxError) {
67
- return effect_1.Stream.make((0, sse_types_1.formatErrorEvent)([syntaxError]), (0, sse_types_1.formatCompleteEvent)());
68
- }
69
- // Validate the query
70
- const validationErrors = (0, graphql_1.validate)(schema, document);
71
- if (validationErrors.length > 0) {
72
- return effect_1.Stream.make((0, sse_types_1.formatErrorEvent)(validationErrors), (0, sse_types_1.formatCompleteEvent)());
73
- }
74
- // Find the subscription operation
75
- const operations = document.definitions.filter((d) => d.kind === graphql_1.Kind.OPERATION_DEFINITION);
76
- const operation = request.operationName
77
- ? operations.find((o) => o.name?.value === request.operationName)
78
- : operations[0];
79
- if (!operation) {
80
- return effect_1.Stream.make((0, sse_types_1.formatErrorEvent)([new graphql_1.GraphQLError("No operation found in query")]), (0, sse_types_1.formatCompleteEvent)());
81
- }
82
- if (operation.operation !== "subscription") {
83
- return effect_1.Stream.make((0, sse_types_1.formatErrorEvent)([
84
- new graphql_1.GraphQLError(`SSE endpoint only supports subscriptions, received: ${operation.operation}`, { extensions: { code: "OPERATION_NOT_SUPPORTED" } }),
85
- ]), (0, sse_types_1.formatCompleteEvent)());
86
- }
87
- // Validate complexity if configured
88
- if (complexityConfig) {
89
- const complexityResult = yield* (0, complexity_1.validateComplexity)(request.query, request.operationName, request.variables, schema, fieldComplexities, complexityConfig).pipe(effect_1.Effect.map(() => null), effect_1.Effect.catchAll((error) => {
90
- if (error._tag === "ComplexityLimitExceededError") {
91
- return effect_1.Effect.succeed(new graphql_1.GraphQLError(error.message, {
92
- extensions: {
93
- code: "COMPLEXITY_LIMIT_EXCEEDED",
94
- limitType: error.limitType,
95
- limit: error.limit,
96
- actual: error.actual,
97
- },
98
- }));
99
- }
100
- // Log analysis errors but don't block (fail open)
101
- return effect_1.Effect.logWarning("Complexity analysis failed for SSE subscription", error).pipe(effect_1.Effect.map(() => null));
102
- }));
103
- if (complexityResult) {
104
- return effect_1.Stream.make((0, sse_types_1.formatErrorEvent)([complexityResult]), (0, sse_types_1.formatCompleteEvent)());
105
- }
106
- }
107
- // Build the context for the subscription
108
- const ctx = {
109
- runtime,
110
- request,
111
- connectionContext,
112
- };
113
- // Call onSubscribe hook if provided
114
- if (options?.onSubscribe) {
115
- yield* effect_1.Effect.provide(options.onSubscribe(ctx), layer).pipe(effect_1.Effect.catchAll(() => effect_1.Effect.void));
116
- }
117
- // Execute the subscription
118
- const graphqlContext = {
119
- runtime,
120
- ...connectionContext,
121
- };
122
- const subscriptionResult = yield* effect_1.Effect.tryPromise({
123
- try: () => (0, graphql_1.subscribe)({
124
- schema,
125
- document,
126
- variableValues: request.variables,
127
- operationName: request.operationName ?? undefined,
128
- contextValue: graphqlContext,
129
- }),
130
- catch: (error) => new sse_types_1.SSEError({ cause: error }),
131
- });
132
- // Check if subscribe returned an error result instead of async iterator
133
- if (!isAsyncIterable(subscriptionResult)) {
134
- // It's an ExecutionResult with errors
135
- const result = subscriptionResult;
136
- if (result.errors) {
137
- return effect_1.Stream.make((0, sse_types_1.formatErrorEvent)(result.errors), (0, sse_types_1.formatCompleteEvent)());
138
- }
139
- // Shouldn't happen, but handle gracefully
140
- return effect_1.Stream.make((0, sse_types_1.formatNextEvent)(result), (0, sse_types_1.formatCompleteEvent)());
141
- }
142
- // Create a stream from the async iterator
143
- const asyncIterator = subscriptionResult[Symbol.asyncIterator]();
144
- const eventStream = effect_1.Stream.async((emit) => {
145
- let done = false;
146
- const iterate = async () => {
147
- try {
148
- while (!done) {
149
- const result = await asyncIterator.next();
150
- if (result.done) {
151
- emit.end();
152
- break;
153
- }
154
- emit.single((0, sse_types_1.formatNextEvent)(result.value));
155
- }
156
- }
157
- catch (error) {
158
- if (!done) {
159
- emit.single((0, sse_types_1.formatErrorEvent)([
160
- error instanceof graphql_1.GraphQLError
161
- ? error
162
- : new graphql_1.GraphQLError(error instanceof Error ? error.message : "Subscription error", { extensions: { code: "SUBSCRIPTION_ERROR" } }),
163
- ]));
164
- emit.end();
165
- }
166
- }
167
- };
168
- iterate();
169
- // Return cleanup function
170
- return effect_1.Effect.sync(() => {
171
- done = true;
172
- asyncIterator.return?.();
173
- });
174
- });
175
- // Add complete event at the end and handle cleanup
176
- return eventStream.pipe(effect_1.Stream.onDone(() => effect_1.Effect.gen(function* () {
177
- yield* effect_1.Effect.sync(() => { });
178
- }).pipe(effect_1.Effect.asVoid)), effect_1.Stream.concat(effect_1.Stream.make((0, sse_types_1.formatCompleteEvent)())), effect_1.Stream.onDone(() => {
179
- if (options?.onComplete) {
180
- return effect_1.Effect.provide(options.onComplete(ctx), layer).pipe(effect_1.Effect.catchAll(() => effect_1.Effect.void));
181
- }
182
- return effect_1.Effect.void;
183
- }));
184
- }).pipe(effect_1.Effect.catchAll((error) => effect_1.Effect.succeed(effect_1.Stream.make((0, sse_types_1.formatErrorEvent)([
185
- new graphql_1.GraphQLError(error instanceof Error ? error.message : "Internal error", {
186
- extensions: { code: "INTERNAL_ERROR" },
187
- }),
188
- ]), (0, sse_types_1.formatCompleteEvent)())))));
189
- };
190
- exports.makeSSESubscriptionStream = makeSSESubscriptionStream;
191
- /**
192
- * Create an SSE subscription handler that can be used with platform-specific servers.
193
- *
194
- * This is a higher-level API that returns a handler function. The handler
195
- * takes a request and headers, and returns a Stream of SSE events.
196
- *
197
- * @param schema - The GraphQL schema with subscription definitions
198
- * @param layer - Effect layer providing services required by resolvers
199
- * @param options - Optional lifecycle hooks and configuration
200
- * @returns A handler function for SSE subscription requests
201
- *
202
- * @example
203
- * ```typescript
204
- * const handler = makeGraphQLSSEHandler(schema, serviceLayer, {
205
- * onConnect: (request, headers) => Effect.gen(function* () {
206
- * const token = headers.get("authorization")
207
- * const user = yield* AuthService.validateToken(token)
208
- * return { user }
209
- * }),
210
- * })
211
- *
212
- * // In platform-specific code:
213
- * const events = handler(request, headers)
214
- * // Stream events to client...
215
- * ```
216
- */
217
- const makeGraphQLSSEHandler = (schema, layer, options) => {
218
- return (request, headers) => (0, exports.makeSSESubscriptionStream)(schema, layer, request, headers, options);
219
- };
220
- exports.makeGraphQLSSEHandler = makeGraphQLSSEHandler;
221
- /**
222
- * Type guard to check if a value is an AsyncIterable (subscription result)
223
- */
224
- function isAsyncIterable(value) {
225
- return typeof value === "object" && value !== null && Symbol.asyncIterator in value;
226
- }
227
- //# sourceMappingURL=sse-adap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qBAAqB,GAAG,CACnC,MAAqB,EACrB,KAAqB,EACrB,OAA8B,EAC8D,EAAE;IAC9F,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE,CAAC,IAAA,iCAAyB,EAAC,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,CAAA;AAClG,CAAC,CAAA;AANY,QAAA,qBAAqB,yBAMjC;AAED;;GAEG;AACH,SAAS,eAAe,CAAI,KAAc;IACxC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,MAAM,CAAC,aAAa,IAAI,KAAK,CAAA;AACrF,CAAC"}
@@ -1,192 +0,0 @@
1
- import { Effect, Runtime, Stream } from "effect";
2
- import type { ExecutionResult } from "graphql";
3
- import type { ComplexityConfig, FieldComplexityMap } from "./complexity";
4
- /**
5
- * Standard SSE response headers following the graphql-sse protocol.
6
- * Use these headers when writing SSE responses in platform adapters.
7
- */
8
- export declare const SSE_HEADERS: Record<string, string>;
9
- declare const SSEError_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 & {
10
- readonly _tag: "SSEError";
11
- } & Readonly<A>;
12
- /**
13
- * Error type for SSE operations
14
- */
15
- export declare class SSEError extends SSEError_base<{
16
- readonly cause: unknown;
17
- }> {
18
- }
19
- /**
20
- * SSE event types following the graphql-sse protocol (distinct connections mode).
21
- * @see https://github.com/enisdenjo/graphql-sse/blob/master/PROTOCOL.md
22
- */
23
- export type SSEEventType = "next" | "error" | "complete";
24
- /**
25
- * An SSE event to be sent to the client.
26
- */
27
- export interface SSEEvent {
28
- readonly event: SSEEventType;
29
- readonly data: string;
30
- }
31
- /**
32
- * Platform-neutral SSE response interface using Effect types.
33
- *
34
- * This interface abstracts SSE operations across different platforms
35
- * (Node.js, Bun, Deno, Workers). Platform packages implement this
36
- * interface to bridge their specific HTTP response implementations.
37
- *
38
- * Unlike WebSocket which is bidirectional, SSE is unidirectional
39
- * (server to client only). The subscription query is provided
40
- * upfront when creating the SSE connection.
41
- */
42
- export interface EffectSSE {
43
- /**
44
- * Send an SSE event to the client.
45
- * The platform adapter formats this as proper SSE format:
46
- * ```
47
- * event: next
48
- * data: {"data":{"field":"value"}}
49
- *
50
- * ```
51
- */
52
- readonly sendEvent: (event: SSEEvent) => Effect.Effect<void, SSEError>;
53
- /**
54
- * Effect that completes when the client disconnects.
55
- * Use this to detect client disconnection and cleanup.
56
- */
57
- readonly closed: Effect.Effect<void, SSEError>;
58
- }
59
- /**
60
- * The GraphQL request payload for SSE subscriptions.
61
- * Same as a regular GraphQL HTTP request.
62
- */
63
- export interface SSESubscriptionRequest {
64
- readonly query: string;
65
- readonly variables?: Record<string, unknown>;
66
- readonly operationName?: string;
67
- readonly extensions?: Record<string, unknown>;
68
- }
69
- /**
70
- * Context available during an SSE subscription.
71
- * This is passed to lifecycle hooks.
72
- */
73
- export interface SSEConnectionContext<R> {
74
- /**
75
- * The Effect runtime for this connection.
76
- * Use this to run Effects within the connection scope.
77
- */
78
- readonly runtime: Runtime.Runtime<R>;
79
- /**
80
- * The original subscription request.
81
- */
82
- readonly request: SSESubscriptionRequest;
83
- /**
84
- * Optional authentication/authorization context.
85
- * Populated by the onConnect hook.
86
- */
87
- readonly connectionContext: Record<string, unknown>;
88
- }
89
- /**
90
- * Options for configuring the GraphQL SSE handler.
91
- *
92
- * @template R - Service requirements for lifecycle hooks
93
- */
94
- export interface GraphQLSSEOptions<R> {
95
- /**
96
- * Query complexity limiting configuration.
97
- * When provided, subscriptions are validated against complexity limits
98
- * before execution begins.
99
- */
100
- readonly complexity?: ComplexityConfig;
101
- /**
102
- * Field complexity definitions from the schema builder.
103
- * If using the platform serve() functions, this is typically
104
- * passed automatically.
105
- */
106
- readonly fieldComplexities?: FieldComplexityMap;
107
- /**
108
- * Called before a subscription starts.
109
- *
110
- * Use this for authentication/authorization. Return:
111
- * - A context object to accept the subscription
112
- * - Throw/fail to reject the subscription
113
- *
114
- * The returned object is available in the GraphQL context.
115
- *
116
- * @example
117
- * ```typescript
118
- * onConnect: (request, headers) => Effect.gen(function* () {
119
- * const token = headers.get("authorization")
120
- * const user = yield* AuthService.validateToken(token)
121
- * return { user } // Available in GraphQL context
122
- * })
123
- * ```
124
- */
125
- readonly onConnect?: (request: SSESubscriptionRequest, headers: Headers) => Effect.Effect<Record<string, unknown>, unknown, R>;
126
- /**
127
- * Called when the subscription starts streaming.
128
- */
129
- readonly onSubscribe?: (ctx: SSEConnectionContext<R>) => Effect.Effect<void, never, R>;
130
- /**
131
- * Called when the subscription completes (normally or due to error).
132
- */
133
- readonly onComplete?: (ctx: SSEConnectionContext<R>) => Effect.Effect<void, never, R>;
134
- /**
135
- * Called when the client disconnects.
136
- */
137
- readonly onDisconnect?: (ctx: SSEConnectionContext<R>) => Effect.Effect<void, never, R>;
138
- /**
139
- * Called when an error occurs during subscription execution.
140
- */
141
- readonly onError?: (ctx: SSEConnectionContext<R>, error: unknown) => Effect.Effect<void, never, R>;
142
- }
143
- /**
144
- * Configuration for the SSE endpoint
145
- */
146
- export interface GraphQLSSEConfig {
147
- /**
148
- * Path for SSE connections.
149
- * @default "/graphql/stream"
150
- */
151
- readonly path?: string;
152
- }
153
- /**
154
- * Result of SSE subscription handler creation.
155
- * This is used by platform packages to implement their SSE response.
156
- */
157
- export interface SSESubscriptionResult {
158
- /**
159
- * Stream of SSE events to send to the client.
160
- * The platform adapter should consume this stream and send events.
161
- */
162
- readonly events: Stream.Stream<SSEEvent, SSEError>;
163
- /**
164
- * Effect that should be run when client disconnects.
165
- * This allows cleanup of resources.
166
- */
167
- readonly cleanup: Effect.Effect<void, never, never>;
168
- }
169
- /**
170
- * Format an ExecutionResult as an SSE "next" event.
171
- */
172
- export declare const formatNextEvent: (result: ExecutionResult) => SSEEvent;
173
- /**
174
- * Format errors as an SSE "error" event.
175
- */
176
- export declare const formatErrorEvent: (errors: readonly unknown[]) => SSEEvent;
177
- /**
178
- * Format a "complete" event.
179
- */
180
- export declare const formatCompleteEvent: () => SSEEvent;
181
- /**
182
- * Format an SSE event to the wire format.
183
- * Each event is formatted as:
184
- * ```
185
- * event: <type>
186
- * data: <json>
187
- *
188
- * ```
189
- */
190
- export declare const formatSSEMessage: (event: SSEEvent) => string;
191
- export {};
192
- //# sourceMappingURL=sse-types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"sse-types.d.ts","sourceRoot":"","sources":["../../src/server/sse-types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AACtD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAC9C,OAAO,KAAK,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAA;AAExE;;;GAGG;AACH,eAAO,MAAM,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAKrC,CAAA;;;;AAEV;;GAEG;AACH,qBAAa,QAAS,SAAQ,cAA6B;IACzD,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAA;CACxB,CAAC;CAAG;AAEL;;;GAGG;AACH,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,OAAO,GAAG,UAAU,CAAA;AAExD;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,KAAK,EAAE,YAAY,CAAA;IAC5B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CACtB;AAED;;;;;;;;;;GAUG;AACH,MAAM,WAAW,SAAS;IACxB;;;;;;;;OAQG;IACH,QAAQ,CAAC,SAAS,EAAE,CAAC,KAAK,EAAE,QAAQ,KAAK,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAA;IAEtE;;;OAGG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,QAAQ,CA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age = exports.formatCompleteEvent = exports.formatErrorEvent = exports.formatNextEvent = exports.SSEError = exports.SSE_HEADERS = void 0;
4
- const effect_1 = require("effect");
5
- /**
6
- * Standard SSE response headers following the graphql-sse protocol.
7
- * Use these headers when writing SSE responses in platform adapters.
8
- */
9
- exports.SSE_HEADERS = {
10
- "Content-Type": "text/event-stream",
11
- "Cache-Control": "no-cache",
12
- Connection: "keep-alive",
13
- "X-Accel-Buffering": "no", // Disable nginx buffering
14
- };
15
- /**
16
- * Error type for SSE operations
17
- */
18
- class SSEError extends effect_1.Data.TaggedError("SSEError") {
19
- }
20
- exports.SSEError = SSEError;
21
- /**
22
- * Format an ExecutionResult as an SSE "next" event.
23
- */
24
- const formatNextEvent = (result) => ({
25
- event: "next",
26
- data: JSON.stringify(result),
27
- });
28
- exports.formatNextEvent = formatNextEvent;
29
- /**
30
- * Format errors as an SSE "error" event.
31
- */
32
- const formatErrorEvent = (errors) => ({
33
- event: "error",
34
- data: JSON.stringify({ errors }),
35
- });
36
- exports.formatErrorEvent = formatErrorEvent;
37
- /**
38
- * Format a "complete" event.
39
- */
40
- const formatCompleteEvent = () => ({
41
- event: "complete",
42
- data: "",
43
- });
44
- exports.formatCompleteEvent = formatCompleteEvent;
45
- /**
46
- * Format an SSE event to the wire format.
47
- * Each event is formatted as:
48
- * ```
49
- * event: <type>
50
- * data: <json>
51
- *
52
- * ```
53
- */
54
- const formatSSEMessage = (event) => {
55
- const lines = [`event: ${event.event}`];
56
- if (event.data) {
57
- lines.push(`data: ${event.data}`);
58
- }
59
- lines.push("", ""); // Two newlines to end the event
60
- return lines.join("\n");
61
- };
62
- exports.formatSSEMessage = formatSSEMessage;
63
- //# sourceMappingURL=sse-types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"sse-types.js","sourceRoot":"","sources":["../../src/server/sse-types.ts"],"names":[],"mappings":";;;AAAA,mCAAsD;AAItD;;;GAGG;AACU,QAAA,WAAW,GAA2B;IACjD,cAAc,EAAE,mBAAmB;IAC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effect, Layer } from "effect";
2
- import { GraphQLSchema } from "graphql";
3
- import type { EffectWebSocket, GraphQLWSOptions } from "./ws-types";
4
- /**
5
- * Create a WebSocket handler for GraphQL subscriptions using the graphql-ws protocol.
6
- *
7
- * This function creates a handler that can be used with any WebSocket implementation
8
- * that conforms to the EffectWebSocket interface. Platform packages (node, bun, express)
9
- * provide adapters that convert their native WebSocket to EffectWebSocket.
10
- *
11
- * The handler:
12
- * - Uses the graphql-ws protocol for client communication
13
- * - Creates an Effect runtime from the provided layer for each connection
14
- * - Executes subscriptions using GraphQL's subscribe() function
15
- * - Properly cleans up resources when connections close
16
- *
17
- * @param schema - The GraphQL schema with subscription definitions
18
- * @param layer - Effect layer providing services required by resolvers
19
- * @param options - Optional lifecycle hooks for connection/subscription events
20
- * @returns A function that handles individual WebSocket connections
21
- *
22
- * @example
23
- * ```typescript
24
- * import { makeGraphQLWSHandler } from "@effect-gql/core"
25
- *
26
- * const handler = makeGraphQLWSHandler(schema, serviceLayer, {
27
- * onConnect: (params) => Effect.gen(function* () {
28
- * const user = yield* AuthService.validateToken(params.authToken)
29
- * return { user }
30
- * }),
31
- * })
32
- *
33
- * // In platform-specific code:
34
- * const effectSocket = toEffectWebSocket(rawWebSocket)
35
- * await Effect.runPromise(handler(effectSocket))
36
- * ```
37
- */
38
- export declare const makeGraphQLWSHandler: <R>(schema: GraphQLSchema, layer: Layer.Layer<R>, options?: GraphQLWSOptions<R>) => ((socket: EffectWebSocket) => Effect.Effect<void, never, never>);
39
- //# sourceMappingURL=ws-adapter.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ws-adapter.d.ts","sourceRoot":"","sources":["../../src/server/ws-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,KAAK,EAA2C,MAAM,QAAQ,CAAA;AAC/E,OAAO,EAAE,aAAa,EAA2B,MAAM,SAAS,CAAA;AAGhE,OAAO,KAAK,EACV,eAAe,EACf,gBAAgB,EAIjB,MAAM,YAAY,CAAA;AAuQnB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,eAAO,MAAM,oBAAoB,GAAI,CAAC,EACpC,QAAQ,aAAa,EACrB,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,EACrB,UAAU,gBAAgB,CAAC,CAAC,CAAC,KAC5B,CAAC,CAAC,MAAM,EAAE,eAAe,KAAK,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC,CA2CjE,CAAA"}