@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
@@ -0,0 +1,1555 @@
1
+ 'use strict';
2
+
3
+ var effect = require('effect');
4
+ var platform = require('@effect/platform');
5
+ var graphql = require('graphql');
6
+ var graphqlWs = require('graphql-ws');
7
+
8
+ // src/server/config.ts
9
+ var defaultConfig = {
10
+ path: "/graphql",
11
+ graphiql: false,
12
+ complexity: void 0,
13
+ introspection: true,
14
+ cacheControl: void 0
15
+ };
16
+ var normalizeConfig = (input = {}) => {
17
+ const path = input.path ?? defaultConfig.path;
18
+ let graphiql = false;
19
+ if (input.graphiql === true) {
20
+ graphiql = { path: "/graphiql", endpoint: path };
21
+ } else if (input.graphiql && typeof input.graphiql === "object") {
22
+ graphiql = {
23
+ path: input.graphiql.path ?? "/graphiql",
24
+ endpoint: input.graphiql.endpoint ?? path
25
+ };
26
+ }
27
+ return {
28
+ path,
29
+ graphiql,
30
+ complexity: input.complexity,
31
+ introspection: input.introspection ?? true,
32
+ cacheControl: input.cacheControl
33
+ };
34
+ };
35
+ var GraphQLRouterConfigFromEnv = effect.Config.all({
36
+ path: effect.Config.string("GRAPHQL_PATH").pipe(effect.Config.withDefault("/graphql")),
37
+ introspection: effect.Config.boolean("GRAPHQL_INTROSPECTION").pipe(effect.Config.withDefault(true)),
38
+ graphiqlEnabled: effect.Config.boolean("GRAPHIQL_ENABLED").pipe(effect.Config.withDefault(false)),
39
+ graphiqlPath: effect.Config.string("GRAPHIQL_PATH").pipe(effect.Config.withDefault("/graphiql")),
40
+ graphiqlEndpoint: effect.Config.string("GRAPHIQL_ENDPOINT").pipe(effect.Config.option),
41
+ maxDepth: effect.Config.number("GRAPHQL_MAX_DEPTH").pipe(effect.Config.option),
42
+ maxComplexity: effect.Config.number("GRAPHQL_MAX_COMPLEXITY").pipe(effect.Config.option),
43
+ maxAliases: effect.Config.number("GRAPHQL_MAX_ALIASES").pipe(effect.Config.option),
44
+ maxFields: effect.Config.number("GRAPHQL_MAX_FIELDS").pipe(effect.Config.option),
45
+ defaultFieldComplexity: effect.Config.number("GRAPHQL_DEFAULT_FIELD_COMPLEXITY").pipe(
46
+ effect.Config.withDefault(1)
47
+ ),
48
+ cacheControlEnabled: effect.Config.boolean("GRAPHQL_CACHE_CONTROL_ENABLED").pipe(
49
+ effect.Config.withDefault(false)
50
+ ),
51
+ cacheControlDefaultMaxAge: effect.Config.number("GRAPHQL_CACHE_CONTROL_DEFAULT_MAX_AGE").pipe(
52
+ effect.Config.withDefault(0)
53
+ ),
54
+ cacheControlDefaultScope: effect.Config.string("GRAPHQL_CACHE_CONTROL_DEFAULT_SCOPE").pipe(
55
+ effect.Config.withDefault("PUBLIC")
56
+ )
57
+ }).pipe(
58
+ effect.Config.map(
59
+ ({
60
+ path,
61
+ introspection,
62
+ graphiqlEnabled,
63
+ graphiqlPath,
64
+ graphiqlEndpoint,
65
+ maxDepth,
66
+ maxComplexity,
67
+ maxAliases,
68
+ maxFields,
69
+ defaultFieldComplexity,
70
+ cacheControlEnabled,
71
+ cacheControlDefaultMaxAge,
72
+ cacheControlDefaultScope
73
+ }) => {
74
+ const hasComplexity = effect.Option.isSome(maxDepth) || effect.Option.isSome(maxComplexity) || effect.Option.isSome(maxAliases) || effect.Option.isSome(maxFields);
75
+ return {
76
+ path,
77
+ introspection,
78
+ graphiql: graphiqlEnabled ? {
79
+ path: graphiqlPath,
80
+ endpoint: effect.Option.isSome(graphiqlEndpoint) ? graphiqlEndpoint.value : path
81
+ } : false,
82
+ complexity: hasComplexity ? {
83
+ maxDepth: effect.Option.getOrUndefined(maxDepth),
84
+ maxComplexity: effect.Option.getOrUndefined(maxComplexity),
85
+ maxAliases: effect.Option.getOrUndefined(maxAliases),
86
+ maxFields: effect.Option.getOrUndefined(maxFields),
87
+ defaultFieldComplexity
88
+ } : void 0,
89
+ cacheControl: cacheControlEnabled ? {
90
+ enabled: true,
91
+ defaultMaxAge: cacheControlDefaultMaxAge,
92
+ defaultScope: cacheControlDefaultScope === "PRIVATE" ? "PRIVATE" : "PUBLIC",
93
+ calculateHttpHeaders: true
94
+ } : void 0
95
+ };
96
+ }
97
+ )
98
+ );
99
+
100
+ // src/server/graphiql.ts
101
+ var graphiqlHtml = (endpoint) => `<!DOCTYPE html>
102
+ <html lang="en">
103
+ <head>
104
+ <meta charset="utf-8" />
105
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
106
+ <title>GraphiQL</title>
107
+ <link
108
+ rel="stylesheet"
109
+ href="https://unpkg.com/graphiql@3/graphiql.min.css"
110
+ />
111
+ </head>
112
+ <body style="margin: 0; overflow: hidden;">
113
+ <div id="graphiql" style="height: 100vh;"></div>
114
+ <script
115
+ crossorigin
116
+ src="https://unpkg.com/react@18/umd/react.production.min.js"
117
+ ></script>
118
+ <script
119
+ crossorigin
120
+ src="https://unpkg.com/react-dom@18/umd/react-dom.production.min.js"
121
+ ></script>
122
+ <script
123
+ crossorigin
124
+ src="https://unpkg.com/graphiql@3/graphiql.min.js"
125
+ ></script>
126
+ <script>
127
+ const fetcher = GraphiQL.createFetcher({
128
+ url: ${JSON.stringify(endpoint)},
129
+ });
130
+ ReactDOM.createRoot(document.getElementById('graphiql')).render(
131
+ React.createElement(GraphiQL, { fetcher })
132
+ );
133
+ </script>
134
+ </body>
135
+ </html>`;
136
+ var ComplexityLimitExceededError = class extends effect.Data.TaggedError("ComplexityLimitExceededError") {
137
+ };
138
+ var ComplexityAnalysisError = class extends effect.Data.TaggedError("ComplexityAnalysisError") {
139
+ };
140
+ var defaultComplexityCalculator = (defaultCost = 1) => {
141
+ return (info) => effect.Effect.try({
142
+ try: () => {
143
+ const fragments = /* @__PURE__ */ new Map();
144
+ for (const definition of info.document.definitions) {
145
+ if (definition.kind === graphql.Kind.FRAGMENT_DEFINITION) {
146
+ fragments.set(definition.name.value, definition);
147
+ }
148
+ }
149
+ const rootType = getRootType(info.schema, info.operation.operation);
150
+ if (!rootType) {
151
+ throw new Error(`No root type found for operation: ${info.operation.operation}`);
152
+ }
153
+ const result = analyzeSelectionSet(
154
+ info.operation.selectionSet,
155
+ rootType,
156
+ info.schema,
157
+ fragments,
158
+ info.fieldComplexities,
159
+ info.variables ?? {},
160
+ defaultCost,
161
+ 1,
162
+ // Starting depth
163
+ /* @__PURE__ */ new Set()
164
+ // Visited fragments to prevent infinite loops
165
+ );
166
+ return result;
167
+ },
168
+ catch: (error) => new ComplexityAnalysisError({
169
+ message: `Failed to analyze query complexity: ${error}`,
170
+ cause: error
171
+ })
172
+ });
173
+ };
174
+ function getRootType(schema, operation) {
175
+ switch (operation) {
176
+ case "query":
177
+ return schema.getQueryType() ?? null;
178
+ case "mutation":
179
+ return schema.getMutationType() ?? null;
180
+ case "subscription":
181
+ return schema.getSubscriptionType() ?? null;
182
+ }
183
+ }
184
+ function getNamedType(type) {
185
+ if (type instanceof graphql.GraphQLNonNull || type instanceof graphql.GraphQLList) {
186
+ return getNamedType(type.ofType);
187
+ }
188
+ if (type instanceof graphql.GraphQLObjectType) {
189
+ return type;
190
+ }
191
+ return null;
192
+ }
193
+ function accumulateResult(acc, result) {
194
+ acc.maxDepth = Math.max(acc.maxDepth, result.depth);
195
+ acc.complexity += result.complexity;
196
+ acc.fieldCount += result.fieldCount;
197
+ acc.aliasCount += result.aliasCount;
198
+ }
199
+ function analyzeSelectionSet(selectionSet, parentType, schema, fragments, fieldComplexities, variables, defaultCost, currentDepth, visitedFragments) {
200
+ const ctx = { schema, fragments, fieldComplexities, variables, defaultCost };
201
+ const acc = { maxDepth: currentDepth, complexity: 0, fieldCount: 0, aliasCount: 0 };
202
+ for (const selection of selectionSet.selections) {
203
+ const result = analyzeSelection(selection, parentType, ctx, currentDepth, visitedFragments);
204
+ accumulateResult(acc, result);
205
+ }
206
+ return {
207
+ depth: acc.maxDepth,
208
+ complexity: acc.complexity,
209
+ fieldCount: acc.fieldCount,
210
+ aliasCount: acc.aliasCount
211
+ };
212
+ }
213
+ function analyzeSelection(selection, parentType, ctx, currentDepth, visitedFragments) {
214
+ switch (selection.kind) {
215
+ case graphql.Kind.FIELD:
216
+ return analyzeField(selection, parentType, ctx, currentDepth, visitedFragments);
217
+ case graphql.Kind.FRAGMENT_SPREAD:
218
+ return analyzeFragmentSpread(selection, ctx, currentDepth, visitedFragments);
219
+ case graphql.Kind.INLINE_FRAGMENT:
220
+ return analyzeInlineFragment(selection, parentType, ctx, currentDepth, visitedFragments);
221
+ }
222
+ }
223
+ function analyzeField(field, parentType, ctx, currentDepth, visitedFragments) {
224
+ const fieldName = field.name.value;
225
+ const aliasCount = field.alias ? 1 : 0;
226
+ if (fieldName.startsWith("__")) {
227
+ return { depth: currentDepth, complexity: 0, fieldCount: 1, aliasCount };
228
+ }
229
+ const schemaField = parentType.getFields()[fieldName];
230
+ if (!schemaField) {
231
+ return { depth: currentDepth, complexity: ctx.defaultCost, fieldCount: 1, aliasCount };
232
+ }
233
+ const args = resolveFieldArguments(field, ctx.variables);
234
+ const complexityKey = `${parentType.name}.${fieldName}`;
235
+ const fieldComplexity = ctx.fieldComplexities.get(complexityKey);
236
+ const cost = fieldComplexity !== void 0 ? typeof fieldComplexity === "function" ? fieldComplexity(args) : fieldComplexity : ctx.defaultCost;
237
+ if (field.selectionSet) {
238
+ const fieldType = getNamedType(schemaField.type);
239
+ if (fieldType) {
240
+ const nestedResult = analyzeSelectionSet(
241
+ field.selectionSet,
242
+ fieldType,
243
+ ctx.schema,
244
+ ctx.fragments,
245
+ ctx.fieldComplexities,
246
+ ctx.variables,
247
+ ctx.defaultCost,
248
+ currentDepth + 1,
249
+ visitedFragments
250
+ );
251
+ return {
252
+ depth: nestedResult.depth,
253
+ complexity: cost + nestedResult.complexity,
254
+ fieldCount: 1 + nestedResult.fieldCount,
255
+ aliasCount: aliasCount + nestedResult.aliasCount
256
+ };
257
+ }
258
+ }
259
+ return { depth: currentDepth, complexity: cost, fieldCount: 1, aliasCount };
260
+ }
261
+ function analyzeFragmentSpread(spread, ctx, currentDepth, visitedFragments) {
262
+ const fragmentName = spread.name.value;
263
+ if (visitedFragments.has(fragmentName)) {
264
+ return { depth: currentDepth, complexity: 0, fieldCount: 0, aliasCount: 0 };
265
+ }
266
+ const fragment = ctx.fragments.get(fragmentName);
267
+ if (!fragment) {
268
+ return { depth: currentDepth, complexity: 0, fieldCount: 0, aliasCount: 0 };
269
+ }
270
+ const fragmentType = ctx.schema.getType(fragment.typeCondition.name.value);
271
+ if (!(fragmentType instanceof graphql.GraphQLObjectType)) {
272
+ return { depth: currentDepth, complexity: 0, fieldCount: 0, aliasCount: 0 };
273
+ }
274
+ const newVisited = new Set(visitedFragments);
275
+ newVisited.add(fragmentName);
276
+ return analyzeSelectionSet(
277
+ fragment.selectionSet,
278
+ fragmentType,
279
+ ctx.schema,
280
+ ctx.fragments,
281
+ ctx.fieldComplexities,
282
+ ctx.variables,
283
+ ctx.defaultCost,
284
+ currentDepth,
285
+ newVisited
286
+ );
287
+ }
288
+ function analyzeInlineFragment(fragment, parentType, ctx, currentDepth, visitedFragments) {
289
+ let targetType = parentType;
290
+ if (fragment.typeCondition) {
291
+ const conditionType = ctx.schema.getType(fragment.typeCondition.name.value);
292
+ if (conditionType instanceof graphql.GraphQLObjectType) {
293
+ targetType = conditionType;
294
+ }
295
+ }
296
+ return analyzeSelectionSet(
297
+ fragment.selectionSet,
298
+ targetType,
299
+ ctx.schema,
300
+ ctx.fragments,
301
+ ctx.fieldComplexities,
302
+ ctx.variables,
303
+ ctx.defaultCost,
304
+ currentDepth,
305
+ visitedFragments
306
+ );
307
+ }
308
+ function resolveFieldArguments(field, variables) {
309
+ const args = {};
310
+ if (!field.arguments) {
311
+ return args;
312
+ }
313
+ for (const arg of field.arguments) {
314
+ const value = arg.value;
315
+ switch (value.kind) {
316
+ case graphql.Kind.VARIABLE:
317
+ args[arg.name.value] = variables[value.name.value];
318
+ break;
319
+ case graphql.Kind.INT:
320
+ args[arg.name.value] = parseInt(value.value, 10);
321
+ break;
322
+ case graphql.Kind.FLOAT:
323
+ args[arg.name.value] = parseFloat(value.value);
324
+ break;
325
+ case graphql.Kind.STRING:
326
+ args[arg.name.value] = value.value;
327
+ break;
328
+ case graphql.Kind.BOOLEAN:
329
+ args[arg.name.value] = value.value;
330
+ break;
331
+ case graphql.Kind.NULL:
332
+ args[arg.name.value] = null;
333
+ break;
334
+ case graphql.Kind.ENUM:
335
+ args[arg.name.value] = value.value;
336
+ break;
337
+ case graphql.Kind.LIST:
338
+ args[arg.name.value] = [];
339
+ break;
340
+ case graphql.Kind.OBJECT:
341
+ args[arg.name.value] = {};
342
+ break;
343
+ }
344
+ }
345
+ return args;
346
+ }
347
+ var validateComplexity = (query, operationName, variables, schema, fieldComplexities, config) => effect.Effect.gen(function* () {
348
+ const document = yield* effect.Effect.try({
349
+ try: () => graphql.parse(query),
350
+ catch: (error) => new ComplexityAnalysisError({
351
+ message: `Failed to parse query: ${error}`,
352
+ cause: error
353
+ })
354
+ });
355
+ const operation = yield* effect.Effect.try({
356
+ try: () => {
357
+ const operations = document.definitions.filter(
358
+ (d) => d.kind === graphql.Kind.OPERATION_DEFINITION
359
+ );
360
+ if (operations.length === 0) {
361
+ throw new Error("No operation found in query");
362
+ }
363
+ if (operationName) {
364
+ const op = operations.find((o) => o.name?.value === operationName);
365
+ if (!op) {
366
+ throw new Error(`Operation "${operationName}" not found`);
367
+ }
368
+ return op;
369
+ }
370
+ if (operations.length > 1) {
371
+ throw new Error("Multiple operations found - operationName required");
372
+ }
373
+ return operations[0];
374
+ },
375
+ catch: (error) => new ComplexityAnalysisError({
376
+ message: String(error),
377
+ cause: error
378
+ })
379
+ });
380
+ const calculator = config.calculator ?? defaultComplexityCalculator(config.defaultFieldComplexity ?? 1);
381
+ const result = yield* calculator({
382
+ document,
383
+ operation,
384
+ variables,
385
+ schema,
386
+ fieldComplexities
387
+ });
388
+ const checkLimit = (limitType, limit, actual) => effect.Effect.gen(function* () {
389
+ if (limit !== void 0 && actual > limit) {
390
+ const exceededInfo = {
391
+ result,
392
+ exceededLimit: limitType,
393
+ limit,
394
+ actual,
395
+ query,
396
+ operationName
397
+ };
398
+ if (config.onExceeded) {
399
+ yield* config.onExceeded(exceededInfo);
400
+ }
401
+ yield* effect.Effect.fail(
402
+ new ComplexityLimitExceededError({
403
+ message: `Query ${limitType} of ${actual} exceeds maximum allowed ${limitType} of ${limit}`,
404
+ limit,
405
+ actual,
406
+ limitType
407
+ })
408
+ );
409
+ }
410
+ });
411
+ yield* checkLimit("depth", config.maxDepth, result.depth);
412
+ yield* checkLimit("complexity", config.maxComplexity, result.complexity);
413
+ yield* checkLimit("aliases", config.maxAliases, result.aliasCount);
414
+ yield* checkLimit("fields", config.maxFields, result.fieldCount);
415
+ return result;
416
+ });
417
+ var ComplexityConfigFromEnv = effect.Config.all({
418
+ maxDepth: effect.Config.number("GRAPHQL_MAX_DEPTH").pipe(effect.Config.option),
419
+ maxComplexity: effect.Config.number("GRAPHQL_MAX_COMPLEXITY").pipe(effect.Config.option),
420
+ maxAliases: effect.Config.number("GRAPHQL_MAX_ALIASES").pipe(effect.Config.option),
421
+ maxFields: effect.Config.number("GRAPHQL_MAX_FIELDS").pipe(effect.Config.option),
422
+ defaultFieldComplexity: effect.Config.number("GRAPHQL_DEFAULT_FIELD_COMPLEXITY").pipe(
423
+ effect.Config.withDefault(1)
424
+ )
425
+ }).pipe(
426
+ effect.Config.map(({ maxDepth, maxComplexity, maxAliases, maxFields, defaultFieldComplexity }) => ({
427
+ maxDepth: effect.Option.getOrUndefined(maxDepth),
428
+ maxComplexity: effect.Option.getOrUndefined(maxComplexity),
429
+ maxAliases: effect.Option.getOrUndefined(maxAliases),
430
+ maxFields: effect.Option.getOrUndefined(maxFields),
431
+ defaultFieldComplexity
432
+ }))
433
+ );
434
+ var depthOnlyCalculator = (info) => effect.Effect.try({
435
+ try: () => {
436
+ const fragments = /* @__PURE__ */ new Map();
437
+ for (const definition of info.document.definitions) {
438
+ if (definition.kind === graphql.Kind.FRAGMENT_DEFINITION) {
439
+ fragments.set(definition.name.value, definition);
440
+ }
441
+ }
442
+ const depth = calculateMaxDepth(info.operation.selectionSet, fragments, 1, /* @__PURE__ */ new Set());
443
+ return {
444
+ depth,
445
+ complexity: 0,
446
+ fieldCount: 0,
447
+ aliasCount: 0
448
+ };
449
+ },
450
+ catch: (error) => new ComplexityAnalysisError({
451
+ message: `Failed to analyze query depth: ${error}`,
452
+ cause: error
453
+ })
454
+ });
455
+ function calculateMaxDepth(selectionSet, fragments, currentDepth, visitedFragments) {
456
+ let maxDepth = currentDepth;
457
+ for (const selection of selectionSet.selections) {
458
+ switch (selection.kind) {
459
+ case graphql.Kind.FIELD:
460
+ if (selection.selectionSet) {
461
+ const nestedDepth = calculateMaxDepth(
462
+ selection.selectionSet,
463
+ fragments,
464
+ currentDepth + 1,
465
+ visitedFragments
466
+ );
467
+ maxDepth = Math.max(maxDepth, nestedDepth);
468
+ }
469
+ break;
470
+ case graphql.Kind.FRAGMENT_SPREAD: {
471
+ const fragmentName = selection.name.value;
472
+ if (!visitedFragments.has(fragmentName)) {
473
+ const fragment = fragments.get(fragmentName);
474
+ if (fragment) {
475
+ const newVisited = new Set(visitedFragments);
476
+ newVisited.add(fragmentName);
477
+ const fragmentDepth = calculateMaxDepth(
478
+ fragment.selectionSet,
479
+ fragments,
480
+ currentDepth,
481
+ newVisited
482
+ );
483
+ maxDepth = Math.max(maxDepth, fragmentDepth);
484
+ }
485
+ }
486
+ break;
487
+ }
488
+ case graphql.Kind.INLINE_FRAGMENT: {
489
+ const inlineDepth = calculateMaxDepth(
490
+ selection.selectionSet,
491
+ fragments,
492
+ currentDepth,
493
+ visitedFragments
494
+ );
495
+ maxDepth = Math.max(maxDepth, inlineDepth);
496
+ break;
497
+ }
498
+ }
499
+ }
500
+ return maxDepth;
501
+ }
502
+ var combineCalculators = (...calculators) => {
503
+ return (info) => effect.Effect.gen(function* () {
504
+ let maxDepth = 0;
505
+ let maxComplexity = 0;
506
+ let maxFieldCount = 0;
507
+ let maxAliasCount = 0;
508
+ for (const calculator of calculators) {
509
+ const result = yield* calculator(info);
510
+ maxDepth = Math.max(maxDepth, result.depth);
511
+ maxComplexity = Math.max(maxComplexity, result.complexity);
512
+ maxFieldCount = Math.max(maxFieldCount, result.fieldCount);
513
+ maxAliasCount = Math.max(maxAliasCount, result.aliasCount);
514
+ }
515
+ return {
516
+ depth: maxDepth,
517
+ complexity: maxComplexity,
518
+ fieldCount: maxFieldCount,
519
+ aliasCount: maxAliasCount
520
+ };
521
+ });
522
+ };
523
+ var computeCachePolicy = (info) => effect.Effect.sync(() => {
524
+ const fragments = /* @__PURE__ */ new Map();
525
+ for (const definition of info.document.definitions) {
526
+ if (definition.kind === graphql.Kind.FRAGMENT_DEFINITION) {
527
+ fragments.set(definition.name.value, definition);
528
+ }
529
+ }
530
+ const rootType = getRootType2(info.schema, info.operation.operation);
531
+ if (!rootType) {
532
+ return { maxAge: 0, scope: "PUBLIC" };
533
+ }
534
+ const defaultMaxAge = info.config.defaultMaxAge ?? 0;
535
+ const defaultScope = info.config.defaultScope ?? "PUBLIC";
536
+ const result = analyzeSelectionSet2(
537
+ info.operation.selectionSet,
538
+ rootType,
539
+ info.schema,
540
+ fragments,
541
+ info.cacheHints,
542
+ defaultMaxAge,
543
+ defaultScope,
544
+ void 0,
545
+ // No parent maxAge for root
546
+ /* @__PURE__ */ new Set()
547
+ );
548
+ return result;
549
+ });
550
+ var computeCachePolicyFromQuery = (query, operationName, schema, cacheHints, config = {}) => effect.Effect.gen(function* () {
551
+ const document = yield* effect.Effect.try({
552
+ try: () => graphql.parse(query),
553
+ catch: (error) => new Error(`Failed to parse query: ${error}`)
554
+ });
555
+ const operation = yield* effect.Effect.try({
556
+ try: () => {
557
+ const operations = document.definitions.filter(
558
+ (d) => d.kind === graphql.Kind.OPERATION_DEFINITION
559
+ );
560
+ if (operations.length === 0) {
561
+ throw new Error("No operation found in query");
562
+ }
563
+ if (operationName) {
564
+ const op = operations.find((o) => o.name?.value === operationName);
565
+ if (!op) {
566
+ throw new Error(`Operation "${operationName}" not found`);
567
+ }
568
+ return op;
569
+ }
570
+ if (operations.length > 1) {
571
+ throw new Error("Multiple operations found - operationName required");
572
+ }
573
+ return operations[0];
574
+ },
575
+ catch: (error) => error
576
+ });
577
+ return yield* computeCachePolicy({
578
+ document,
579
+ operation,
580
+ schema,
581
+ cacheHints,
582
+ config
583
+ });
584
+ });
585
+ var toCacheControlHeader = (policy) => {
586
+ if (policy.maxAge === 0) {
587
+ return "no-store";
588
+ }
589
+ const directives = [];
590
+ directives.push(policy.scope === "PRIVATE" ? "private" : "public");
591
+ directives.push(`max-age=${policy.maxAge}`);
592
+ return directives.join(", ");
593
+ };
594
+ function getRootType2(schema, operation) {
595
+ switch (operation) {
596
+ case "query":
597
+ return schema.getQueryType() ?? null;
598
+ case "mutation":
599
+ return schema.getMutationType() ?? null;
600
+ case "subscription":
601
+ return schema.getSubscriptionType() ?? null;
602
+ }
603
+ }
604
+ function getNamedType2(type) {
605
+ if (type instanceof graphql.GraphQLNonNull || type instanceof graphql.GraphQLList) {
606
+ return getNamedType2(type.ofType);
607
+ }
608
+ if (type instanceof graphql.GraphQLObjectType || type instanceof graphql.GraphQLScalarType || type instanceof graphql.GraphQLEnumType) {
609
+ return type;
610
+ }
611
+ return null;
612
+ }
613
+ function isLeafType(type) {
614
+ const namedType = getNamedType2(type);
615
+ return namedType instanceof graphql.GraphQLScalarType || namedType instanceof graphql.GraphQLEnumType;
616
+ }
617
+ function aggregatePolicy(acc, policy) {
618
+ if (acc.minMaxAge === void 0) {
619
+ acc.minMaxAge = policy.maxAge;
620
+ } else {
621
+ acc.minMaxAge = Math.min(acc.minMaxAge, policy.maxAge);
622
+ }
623
+ if (policy.scope === "PRIVATE") {
624
+ acc.hasPrivate = true;
625
+ }
626
+ }
627
+ function analyzeFragmentSpread2(fragmentName, ctx, parentMaxAge, visitedFragments) {
628
+ if (visitedFragments.has(fragmentName)) {
629
+ return void 0;
630
+ }
631
+ const fragment = ctx.fragments.get(fragmentName);
632
+ if (!fragment) {
633
+ return void 0;
634
+ }
635
+ const fragmentType = ctx.schema.getType(fragment.typeCondition.name.value);
636
+ if (!(fragmentType instanceof graphql.GraphQLObjectType)) {
637
+ return void 0;
638
+ }
639
+ const newVisited = new Set(visitedFragments);
640
+ newVisited.add(fragmentName);
641
+ return analyzeSelectionSet2(fragment.selectionSet, fragmentType, ctx, parentMaxAge, newVisited);
642
+ }
643
+ function analyzeInlineFragment2(selection, parentType, ctx, parentMaxAge, visitedFragments) {
644
+ let targetType = parentType;
645
+ if (selection.typeCondition) {
646
+ const conditionType = ctx.schema.getType(selection.typeCondition.name.value);
647
+ if (conditionType instanceof graphql.GraphQLObjectType) {
648
+ targetType = conditionType;
649
+ }
650
+ }
651
+ return analyzeSelectionSet2(
652
+ selection.selectionSet,
653
+ targetType,
654
+ ctx,
655
+ parentMaxAge,
656
+ visitedFragments
657
+ );
658
+ }
659
+ function lookupEffectiveCacheHint(parentTypeName, fieldName, returnType, cacheHints) {
660
+ const fieldKey = `${parentTypeName}.${fieldName}`;
661
+ const fieldHint = cacheHints.get(fieldKey);
662
+ if (fieldHint) return fieldHint;
663
+ const namedType = getNamedType2(returnType);
664
+ return namedType ? cacheHints.get(namedType.name) : void 0;
665
+ }
666
+ function computeFieldMaxAge(hint, fieldType, parentMaxAge, defaultMaxAge) {
667
+ if (hint) {
668
+ if (hint.inheritMaxAge && parentMaxAge !== void 0) {
669
+ return parentMaxAge;
670
+ }
671
+ if (hint.maxAge !== void 0) {
672
+ return hint.maxAge;
673
+ }
674
+ }
675
+ if (isLeafType(fieldType) && parentMaxAge !== void 0) {
676
+ return parentMaxAge;
677
+ }
678
+ return defaultMaxAge;
679
+ }
680
+ function analyzeSelectionSet2(selectionSet, parentType, schemaOrCtx, fragmentsOrParentMaxAge, cacheHintsOrVisited, defaultMaxAge, defaultScope, parentMaxAge, visitedFragments) {
681
+ let ctx;
682
+ let actualParentMaxAge;
683
+ let actualVisitedFragments;
684
+ if (schemaOrCtx instanceof graphql.GraphQLSchema) {
685
+ ctx = {
686
+ schema: schemaOrCtx,
687
+ fragments: fragmentsOrParentMaxAge,
688
+ cacheHints: cacheHintsOrVisited,
689
+ defaultMaxAge,
690
+ defaultScope
691
+ };
692
+ actualParentMaxAge = parentMaxAge;
693
+ actualVisitedFragments = visitedFragments;
694
+ } else {
695
+ ctx = schemaOrCtx;
696
+ actualParentMaxAge = fragmentsOrParentMaxAge;
697
+ actualVisitedFragments = cacheHintsOrVisited;
698
+ }
699
+ const acc = { minMaxAge: void 0, hasPrivate: false };
700
+ for (const selection of selectionSet.selections) {
701
+ let fieldPolicy;
702
+ switch (selection.kind) {
703
+ case graphql.Kind.FIELD:
704
+ fieldPolicy = analyzeField2(
705
+ selection,
706
+ parentType,
707
+ ctx,
708
+ actualParentMaxAge,
709
+ actualVisitedFragments
710
+ );
711
+ break;
712
+ case graphql.Kind.FRAGMENT_SPREAD:
713
+ fieldPolicy = analyzeFragmentSpread2(
714
+ selection.name.value,
715
+ ctx,
716
+ actualParentMaxAge,
717
+ actualVisitedFragments
718
+ );
719
+ break;
720
+ case graphql.Kind.INLINE_FRAGMENT:
721
+ fieldPolicy = analyzeInlineFragment2(
722
+ selection,
723
+ parentType,
724
+ ctx,
725
+ actualParentMaxAge,
726
+ actualVisitedFragments
727
+ );
728
+ break;
729
+ }
730
+ if (fieldPolicy) {
731
+ aggregatePolicy(acc, fieldPolicy);
732
+ }
733
+ }
734
+ return {
735
+ maxAge: acc.minMaxAge ?? ctx.defaultMaxAge,
736
+ scope: acc.hasPrivate ? "PRIVATE" : ctx.defaultScope
737
+ };
738
+ }
739
+ function analyzeField2(field, parentType, ctx, parentMaxAge, visitedFragments) {
740
+ const fieldName = field.name.value;
741
+ if (fieldName.startsWith("__")) {
742
+ return { maxAge: Infinity, scope: "PUBLIC" };
743
+ }
744
+ const schemaField = parentType.getFields()[fieldName];
745
+ if (!schemaField) {
746
+ return { maxAge: ctx.defaultMaxAge, scope: ctx.defaultScope };
747
+ }
748
+ const effectiveHint = lookupEffectiveCacheHint(
749
+ parentType.name,
750
+ fieldName,
751
+ schemaField.type,
752
+ ctx.cacheHints
753
+ );
754
+ const fieldMaxAge = computeFieldMaxAge(
755
+ effectiveHint,
756
+ schemaField.type,
757
+ parentMaxAge,
758
+ ctx.defaultMaxAge
759
+ );
760
+ const fieldScope = effectiveHint?.scope ?? ctx.defaultScope;
761
+ const namedType = getNamedType2(schemaField.type);
762
+ if (field.selectionSet && namedType instanceof graphql.GraphQLObjectType) {
763
+ const nestedPolicy = analyzeSelectionSet2(
764
+ field.selectionSet,
765
+ namedType,
766
+ ctx,
767
+ fieldMaxAge,
768
+ visitedFragments
769
+ );
770
+ return {
771
+ maxAge: Math.min(fieldMaxAge, nestedPolicy.maxAge),
772
+ scope: fieldScope === "PRIVATE" || nestedPolicy.scope === "PRIVATE" ? "PRIVATE" : "PUBLIC"
773
+ };
774
+ }
775
+ return { maxAge: fieldMaxAge, scope: fieldScope };
776
+ }
777
+ var CacheControlConfigFromEnv = effect.Config.all({
778
+ enabled: effect.Config.boolean("GRAPHQL_CACHE_CONTROL_ENABLED").pipe(effect.Config.withDefault(true)),
779
+ defaultMaxAge: effect.Config.number("GRAPHQL_CACHE_CONTROL_DEFAULT_MAX_AGE").pipe(effect.Config.withDefault(0)),
780
+ defaultScope: effect.Config.string("GRAPHQL_CACHE_CONTROL_DEFAULT_SCOPE").pipe(
781
+ effect.Config.withDefault("PUBLIC"),
782
+ effect.Config.map((s) => s === "PRIVATE" ? "PRIVATE" : "PUBLIC")
783
+ ),
784
+ calculateHttpHeaders: effect.Config.boolean("GRAPHQL_CACHE_CONTROL_HTTP_HEADERS").pipe(
785
+ effect.Config.withDefault(true)
786
+ )
787
+ });
788
+ var ExtensionsService = effect.Context.GenericTag(
789
+ "@effect-gql/ExtensionsService"
790
+ );
791
+ function deepMerge(target, source) {
792
+ const result = { ...target };
793
+ for (const key of Object.keys(source)) {
794
+ const sourceValue = source[key];
795
+ const targetValue = result[key];
796
+ if (typeof sourceValue === "object" && sourceValue !== null && !Array.isArray(sourceValue) && typeof targetValue === "object" && targetValue !== null && !Array.isArray(targetValue)) {
797
+ result[key] = deepMerge(
798
+ targetValue,
799
+ sourceValue
800
+ );
801
+ } else {
802
+ result[key] = sourceValue;
803
+ }
804
+ }
805
+ return result;
806
+ }
807
+ var makeExtensionsService = () => effect.Effect.gen(function* () {
808
+ const ref = yield* effect.Ref.make({});
809
+ return ExtensionsService.of({
810
+ set: (key, value) => effect.Ref.update(ref, (current) => ({ ...current, [key]: value })),
811
+ merge: (key, value) => effect.Ref.update(ref, (current) => {
812
+ const existing = current[key];
813
+ if (typeof existing === "object" && existing !== null && !Array.isArray(existing)) {
814
+ return {
815
+ ...current,
816
+ [key]: deepMerge(existing, value)
817
+ };
818
+ }
819
+ return { ...current, [key]: value };
820
+ }),
821
+ get: () => effect.Ref.get(ref)
822
+ });
823
+ });
824
+ var runExtensionHooks = (extensions, hookName, getHookEffect) => effect.Effect.forEach(
825
+ extensions.filter((ext) => ext[hookName] !== void 0),
826
+ (ext) => getHookEffect(ext).pipe(
827
+ effect.Effect.catchAllCause(
828
+ (cause) => effect.Effect.logWarning(`Extension "${ext.name}" ${String(hookName)} hook failed`, cause)
829
+ )
830
+ ),
831
+ { discard: true }
832
+ );
833
+ var runParseHooks = (extensions, source, document) => runExtensionHooks(extensions, "onParse", (ext) => ext.onParse(source, document));
834
+ var runValidateHooks = (extensions, document, errors) => runExtensionHooks(extensions, "onValidate", (ext) => ext.onValidate(document, errors));
835
+ var runExecuteStartHooks = (extensions, args) => runExtensionHooks(extensions, "onExecuteStart", (ext) => ext.onExecuteStart(args));
836
+ var runExecuteEndHooks = (extensions, result) => runExtensionHooks(extensions, "onExecuteEnd", (ext) => ext.onExecuteEnd(result));
837
+
838
+ // src/server/router.ts
839
+ var defaultErrorHandler = (cause) => (process.env.NODE_ENV !== "production" ? effect.Effect.logError("GraphQL error", cause) : effect.Effect.void).pipe(
840
+ effect.Effect.andThen(
841
+ platform.HttpServerResponse.json(
842
+ {
843
+ errors: [
844
+ {
845
+ message: "An error occurred processing your request"
846
+ }
847
+ ]
848
+ },
849
+ { status: 500 }
850
+ ).pipe(effect.Effect.orDie)
851
+ )
852
+ );
853
+ var parseGraphQLQuery = (query, extensionsService) => effect.Effect.gen(function* () {
854
+ try {
855
+ const document = graphql.parse(query);
856
+ return { ok: true, document };
857
+ } catch (parseError) {
858
+ const extensionData = yield* extensionsService.get();
859
+ const response = yield* platform.HttpServerResponse.json({
860
+ errors: [{ message: String(parseError) }],
861
+ extensions: Object.keys(extensionData).length > 0 ? extensionData : void 0
862
+ }).pipe(effect.Effect.orDie);
863
+ return { ok: false, response };
864
+ }
865
+ });
866
+ var runComplexityValidation = (body, schema, fieldComplexities, complexityConfig) => {
867
+ if (!complexityConfig) {
868
+ return effect.Effect.void;
869
+ }
870
+ return validateComplexity(
871
+ body.query,
872
+ body.operationName,
873
+ body.variables,
874
+ schema,
875
+ fieldComplexities,
876
+ complexityConfig
877
+ ).pipe(
878
+ effect.Effect.catchTag("ComplexityLimitExceededError", (error) => effect.Effect.fail(error)),
879
+ effect.Effect.catchTag(
880
+ "ComplexityAnalysisError",
881
+ (error) => effect.Effect.logWarning("Complexity analysis failed", error)
882
+ )
883
+ );
884
+ };
885
+ var executeGraphQLQuery = (schema, document, variables, operationName, runtime) => effect.Effect.gen(function* () {
886
+ const executeResult = yield* effect.Effect.try({
887
+ try: () => graphql.execute({
888
+ schema,
889
+ document,
890
+ variableValues: variables,
891
+ operationName,
892
+ contextValue: { runtime }
893
+ }),
894
+ catch: (error) => new Error(String(error))
895
+ });
896
+ if (executeResult && typeof executeResult === "object" && "then" in executeResult) {
897
+ return yield* effect.Effect.promise(
898
+ () => executeResult
899
+ );
900
+ }
901
+ return executeResult;
902
+ });
903
+ var computeCacheControlHeader = (document, operationName, schema, cacheHints, cacheControlConfig) => effect.Effect.gen(function* () {
904
+ if (cacheControlConfig?.enabled === false || cacheControlConfig?.calculateHttpHeaders === false) {
905
+ return void 0;
906
+ }
907
+ const operations = document.definitions.filter(
908
+ (d) => d.kind === graphql.Kind.OPERATION_DEFINITION
909
+ );
910
+ const operation = operationName ? operations.find((o) => o.name?.value === operationName) : operations[0];
911
+ if (!operation || operation.operation === "mutation") {
912
+ return void 0;
913
+ }
914
+ const cachePolicy = yield* computeCachePolicy({
915
+ document,
916
+ operation,
917
+ schema,
918
+ cacheHints,
919
+ config: cacheControlConfig ?? {}
920
+ });
921
+ return toCacheControlHeader(cachePolicy);
922
+ });
923
+ var buildGraphQLResponse = (result, extensionData, cacheControlHeader) => {
924
+ const finalResult = Object.keys(extensionData).length > 0 ? {
925
+ ...result,
926
+ extensions: {
927
+ ...result.extensions,
928
+ ...extensionData
929
+ }
930
+ } : result;
931
+ const responseHeaders = cacheControlHeader ? { "cache-control": cacheControlHeader } : void 0;
932
+ return platform.HttpServerResponse.json(finalResult, { headers: responseHeaders }).pipe(effect.Effect.orDie);
933
+ };
934
+ var handleComplexityError = (error) => platform.HttpServerResponse.json(
935
+ {
936
+ errors: [
937
+ {
938
+ message: error.message,
939
+ extensions: {
940
+ code: "COMPLEXITY_LIMIT_EXCEEDED",
941
+ limitType: error.limitType,
942
+ limit: error.limit,
943
+ actual: error.actual
944
+ }
945
+ }
946
+ ]
947
+ },
948
+ { status: 400 }
949
+ ).pipe(effect.Effect.orDie);
950
+ var makeGraphQLRouter = (schema, layer, options = {}) => {
951
+ const resolvedConfig = normalizeConfig(options);
952
+ const fieldComplexities = options.fieldComplexities ?? /* @__PURE__ */ new Map();
953
+ const cacheHints = options.cacheHints ?? /* @__PURE__ */ new Map();
954
+ const extensions = options.extensions ?? [];
955
+ const errorHandler = options.errorHandler ?? defaultErrorHandler;
956
+ const graphqlHandler = effect.Effect.gen(function* () {
957
+ const extensionsService = yield* makeExtensionsService();
958
+ const runtime = yield* effect.Effect.runtime();
959
+ const request = yield* platform.HttpServerRequest.HttpServerRequest;
960
+ const body = yield* request.json;
961
+ const parseResult = yield* parseGraphQLQuery(body.query, extensionsService);
962
+ if (!parseResult.ok) {
963
+ return parseResult.response;
964
+ }
965
+ const document = parseResult.document;
966
+ yield* runParseHooks(extensions, body.query, document).pipe(
967
+ effect.Effect.provideService(ExtensionsService, extensionsService)
968
+ );
969
+ const validationRules = resolvedConfig.introspection ? void 0 : [...graphql.specifiedRules, graphql.NoSchemaIntrospectionCustomRule];
970
+ const validationErrors = graphql.validate(schema, document, validationRules);
971
+ yield* runValidateHooks(extensions, document, validationErrors).pipe(
972
+ effect.Effect.provideService(ExtensionsService, extensionsService)
973
+ );
974
+ if (validationErrors.length > 0) {
975
+ const extensionData2 = yield* extensionsService.get();
976
+ return yield* platform.HttpServerResponse.json(
977
+ {
978
+ errors: validationErrors.map((e) => ({
979
+ message: e.message,
980
+ locations: e.locations,
981
+ path: e.path
982
+ })),
983
+ extensions: Object.keys(extensionData2).length > 0 ? extensionData2 : void 0
984
+ },
985
+ { status: 400 }
986
+ );
987
+ }
988
+ yield* runComplexityValidation(body, schema, fieldComplexities, resolvedConfig.complexity);
989
+ yield* runExecuteStartHooks(extensions, {
990
+ source: body.query,
991
+ document,
992
+ variableValues: body.variables,
993
+ operationName: body.operationName,
994
+ schema,
995
+ fieldComplexities
996
+ }).pipe(effect.Effect.provideService(ExtensionsService, extensionsService));
997
+ const result = yield* executeGraphQLQuery(
998
+ schema,
999
+ document,
1000
+ body.variables,
1001
+ body.operationName,
1002
+ runtime
1003
+ );
1004
+ yield* runExecuteEndHooks(extensions, result).pipe(
1005
+ effect.Effect.provideService(ExtensionsService, extensionsService)
1006
+ );
1007
+ const extensionData = yield* extensionsService.get();
1008
+ const cacheControlHeader = yield* computeCacheControlHeader(
1009
+ document,
1010
+ body.operationName,
1011
+ schema,
1012
+ cacheHints,
1013
+ resolvedConfig.cacheControl
1014
+ );
1015
+ return yield* buildGraphQLResponse(result, extensionData, cacheControlHeader);
1016
+ }).pipe(
1017
+ effect.Effect.provide(layer),
1018
+ effect.Effect.catchAll((error) => {
1019
+ if (error instanceof ComplexityLimitExceededError) {
1020
+ return handleComplexityError(error);
1021
+ }
1022
+ return effect.Effect.fail(error);
1023
+ }),
1024
+ effect.Effect.catchAllCause(errorHandler)
1025
+ );
1026
+ let router = platform.HttpRouter.empty.pipe(
1027
+ platform.HttpRouter.post(resolvedConfig.path, graphqlHandler)
1028
+ );
1029
+ if (resolvedConfig.graphiql) {
1030
+ const { path, endpoint } = resolvedConfig.graphiql;
1031
+ router = router.pipe(
1032
+ platform.HttpRouter.get(path, platform.HttpServerResponse.html(graphiqlHtml(endpoint)))
1033
+ );
1034
+ }
1035
+ return router;
1036
+ };
1037
+
1038
+ // src/server/schema-builder-extensions.ts
1039
+ var toRouter = (builder, layer, options) => {
1040
+ const schema = builder.buildSchema();
1041
+ const fieldComplexities = builder.getFieldComplexities();
1042
+ const cacheHints = builder.getCacheHints();
1043
+ return makeGraphQLRouter(schema, layer, { ...options, fieldComplexities, cacheHints });
1044
+ };
1045
+ var WebSocketError = class extends effect.Data.TaggedError("WebSocketError") {
1046
+ };
1047
+ var createConnectionContext = (extra) => ({
1048
+ runtime: extra.runtime,
1049
+ connectionParams: extra.connectionParams,
1050
+ socket: extra.socket
1051
+ });
1052
+ var makeOnConnectHandler = (options) => {
1053
+ if (!options?.onConnect) return void 0;
1054
+ return async (ctx) => {
1055
+ const extra = ctx.extra;
1056
+ try {
1057
+ const result = await effect.Runtime.runPromise(extra.runtime)(
1058
+ options.onConnect(ctx.connectionParams ?? {})
1059
+ );
1060
+ if (typeof result === "object" && result !== null) {
1061
+ Object.assign(extra.connectionParams, result);
1062
+ }
1063
+ return result !== false;
1064
+ } catch {
1065
+ return false;
1066
+ }
1067
+ };
1068
+ };
1069
+ var makeOnDisconnectHandler = (options) => {
1070
+ if (!options?.onDisconnect) return void 0;
1071
+ return async (ctx) => {
1072
+ const extra = ctx.extra;
1073
+ await effect.Runtime.runPromise(extra.runtime)(
1074
+ options.onDisconnect(createConnectionContext(extra))
1075
+ ).catch(() => {
1076
+ });
1077
+ };
1078
+ };
1079
+ var makeOnSubscribeHandler = (options, schema, complexityConfig, fieldComplexities) => {
1080
+ return async (ctx, id, payload) => {
1081
+ const extra = ctx.extra;
1082
+ const connectionCtx = createConnectionContext(extra);
1083
+ if (complexityConfig) {
1084
+ const validationEffect = validateComplexity(
1085
+ payload.query,
1086
+ payload.operationName ?? void 0,
1087
+ payload.variables ?? void 0,
1088
+ schema,
1089
+ fieldComplexities,
1090
+ complexityConfig
1091
+ ).pipe(
1092
+ effect.Effect.catchAll((error) => {
1093
+ if (error._tag === "ComplexityLimitExceededError") {
1094
+ throw new graphql.GraphQLError(error.message, {
1095
+ extensions: {
1096
+ code: "COMPLEXITY_LIMIT_EXCEEDED",
1097
+ limitType: error.limitType,
1098
+ limit: error.limit,
1099
+ actual: error.actual
1100
+ }
1101
+ });
1102
+ }
1103
+ return effect.Effect.logWarning("Complexity analysis failed for subscription", error);
1104
+ })
1105
+ );
1106
+ await effect.Effect.runPromise(validationEffect);
1107
+ }
1108
+ if (options?.onSubscribe) {
1109
+ await effect.Runtime.runPromise(extra.runtime)(
1110
+ options.onSubscribe(connectionCtx, {
1111
+ id,
1112
+ payload: {
1113
+ query: payload.query,
1114
+ variables: payload.variables ?? void 0,
1115
+ operationName: payload.operationName ?? void 0,
1116
+ extensions: payload.extensions ?? void 0
1117
+ }
1118
+ })
1119
+ );
1120
+ }
1121
+ };
1122
+ };
1123
+ var makeOnCompleteHandler = (options) => {
1124
+ if (!options?.onComplete) return void 0;
1125
+ return async (ctx, id, _payload) => {
1126
+ const extra = ctx.extra;
1127
+ await effect.Runtime.runPromise(extra.runtime)(
1128
+ options.onComplete(createConnectionContext(extra), { id })
1129
+ ).catch(() => {
1130
+ });
1131
+ };
1132
+ };
1133
+ var makeOnErrorHandler = (options) => {
1134
+ if (!options?.onError) return void 0;
1135
+ return async (ctx, _id, _payload, errors) => {
1136
+ const extra = ctx.extra;
1137
+ await effect.Runtime.runPromise(extra.runtime)(
1138
+ options.onError(createConnectionContext(extra), errors)
1139
+ ).catch(() => {
1140
+ });
1141
+ };
1142
+ };
1143
+ var createGraphqlWsSocketAdapter = (socket, runtime) => {
1144
+ let messageCallback = null;
1145
+ return {
1146
+ adapter: {
1147
+ protocol: socket.protocol,
1148
+ send: (data) => effect.Runtime.runPromise(runtime)(
1149
+ socket.send(data).pipe(effect.Effect.catchAll((error) => effect.Effect.logError("WebSocket send error", error)))
1150
+ ),
1151
+ close: (code, reason) => {
1152
+ effect.Runtime.runPromise(runtime)(socket.close(code, reason)).catch(() => {
1153
+ });
1154
+ },
1155
+ onMessage: (cb) => {
1156
+ messageCallback = cb;
1157
+ },
1158
+ onPong: (_payload) => {
1159
+ }
1160
+ },
1161
+ dispatchMessage: async (message) => {
1162
+ if (messageCallback) {
1163
+ await messageCallback(message);
1164
+ }
1165
+ }
1166
+ };
1167
+ };
1168
+ var runConnectionLifecycle = (socket, wsServer, extra) => effect.Effect.gen(function* () {
1169
+ const messageQueue = yield* effect.Queue.unbounded();
1170
+ const closedDeferred = yield* effect.Deferred.make();
1171
+ const messageFiber = yield* effect.Effect.fork(
1172
+ effect.Stream.runForEach(socket.messages, (msg) => effect.Queue.offer(messageQueue, msg)).pipe(
1173
+ effect.Effect.catchAll((error) => effect.Deferred.fail(closedDeferred, error))
1174
+ )
1175
+ );
1176
+ const closeFiber = yield* effect.Effect.fork(
1177
+ socket.closed.pipe(
1178
+ effect.Effect.tap((event) => effect.Deferred.succeed(closedDeferred, event)),
1179
+ effect.Effect.catchAll((error) => effect.Deferred.fail(closedDeferred, error))
1180
+ )
1181
+ );
1182
+ const { adapter, dispatchMessage } = createGraphqlWsSocketAdapter(socket, extra.runtime);
1183
+ const closedHandler = wsServer.opened(adapter, extra);
1184
+ const processMessagesFiber = yield* effect.Effect.fork(
1185
+ effect.Effect.gen(function* () {
1186
+ while (true) {
1187
+ const message = yield* effect.Queue.take(messageQueue);
1188
+ yield* effect.Effect.tryPromise({
1189
+ try: () => dispatchMessage(message),
1190
+ catch: (error) => error
1191
+ }).pipe(effect.Effect.catchAll(() => effect.Effect.void));
1192
+ }
1193
+ })
1194
+ );
1195
+ yield* effect.Deferred.await(closedDeferred).pipe(
1196
+ effect.Effect.catchAll(() => effect.Effect.succeed({ code: 1e3, reason: "Error" }))
1197
+ );
1198
+ closedHandler(1e3, "Connection closed");
1199
+ yield* effect.Fiber.interrupt(messageFiber);
1200
+ yield* effect.Fiber.interrupt(closeFiber);
1201
+ yield* effect.Fiber.interrupt(processMessagesFiber);
1202
+ yield* effect.Queue.shutdown(messageQueue);
1203
+ }).pipe(
1204
+ effect.Effect.catchAllCause(() => effect.Effect.void),
1205
+ effect.Effect.scoped
1206
+ );
1207
+ var makeGraphQLWSHandler = (schema, layer, options) => {
1208
+ const complexityConfig = options?.complexity;
1209
+ const fieldComplexities = options?.fieldComplexities ?? /* @__PURE__ */ new Map();
1210
+ const serverOptions = {
1211
+ schema,
1212
+ context: async (ctx) => {
1213
+ const extra = ctx.extra;
1214
+ return {
1215
+ runtime: extra.runtime,
1216
+ ...extra.connectionParams
1217
+ };
1218
+ },
1219
+ subscribe: async (args) => graphql.subscribe(args),
1220
+ onConnect: makeOnConnectHandler(options),
1221
+ onDisconnect: makeOnDisconnectHandler(options),
1222
+ onSubscribe: makeOnSubscribeHandler(options, schema, complexityConfig, fieldComplexities),
1223
+ onComplete: makeOnCompleteHandler(options),
1224
+ onError: makeOnErrorHandler(options)
1225
+ };
1226
+ const wsServer = graphqlWs.makeServer(serverOptions);
1227
+ return (socket) => effect.Effect.gen(function* () {
1228
+ const runtime = yield* effect.Effect.provide(effect.Effect.runtime(), layer);
1229
+ const extra = {
1230
+ socket,
1231
+ runtime,
1232
+ connectionParams: {}
1233
+ };
1234
+ yield* runConnectionLifecycle(socket, wsServer, extra);
1235
+ }).pipe(
1236
+ effect.Effect.catchAllCause(() => effect.Effect.void),
1237
+ effect.Effect.scoped
1238
+ );
1239
+ };
1240
+ var WS_CLOSED = 3;
1241
+ var toEffectWebSocketFromWs = (ws) => {
1242
+ const messagesEffect = effect.Effect.gen(function* () {
1243
+ const queue = yield* effect.Queue.unbounded();
1244
+ const closed = yield* effect.Deferred.make();
1245
+ ws.on("message", (data) => {
1246
+ const message = data.toString();
1247
+ effect.Effect.runPromise(effect.Queue.offer(queue, message)).catch(() => {
1248
+ });
1249
+ });
1250
+ ws.on("error", (error) => {
1251
+ effect.Effect.runPromise(effect.Deferred.fail(closed, new WebSocketError({ cause: error }))).catch(() => {
1252
+ });
1253
+ });
1254
+ ws.on("close", (code, reason) => {
1255
+ effect.Effect.runPromise(
1256
+ effect.Queue.shutdown(queue).pipe(
1257
+ effect.Effect.andThen(effect.Deferred.succeed(closed, { code, reason: reason.toString() }))
1258
+ )
1259
+ ).catch(() => {
1260
+ });
1261
+ });
1262
+ return { queue, closed };
1263
+ });
1264
+ const messages = effect.Stream.unwrap(
1265
+ messagesEffect.pipe(
1266
+ effect.Effect.map(({ queue }) => effect.Stream.fromQueue(queue).pipe(effect.Stream.catchAll(() => effect.Stream.empty)))
1267
+ )
1268
+ );
1269
+ return {
1270
+ protocol: ws.protocol || "graphql-transport-ws",
1271
+ send: (data) => effect.Effect.async((resume) => {
1272
+ ws.send(data, (error) => {
1273
+ if (error) {
1274
+ resume(effect.Effect.fail(new WebSocketError({ cause: error })));
1275
+ } else {
1276
+ resume(effect.Effect.succeed(void 0));
1277
+ }
1278
+ });
1279
+ }),
1280
+ close: (code, reason) => effect.Effect.sync(() => {
1281
+ ws.close(code ?? 1e3, reason ?? "");
1282
+ }),
1283
+ messages,
1284
+ closed: effect.Effect.async((resume) => {
1285
+ if (ws.readyState === WS_CLOSED) {
1286
+ resume(effect.Effect.succeed({ code: 1e3, reason: "" }));
1287
+ return;
1288
+ }
1289
+ const onClose = (code, reason) => {
1290
+ cleanup();
1291
+ resume(effect.Effect.succeed({ code, reason: reason.toString() }));
1292
+ };
1293
+ const onError = (error) => {
1294
+ cleanup();
1295
+ resume(effect.Effect.fail(new WebSocketError({ cause: error })));
1296
+ };
1297
+ const cleanup = () => {
1298
+ ws.removeListener("close", onClose);
1299
+ ws.removeListener("error", onError);
1300
+ };
1301
+ ws.on("close", onClose);
1302
+ ws.on("error", onError);
1303
+ return effect.Effect.sync(cleanup);
1304
+ })
1305
+ };
1306
+ };
1307
+ var SSE_HEADERS = {
1308
+ "Content-Type": "text/event-stream",
1309
+ "Cache-Control": "no-cache",
1310
+ Connection: "keep-alive",
1311
+ "X-Accel-Buffering": "no"
1312
+ // Disable nginx buffering
1313
+ };
1314
+ var SSEError = class extends effect.Data.TaggedError("SSEError") {
1315
+ };
1316
+ var formatNextEvent = (result) => ({
1317
+ event: "next",
1318
+ data: JSON.stringify(result)
1319
+ });
1320
+ var formatErrorEvent = (errors) => ({
1321
+ event: "error",
1322
+ data: JSON.stringify({ errors })
1323
+ });
1324
+ var formatCompleteEvent = () => ({
1325
+ event: "complete",
1326
+ data: ""
1327
+ });
1328
+ var formatSSEMessage = (event) => {
1329
+ const lines = [`event: ${event.event}`];
1330
+ if (event.data) {
1331
+ lines.push(`data: ${event.data}`);
1332
+ }
1333
+ lines.push("", "");
1334
+ return lines.join("\n");
1335
+ };
1336
+ var makeSSESubscriptionStream = (schema, layer, request, headers, options) => {
1337
+ const complexityConfig = options?.complexity;
1338
+ const fieldComplexities = options?.fieldComplexities ?? /* @__PURE__ */ new Map();
1339
+ return effect.Stream.unwrap(
1340
+ effect.Effect.gen(function* () {
1341
+ const runtime = yield* effect.Effect.provide(effect.Effect.runtime(), layer);
1342
+ let connectionContext = {};
1343
+ if (options?.onConnect) {
1344
+ try {
1345
+ connectionContext = yield* effect.Effect.provide(options.onConnect(request, headers), layer);
1346
+ } catch {
1347
+ return effect.Stream.make(
1348
+ formatErrorEvent([
1349
+ new graphql.GraphQLError("Subscription connection rejected", {
1350
+ extensions: { code: "CONNECTION_REJECTED" }
1351
+ })
1352
+ ]),
1353
+ formatCompleteEvent()
1354
+ );
1355
+ }
1356
+ }
1357
+ let document;
1358
+ try {
1359
+ document = graphql.parse(request.query);
1360
+ } catch (syntaxError) {
1361
+ return effect.Stream.make(formatErrorEvent([syntaxError]), formatCompleteEvent());
1362
+ }
1363
+ const validationErrors = graphql.validate(schema, document);
1364
+ if (validationErrors.length > 0) {
1365
+ return effect.Stream.make(formatErrorEvent(validationErrors), formatCompleteEvent());
1366
+ }
1367
+ const operations = document.definitions.filter(
1368
+ (d) => d.kind === graphql.Kind.OPERATION_DEFINITION
1369
+ );
1370
+ const operation = request.operationName ? operations.find((o) => o.name?.value === request.operationName) : operations[0];
1371
+ if (!operation) {
1372
+ return effect.Stream.make(
1373
+ formatErrorEvent([new graphql.GraphQLError("No operation found in query")]),
1374
+ formatCompleteEvent()
1375
+ );
1376
+ }
1377
+ if (operation.operation !== "subscription") {
1378
+ return effect.Stream.make(
1379
+ formatErrorEvent([
1380
+ new graphql.GraphQLError(
1381
+ `SSE endpoint only supports subscriptions, received: ${operation.operation}`,
1382
+ { extensions: { code: "OPERATION_NOT_SUPPORTED" } }
1383
+ )
1384
+ ]),
1385
+ formatCompleteEvent()
1386
+ );
1387
+ }
1388
+ if (complexityConfig) {
1389
+ const complexityResult = yield* validateComplexity(
1390
+ request.query,
1391
+ request.operationName,
1392
+ request.variables,
1393
+ schema,
1394
+ fieldComplexities,
1395
+ complexityConfig
1396
+ ).pipe(
1397
+ effect.Effect.map(() => null),
1398
+ effect.Effect.catchAll((error) => {
1399
+ if (error._tag === "ComplexityLimitExceededError") {
1400
+ return effect.Effect.succeed(
1401
+ new graphql.GraphQLError(error.message, {
1402
+ extensions: {
1403
+ code: "COMPLEXITY_LIMIT_EXCEEDED",
1404
+ limitType: error.limitType,
1405
+ limit: error.limit,
1406
+ actual: error.actual
1407
+ }
1408
+ })
1409
+ );
1410
+ }
1411
+ return effect.Effect.logWarning("Complexity analysis failed for SSE subscription", error).pipe(
1412
+ effect.Effect.map(() => null)
1413
+ );
1414
+ })
1415
+ );
1416
+ if (complexityResult) {
1417
+ return effect.Stream.make(formatErrorEvent([complexityResult]), formatCompleteEvent());
1418
+ }
1419
+ }
1420
+ const ctx = {
1421
+ runtime,
1422
+ request,
1423
+ connectionContext
1424
+ };
1425
+ if (options?.onSubscribe) {
1426
+ yield* effect.Effect.provide(options.onSubscribe(ctx), layer).pipe(
1427
+ effect.Effect.catchAll(() => effect.Effect.void)
1428
+ );
1429
+ }
1430
+ const graphqlContext = {
1431
+ runtime,
1432
+ ...connectionContext
1433
+ };
1434
+ const subscriptionResult = yield* effect.Effect.tryPromise({
1435
+ try: () => graphql.subscribe({
1436
+ schema,
1437
+ document,
1438
+ variableValues: request.variables,
1439
+ operationName: request.operationName ?? void 0,
1440
+ contextValue: graphqlContext
1441
+ }),
1442
+ catch: (error) => new SSEError({ cause: error })
1443
+ });
1444
+ if (!isAsyncIterable(subscriptionResult)) {
1445
+ const result = subscriptionResult;
1446
+ if (result.errors) {
1447
+ return effect.Stream.make(formatErrorEvent(result.errors), formatCompleteEvent());
1448
+ }
1449
+ return effect.Stream.make(formatNextEvent(result), formatCompleteEvent());
1450
+ }
1451
+ const asyncIterator = subscriptionResult[Symbol.asyncIterator]();
1452
+ const eventStream = effect.Stream.async((emit) => {
1453
+ let done = false;
1454
+ const iterate = async () => {
1455
+ try {
1456
+ while (!done) {
1457
+ const result = await asyncIterator.next();
1458
+ if (result.done) {
1459
+ emit.end();
1460
+ break;
1461
+ }
1462
+ emit.single(formatNextEvent(result.value));
1463
+ }
1464
+ } catch (error) {
1465
+ if (!done) {
1466
+ emit.single(
1467
+ formatErrorEvent([
1468
+ error instanceof graphql.GraphQLError ? error : new graphql.GraphQLError(
1469
+ error instanceof Error ? error.message : "Subscription error",
1470
+ { extensions: { code: "SUBSCRIPTION_ERROR" } }
1471
+ )
1472
+ ])
1473
+ );
1474
+ emit.end();
1475
+ }
1476
+ }
1477
+ };
1478
+ iterate();
1479
+ return effect.Effect.sync(() => {
1480
+ done = true;
1481
+ asyncIterator.return?.();
1482
+ });
1483
+ });
1484
+ return eventStream.pipe(
1485
+ effect.Stream.onDone(
1486
+ () => effect.Effect.gen(function* () {
1487
+ yield* effect.Effect.sync(() => {
1488
+ });
1489
+ }).pipe(effect.Effect.asVoid)
1490
+ ),
1491
+ effect.Stream.concat(effect.Stream.make(formatCompleteEvent())),
1492
+ effect.Stream.onDone(() => {
1493
+ if (options?.onComplete) {
1494
+ return effect.Effect.provide(options.onComplete(ctx), layer).pipe(
1495
+ effect.Effect.catchAll(() => effect.Effect.void)
1496
+ );
1497
+ }
1498
+ return effect.Effect.void;
1499
+ })
1500
+ );
1501
+ }).pipe(
1502
+ effect.Effect.catchAll(
1503
+ (error) => effect.Effect.succeed(
1504
+ effect.Stream.make(
1505
+ formatErrorEvent([
1506
+ new graphql.GraphQLError(error instanceof Error ? error.message : "Internal error", {
1507
+ extensions: { code: "INTERNAL_ERROR" }
1508
+ })
1509
+ ]),
1510
+ formatCompleteEvent()
1511
+ )
1512
+ )
1513
+ )
1514
+ )
1515
+ );
1516
+ };
1517
+ var makeGraphQLSSEHandler = (schema, layer, options) => {
1518
+ return (request, headers) => makeSSESubscriptionStream(schema, layer, request, headers, options);
1519
+ };
1520
+ function isAsyncIterable(value) {
1521
+ return typeof value === "object" && value !== null && Symbol.asyncIterator in value;
1522
+ }
1523
+
1524
+ exports.CacheControlConfigFromEnv = CacheControlConfigFromEnv;
1525
+ exports.ComplexityAnalysisError = ComplexityAnalysisError;
1526
+ exports.ComplexityConfigFromEnv = ComplexityConfigFromEnv;
1527
+ exports.ComplexityLimitExceededError = ComplexityLimitExceededError;
1528
+ exports.GraphQLRouterConfigFromEnv = GraphQLRouterConfigFromEnv;
1529
+ exports.SSEError = SSEError;
1530
+ exports.SSE_HEADERS = SSE_HEADERS;
1531
+ exports.WS_CLOSED = WS_CLOSED;
1532
+ exports.WebSocketError = WebSocketError;
1533
+ exports.combineCalculators = combineCalculators;
1534
+ exports.computeCachePolicy = computeCachePolicy;
1535
+ exports.computeCachePolicyFromQuery = computeCachePolicyFromQuery;
1536
+ exports.defaultComplexityCalculator = defaultComplexityCalculator;
1537
+ exports.defaultConfig = defaultConfig;
1538
+ exports.defaultErrorHandler = defaultErrorHandler;
1539
+ exports.depthOnlyCalculator = depthOnlyCalculator;
1540
+ exports.formatCompleteEvent = formatCompleteEvent;
1541
+ exports.formatErrorEvent = formatErrorEvent;
1542
+ exports.formatNextEvent = formatNextEvent;
1543
+ exports.formatSSEMessage = formatSSEMessage;
1544
+ exports.graphiqlHtml = graphiqlHtml;
1545
+ exports.makeGraphQLRouter = makeGraphQLRouter;
1546
+ exports.makeGraphQLSSEHandler = makeGraphQLSSEHandler;
1547
+ exports.makeGraphQLWSHandler = makeGraphQLWSHandler;
1548
+ exports.makeSSESubscriptionStream = makeSSESubscriptionStream;
1549
+ exports.normalizeConfig = normalizeConfig;
1550
+ exports.toCacheControlHeader = toCacheControlHeader;
1551
+ exports.toEffectWebSocketFromWs = toEffectWebSocketFromWs;
1552
+ exports.toRouter = toRouter;
1553
+ exports.validateComplexity = validateComplexity;
1554
+ //# sourceMappingURL=index.cjs.map
1555
+ //# sourceMappingURL=index.cjs.map