@effect-gql/node 0.1.0 → 1.1.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.
- package/README.md +100 -0
- package/index.cjs +315 -0
- package/index.cjs.map +1 -0
- package/index.d.cts +270 -0
- package/index.d.ts +270 -0
- package/index.js +310 -0
- package/index.js.map +1 -0
- package/package.json +14 -31
- package/dist/config.d.ts +0 -43
- package/dist/config.d.ts.map +0 -1
- package/dist/config.js +0 -52
- package/dist/config.js.map +0 -1
- package/dist/graphiql.d.ts +0 -5
- package/dist/graphiql.d.ts.map +0 -1
- package/dist/graphiql.js +0 -43
- package/dist/graphiql.js.map +0 -1
- package/dist/http-utils.d.ts +0 -20
- package/dist/http-utils.d.ts.map +0 -1
- package/dist/http-utils.js +0 -36
- package/dist/http-utils.js.map +0 -1
- package/dist/index.d.ts +0 -5
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -18
- package/dist/index.js.map +0 -1
- package/dist/router.d.ts +0 -32
- package/dist/router.d.ts.map +0 -1
- package/dist/router.js +0 -77
- package/dist/router.js.map +0 -1
- package/dist/schema-builder-extensions.d.ts +0 -31
- package/dist/schema-builder-extensions.d.ts.map +0 -1
- package/dist/schema-builder-extensions.js +0 -35
- package/dist/schema-builder-extensions.js.map +0 -1
- package/dist/serve.d.ts +0 -73
- package/dist/serve.d.ts.map +0 -1
- package/dist/serve.js +0 -176
- package/dist/serve.js.map +0 -1
- package/dist/sse.d.ts +0 -86
- package/dist/sse.d.ts.map +0 -1
- package/dist/sse.js +0 -175
- package/dist/sse.js.map +0 -1
- package/dist/ws.d.ts +0 -97
- package/dist/ws.d.ts.map +0 -1
- package/dist/ws.js +0 -137
- package/dist/ws.js.map +0 -1
- package/src/http-utils.ts +0 -32
- package/src/index.ts +0 -15
- package/src/serve.ts +0 -217
- package/src/sse.ts +0 -234
- package/src/ws.ts +0 -183
package/dist/http-utils.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.toWebHeaders = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Convert Node.js IncomingHttpHeaders to web standard Headers.
|
|
6
|
-
*
|
|
7
|
-
* This handles the difference between Node.js headers (which can be
|
|
8
|
-
* string | string[] | undefined) and web Headers (which are always strings).
|
|
9
|
-
*
|
|
10
|
-
* @param nodeHeaders - Headers from IncomingMessage.headers
|
|
11
|
-
* @returns A web standard Headers object
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* ```typescript
|
|
15
|
-
* import { toWebHeaders } from "@effect-gql/node"
|
|
16
|
-
*
|
|
17
|
-
* const webHeaders = toWebHeaders(req.headers)
|
|
18
|
-
* const auth = webHeaders.get("authorization")
|
|
19
|
-
* ```
|
|
20
|
-
*/
|
|
21
|
-
const toWebHeaders = (nodeHeaders) => {
|
|
22
|
-
const headers = new Headers();
|
|
23
|
-
for (const [key, value] of Object.entries(nodeHeaders)) {
|
|
24
|
-
if (value) {
|
|
25
|
-
if (Array.isArray(value)) {
|
|
26
|
-
value.forEach((v) => headers.append(key, v));
|
|
27
|
-
}
|
|
28
|
-
else {
|
|
29
|
-
headers.set(key, value);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
return headers;
|
|
34
|
-
};
|
|
35
|
-
exports.toWebHeaders = toWebHeaders;
|
|
36
|
-
//# sourceMappingURL=http-utils.js.map
|
package/dist/http-utils.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"http-utils.js","sourceRoot":"","sources":["../src/http-utils.ts"],"names":[],"mappings":";;;AAEA;;;;;;;;;;;;;;;;GAgBG;AACI,MAAM,YAAY,GAAG,CAAC,WAAgC,EAAW,EAAE;IACxE,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAA;IAC7B,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE,CAAC;QACvD,IAAI,KAAK,EAAE,CAAC;YACV,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;gBACzB,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAA;YAC9C,CAAC;iBAAM,CAAC;gBACN,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;YACzB,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO,OAAO,CAAA;AAChB,CAAC,CAAA;AAZY,QAAA,YAAY,gBAYxB"}
|
package/dist/index.d.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
export { serve, type ServeOptions } from "./serve";
|
|
2
|
-
export { toWebHeaders } from "./http-utils";
|
|
3
|
-
export { toEffectWebSocket, createGraphQLWSServer, attachWebSocketToServer, type NodeWSOptions, } from "./ws";
|
|
4
|
-
export { createSSEHandler, createSSEServer, type NodeSSEOptions } from "./sse";
|
|
5
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,KAAK,YAAY,EAAE,MAAM,SAAS,CAAA;AAGlD,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAG3C,OAAO,EACL,iBAAiB,EACjB,qBAAqB,EACrB,uBAAuB,EACvB,KAAK,aAAa,GACnB,MAAM,MAAM,CAAA;AAGb,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,KAAK,cAAc,EAAE,MAAM,OAAO,CAAA"}
|
package/dist/index.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createSSEServer = exports.createSSEHandler = exports.attachWebSocketToServer = exports.createGraphQLWSServer = exports.toEffectWebSocket = exports.toWebHeaders = exports.serve = void 0;
|
|
4
|
-
var serve_1 = require("./serve");
|
|
5
|
-
Object.defineProperty(exports, "serve", { enumerable: true, get: function () { return serve_1.serve; } });
|
|
6
|
-
// HTTP utilities
|
|
7
|
-
var http_utils_1 = require("./http-utils");
|
|
8
|
-
Object.defineProperty(exports, "toWebHeaders", { enumerable: true, get: function () { return http_utils_1.toWebHeaders; } });
|
|
9
|
-
// WebSocket subscription support
|
|
10
|
-
var ws_1 = require("./ws");
|
|
11
|
-
Object.defineProperty(exports, "toEffectWebSocket", { enumerable: true, get: function () { return ws_1.toEffectWebSocket; } });
|
|
12
|
-
Object.defineProperty(exports, "createGraphQLWSServer", { enumerable: true, get: function () { return ws_1.createGraphQLWSServer; } });
|
|
13
|
-
Object.defineProperty(exports, "attachWebSocketToServer", { enumerable: true, get: function () { return ws_1.attachWebSocketToServer; } });
|
|
14
|
-
// SSE (Server-Sent Events) subscription support
|
|
15
|
-
var sse_1 = require("./sse");
|
|
16
|
-
Object.defineProperty(exports, "createSSEHandler", { enumerable: true, get: function () { return sse_1.createSSEHandler; } });
|
|
17
|
-
Object.defineProperty(exports, "createSSEServer", { enumerable: true, get: function () { return sse_1.createSSEServer; } });
|
|
18
|
-
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,iCAAkD;AAAzC,8FAAA,KAAK,OAAA;AAEd,iBAAiB;AACjB,2CAA2C;AAAlC,0GAAA,YAAY,OAAA;AAErB,iCAAiC;AACjC,2BAKa;AAJX,uGAAA,iBAAiB,OAAA;AACjB,2GAAA,qBAAqB,OAAA;AACrB,6GAAA,uBAAuB,OAAA;AAIzB,gDAAgD;AAChD,6BAA8E;AAArE,uGAAA,gBAAgB,OAAA;AAAE,sGAAA,eAAe,OAAA"}
|
package/dist/router.d.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { HttpRouter } from "@effect/platform";
|
|
2
|
-
import { Layer } from "effect";
|
|
3
|
-
import { GraphQLSchema } from "graphql";
|
|
4
|
-
import { type GraphQLRouterConfigInput } from "./config";
|
|
5
|
-
/**
|
|
6
|
-
* Create an HttpRouter configured for GraphQL
|
|
7
|
-
*
|
|
8
|
-
* The router handles:
|
|
9
|
-
* - POST requests to the GraphQL endpoint
|
|
10
|
-
* - GET requests to the GraphiQL UI (if enabled)
|
|
11
|
-
*
|
|
12
|
-
* @param schema - The GraphQL schema
|
|
13
|
-
* @param layer - Effect layer providing services required by resolvers
|
|
14
|
-
* @param config - Optional configuration for paths and GraphiQL
|
|
15
|
-
* @returns An HttpRouter that can be composed with other routes
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
* ```typescript
|
|
19
|
-
* const router = makeGraphQLRouter(schema, Layer.empty, {
|
|
20
|
-
* path: "/graphql",
|
|
21
|
-
* graphiql: { path: "/graphiql" }
|
|
22
|
-
* })
|
|
23
|
-
*
|
|
24
|
-
* // Compose with other routes
|
|
25
|
-
* const app = HttpRouter.empty.pipe(
|
|
26
|
-
* HttpRouter.get("/health", HttpServerResponse.json({ status: "ok" })),
|
|
27
|
-
* HttpRouter.concat(router)
|
|
28
|
-
* )
|
|
29
|
-
* ```
|
|
30
|
-
*/
|
|
31
|
-
export declare const makeGraphQLRouter: <R>(schema: GraphQLSchema, layer: Layer.Layer<R>, config?: GraphQLRouterConfigInput) => HttpRouter.HttpRouter<never, never>;
|
|
32
|
-
//# sourceMappingURL=router.d.ts.map
|
package/dist/router.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../src/router.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAyC,MAAM,kBAAkB,CAAA;AACpF,OAAO,EAAU,KAAK,EAAE,MAAM,QAAQ,CAAA;AACtC,OAAO,EAAE,aAAa,EAAW,MAAM,SAAS,CAAA;AAGhD,OAAO,EAAmB,KAAK,wBAAwB,EAAE,MAAM,UAAU,CAAA;AAEzE;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,iBAAiB,GAAI,CAAC,EACjC,QAAQ,aAAa,EACrB,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,EACrB,SAAQ,wBAA6B,KACpC,UAAU,CAAC,UAAU,CAAC,KAAK,EAAE,KAAK,CAoEpC,CAAA"}
|
package/dist/router.js
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.makeGraphQLRouter = void 0;
|
|
4
|
-
const platform_1 = require("@effect/platform");
|
|
5
|
-
const effect_1 = require("effect");
|
|
6
|
-
const graphql_1 = require("graphql");
|
|
7
|
-
const graphiql_1 = require("./graphiql");
|
|
8
|
-
const config_1 = require("./config");
|
|
9
|
-
/**
|
|
10
|
-
* Create an HttpRouter configured for GraphQL
|
|
11
|
-
*
|
|
12
|
-
* The router handles:
|
|
13
|
-
* - POST requests to the GraphQL endpoint
|
|
14
|
-
* - GET requests to the GraphiQL UI (if enabled)
|
|
15
|
-
*
|
|
16
|
-
* @param schema - The GraphQL schema
|
|
17
|
-
* @param layer - Effect layer providing services required by resolvers
|
|
18
|
-
* @param config - Optional configuration for paths and GraphiQL
|
|
19
|
-
* @returns An HttpRouter that can be composed with other routes
|
|
20
|
-
*
|
|
21
|
-
* @example
|
|
22
|
-
* ```typescript
|
|
23
|
-
* const router = makeGraphQLRouter(schema, Layer.empty, {
|
|
24
|
-
* path: "/graphql",
|
|
25
|
-
* graphiql: { path: "/graphiql" }
|
|
26
|
-
* })
|
|
27
|
-
*
|
|
28
|
-
* // Compose with other routes
|
|
29
|
-
* const app = HttpRouter.empty.pipe(
|
|
30
|
-
* HttpRouter.get("/health", HttpServerResponse.json({ status: "ok" })),
|
|
31
|
-
* HttpRouter.concat(router)
|
|
32
|
-
* )
|
|
33
|
-
* ```
|
|
34
|
-
*/
|
|
35
|
-
const makeGraphQLRouter = (schema, layer, config = {}) => {
|
|
36
|
-
const resolvedConfig = (0, config_1.normalizeConfig)(config);
|
|
37
|
-
// GraphQL POST handler
|
|
38
|
-
const graphqlHandler = effect_1.Effect.gen(function* () {
|
|
39
|
-
// Get the runtime from the layer
|
|
40
|
-
const runtime = yield* effect_1.Effect.runtime();
|
|
41
|
-
// Parse request body
|
|
42
|
-
const request = yield* platform_1.HttpServerRequest.HttpServerRequest;
|
|
43
|
-
const body = yield* request.json;
|
|
44
|
-
// Execute GraphQL query
|
|
45
|
-
const result = yield* effect_1.Effect.tryPromise({
|
|
46
|
-
try: () => (0, graphql_1.graphql)({
|
|
47
|
-
schema,
|
|
48
|
-
source: body.query,
|
|
49
|
-
variableValues: body.variables,
|
|
50
|
-
operationName: body.operationName,
|
|
51
|
-
contextValue: { runtime },
|
|
52
|
-
}),
|
|
53
|
-
catch: (error) => new Error(String(error)),
|
|
54
|
-
});
|
|
55
|
-
return yield* platform_1.HttpServerResponse.json(result);
|
|
56
|
-
}).pipe(effect_1.Effect.provide(layer), effect_1.Effect.catchAllCause((cause) => platform_1.HttpServerResponse.json({
|
|
57
|
-
errors: [
|
|
58
|
-
{
|
|
59
|
-
message: cause._tag === "Fail"
|
|
60
|
-
? cause.error instanceof Error
|
|
61
|
-
? cause.error.message
|
|
62
|
-
: String(cause.error)
|
|
63
|
-
: "Internal server error",
|
|
64
|
-
},
|
|
65
|
-
],
|
|
66
|
-
}, { status: 400 }).pipe(effect_1.Effect.orDie)));
|
|
67
|
-
// Build router with GraphQL endpoint
|
|
68
|
-
let router = platform_1.HttpRouter.empty.pipe(platform_1.HttpRouter.post(resolvedConfig.path, graphqlHandler));
|
|
69
|
-
// Add GraphiQL route if enabled
|
|
70
|
-
if (resolvedConfig.graphiql) {
|
|
71
|
-
const { path, endpoint } = resolvedConfig.graphiql;
|
|
72
|
-
router = router.pipe(platform_1.HttpRouter.get(path, platform_1.HttpServerResponse.html((0, graphiql_1.graphiqlHtml)(endpoint))));
|
|
73
|
-
}
|
|
74
|
-
return router;
|
|
75
|
-
};
|
|
76
|
-
exports.makeGraphQLRouter = makeGraphQLRouter;
|
|
77
|
-
//# sourceMappingURL=router.js.map
|
package/dist/router.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"router.js","sourceRoot":"","sources":["../src/router.ts"],"names":[],"mappings":";;;AAAA,+CAAoF;AACpF,mCAAsC;AACtC,qCAAgD;AAEhD,yCAAyC;AACzC,qCAAyE;AAEzE;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACI,MAAM,iBAAiB,GAAG,CAC/B,MAAqB,EACrB,KAAqB,EACrB,SAAmC,EAAE,EACA,EAAE;IACvC,MAAM,cAAc,GAAG,IAAA,wBAAe,EAAC,MAAM,CAAC,CAAA;IAE9C,uBAAuB;IACvB,MAAM,cAAc,GAAG,eAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;QACzC,iCAAiC;QACjC,MAAM,OAAO,GAAG,KAAK,CAAC,CAAC,eAAM,CAAC,OAAO,EAAK,CAAA;QAE1C,qBAAqB;QACrB,MAAM,OAAO,GAAG,KAAK,CAAC,CAAC,4BAAiB,CAAC,iBAAiB,CAAA;QAC1D,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,OAAO,CAAC,IAI1B,CAAA;QAEF,wBAAwB;QACxB,MAAM,MAAM,GAAG,KAAK,CAAC,CAAC,eAAM,CAAC,UAAU,CAAC;YACtC,GAAG,EAAE,GAAG,EAAE,CACR,IAAA,iBAAO,EAAC;gBACN,MAAM;gBACN,MAAM,EAAE,IAAI,CAAC,KAAK;gBAClB,cAAc,EAAE,IAAI,CAAC,SAAS;gBAC9B,aAAa,EAAE,IAAI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H,CAAC;IAED,OAAO,MAAM,CAAA;AACf,CAAC,CAAA;AAxEY,QAAA,iBAAiB,qBAwE7B"}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { Layer } from "effect";
|
|
2
|
-
import { HttpRouter } from "@effect/platform";
|
|
3
|
-
import { GraphQLSchemaBuilder } from "@effect-gql/core";
|
|
4
|
-
import type { GraphQLRouterConfigInput } from "./config";
|
|
5
|
-
/**
|
|
6
|
-
* Convert a GraphQLSchemaBuilder to an HttpRouter.
|
|
7
|
-
*
|
|
8
|
-
* This is the Node.js server integration that bridges the core
|
|
9
|
-
* GraphQL schema with the @effect/platform HTTP server.
|
|
10
|
-
*
|
|
11
|
-
* @param builder - The GraphQL schema builder
|
|
12
|
-
* @param layer - Effect layer providing services required by resolvers
|
|
13
|
-
* @param config - Optional configuration for paths and GraphiQL
|
|
14
|
-
* @returns An HttpRouter that can be composed with other routes
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* ```typescript
|
|
18
|
-
* import { GraphQLSchemaBuilder, query } from "@effect-gql/core"
|
|
19
|
-
* import { toRouter } from "@effect-gql/node"
|
|
20
|
-
* import { Layer } from "effect"
|
|
21
|
-
* import * as S from "effect/Schema"
|
|
22
|
-
*
|
|
23
|
-
* const builder = GraphQLSchemaBuilder.empty.pipe(
|
|
24
|
-
* query("hello", { type: S.String, resolve: () => Effect.succeed("world") })
|
|
25
|
-
* )
|
|
26
|
-
*
|
|
27
|
-
* const router = toRouter(builder, Layer.empty, { graphiql: true })
|
|
28
|
-
* ```
|
|
29
|
-
*/
|
|
30
|
-
export declare const toRouter: <R, R2>(builder: GraphQLSchemaBuilder<R>, layer: Layer.Layer<R2>, config?: GraphQLRouterConfigInput) => HttpRouter.HttpRouter<never, never>;
|
|
31
|
-
//# sourceMappingURL=schema-builder-extensions.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"schema-builder-extensions.d.ts","sourceRoot":"","sources":["../src/schema-builder-extensions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAA;AAC9B,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAA;AAE3D,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,UAAU,CAAA;AAExD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,eAAO,MAAM,QAAQ,GAAI,CAAC,EAAE,EAAE,EAC5B,SAAS,oBAAoB,CAAC,CAAC,CAAC,EAChC,OAAO,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,EACtB,SAAS,wBAAwB,KAChC,UAAU,CAAC,UAAU,CAAC,KAAK,EAAE,KAAK,CAGpC,CAAA"}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.toRouter = void 0;
|
|
4
|
-
const router_1 = require("./router");
|
|
5
|
-
/**
|
|
6
|
-
* Convert a GraphQLSchemaBuilder to an HttpRouter.
|
|
7
|
-
*
|
|
8
|
-
* This is the Node.js server integration that bridges the core
|
|
9
|
-
* GraphQL schema with the @effect/platform HTTP server.
|
|
10
|
-
*
|
|
11
|
-
* @param builder - The GraphQL schema builder
|
|
12
|
-
* @param layer - Effect layer providing services required by resolvers
|
|
13
|
-
* @param config - Optional configuration for paths and GraphiQL
|
|
14
|
-
* @returns An HttpRouter that can be composed with other routes
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* ```typescript
|
|
18
|
-
* import { GraphQLSchemaBuilder, query } from "@effect-graphql/core"
|
|
19
|
-
* import { toRouter } from "@effect-graphql/node"
|
|
20
|
-
* import { Layer } from "effect"
|
|
21
|
-
* import * as S from "effect/Schema"
|
|
22
|
-
*
|
|
23
|
-
* const builder = GraphQLSchemaBuilder.empty.pipe(
|
|
24
|
-
* query("hello", { type: S.String, resolve: () => Effect.succeed("world") })
|
|
25
|
-
* )
|
|
26
|
-
*
|
|
27
|
-
* const router = toRouter(builder, Layer.empty, { graphiql: true })
|
|
28
|
-
* ```
|
|
29
|
-
*/
|
|
30
|
-
const toRouter = (builder, layer, config) => {
|
|
31
|
-
const schema = builder.buildSchema();
|
|
32
|
-
return (0, router_1.makeGraphQLRouter)(schema, layer, config);
|
|
33
|
-
};
|
|
34
|
-
exports.toRouter = toRouter;
|
|
35
|
-
//# sourceMappingURL=schema-builder-extensions.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"schema-builder-extensions.js","sourceRoot":"","sources":["../src/schema-builder-extensions.ts"],"names":[],"mappings":";;;AAGA,qCAA4C;AAG5C;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACI,MAAM,QAAQ,GAAG,CACtB,OAAgC,EAChC,KAAsB,EACtB,MAAiC,EACI,EAAE;IACvC,MAAM,MAAM,GAAG,OAAO,CAAC,WAAW,EAAE,CAAA;IACpC,OAAO,IAAA,0BAAiB,EAAC,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,CAAA;AACjD,CAAC,CAAA;AAPY,QAAA,QAAQ,YAOpB"}
|
package/dist/serve.d.ts
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { Layer } from "effect";
|
|
2
|
-
import { HttpRouter } from "@effect/platform";
|
|
3
|
-
import type { GraphQLSchema } from "graphql";
|
|
4
|
-
import type { GraphQLWSOptions } from "@effect-gql/core";
|
|
5
|
-
/**
|
|
6
|
-
* Configuration for WebSocket subscriptions
|
|
7
|
-
*/
|
|
8
|
-
export interface SubscriptionsConfig<R> extends GraphQLWSOptions<R> {
|
|
9
|
-
/**
|
|
10
|
-
* The GraphQL schema (required for subscriptions).
|
|
11
|
-
* Must be the same schema used to create the router.
|
|
12
|
-
*/
|
|
13
|
-
readonly schema: GraphQLSchema;
|
|
14
|
-
/**
|
|
15
|
-
* Path for WebSocket connections.
|
|
16
|
-
* @default "/graphql"
|
|
17
|
-
*/
|
|
18
|
-
readonly path?: string;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Options for the Node.js GraphQL server
|
|
22
|
-
*/
|
|
23
|
-
export interface ServeOptions<R = never> {
|
|
24
|
-
/** Port to listen on (default: 4000) */
|
|
25
|
-
readonly port?: number;
|
|
26
|
-
/** Hostname to bind to (default: "0.0.0.0") */
|
|
27
|
-
readonly host?: string;
|
|
28
|
-
/** Callback when server starts */
|
|
29
|
-
readonly onStart?: (url: string) => void;
|
|
30
|
-
/**
|
|
31
|
-
* Enable WebSocket subscriptions.
|
|
32
|
-
* When provided, the server will handle WebSocket upgrade requests
|
|
33
|
-
* for GraphQL subscriptions using the graphql-ws protocol.
|
|
34
|
-
*/
|
|
35
|
-
readonly subscriptions?: SubscriptionsConfig<R>;
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Start a Node.js HTTP server with the given router.
|
|
39
|
-
*
|
|
40
|
-
* This is the main entry point for running a GraphQL server on Node.js.
|
|
41
|
-
* It handles all the Effect runtime setup and server lifecycle.
|
|
42
|
-
*
|
|
43
|
-
* @param router - The HttpRouter to serve (typically from makeGraphQLRouter or toRouter)
|
|
44
|
-
* @param layer - Layer providing the router's service dependencies
|
|
45
|
-
* @param options - Server configuration options
|
|
46
|
-
*
|
|
47
|
-
* @example
|
|
48
|
-
* ```typescript
|
|
49
|
-
* import { makeGraphQLRouter } from "@effect-gql/core"
|
|
50
|
-
* import { serve } from "@effect-gql/node"
|
|
51
|
-
*
|
|
52
|
-
* const schema = GraphQLSchemaBuilder.empty
|
|
53
|
-
* .query("hello", { type: S.String, resolve: () => Effect.succeed("world") })
|
|
54
|
-
* .buildSchema()
|
|
55
|
-
*
|
|
56
|
-
* const router = makeGraphQLRouter(schema, Layer.empty, { graphiql: true })
|
|
57
|
-
*
|
|
58
|
-
* // Without subscriptions
|
|
59
|
-
* serve(router, serviceLayer, {
|
|
60
|
-
* port: 4000,
|
|
61
|
-
* onStart: (url) => console.log(`Server running at ${url}`)
|
|
62
|
-
* })
|
|
63
|
-
*
|
|
64
|
-
* // With subscriptions
|
|
65
|
-
* serve(router, serviceLayer, {
|
|
66
|
-
* port: 4000,
|
|
67
|
-
* subscriptions: { schema },
|
|
68
|
-
* onStart: (url) => console.log(`Server running at ${url}`)
|
|
69
|
-
* })
|
|
70
|
-
* ```
|
|
71
|
-
*/
|
|
72
|
-
export declare const serve: <E, R, RE>(router: HttpRouter.HttpRouter<E, R>, layer: Layer.Layer<R, RE>, options?: ServeOptions<R>) => void;
|
|
73
|
-
//# sourceMappingURL=serve.d.ts.map
|
package/dist/serve.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"serve.d.ts","sourceRoot":"","sources":["../src/serve.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,EAAE,MAAM,QAAQ,CAAA;AACtC,OAAO,EAAW,UAAU,EAAc,MAAM,kBAAkB,CAAA;AAGlE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAC5C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AAGxD;;GAEG;AACH,MAAM,WAAW,mBAAmB,CAAC,CAAC,CAAE,SAAQ,gBAAgB,CAAC,CAAC,CAAC;IACjE;;;OAGG;IACH,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAA;IAC9B;;;OAGG;IACH,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY,CAAC,CAAC,GAAG,KAAK;IACrC,wCAAwC;IACxC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAA;IACtB,+CAA+C;IAC/C,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAA;IACtB,kCAAkC;IAClC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAA;IACxC;;;;OAIG;IACH,QAAQ,CAAC,aAAa,CAAC,EAAE,mBAAmB,CAAC,CAAC,CAAC,CAAA;CAChD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,eAAO,MAAM,KAAK,GAAI,CAAC,EAAE,CAAC,EAAE,EAAE,EAC5B,QAAQ,UAAU,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,EACnC,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,EACzB,UAAS,YAAY,CAAC,CAAC,CAAM,KAC5B,IAsBF,CAAA"}
|
package/dist/serve.js
DELETED
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.serve = void 0;
|
|
37
|
-
const effect_1 = require("effect");
|
|
38
|
-
const platform_1 = require("@effect/platform");
|
|
39
|
-
const platform_node_1 = require("@effect/platform-node");
|
|
40
|
-
const node_http_1 = require("node:http");
|
|
41
|
-
const http_utils_1 = require("./http-utils");
|
|
42
|
-
/**
|
|
43
|
-
* Start a Node.js HTTP server with the given router.
|
|
44
|
-
*
|
|
45
|
-
* This is the main entry point for running a GraphQL server on Node.js.
|
|
46
|
-
* It handles all the Effect runtime setup and server lifecycle.
|
|
47
|
-
*
|
|
48
|
-
* @param router - The HttpRouter to serve (typically from makeGraphQLRouter or toRouter)
|
|
49
|
-
* @param layer - Layer providing the router's service dependencies
|
|
50
|
-
* @param options - Server configuration options
|
|
51
|
-
*
|
|
52
|
-
* @example
|
|
53
|
-
* ```typescript
|
|
54
|
-
* import { makeGraphQLRouter } from "@effect-gql/core"
|
|
55
|
-
* import { serve } from "@effect-gql/node"
|
|
56
|
-
*
|
|
57
|
-
* const schema = GraphQLSchemaBuilder.empty
|
|
58
|
-
* .query("hello", { type: S.String, resolve: () => Effect.succeed("world") })
|
|
59
|
-
* .buildSchema()
|
|
60
|
-
*
|
|
61
|
-
* const router = makeGraphQLRouter(schema, Layer.empty, { graphiql: true })
|
|
62
|
-
*
|
|
63
|
-
* // Without subscriptions
|
|
64
|
-
* serve(router, serviceLayer, {
|
|
65
|
-
* port: 4000,
|
|
66
|
-
* onStart: (url) => console.log(`Server running at ${url}`)
|
|
67
|
-
* })
|
|
68
|
-
*
|
|
69
|
-
* // With subscriptions
|
|
70
|
-
* serve(router, serviceLayer, {
|
|
71
|
-
* port: 4000,
|
|
72
|
-
* subscriptions: { schema },
|
|
73
|
-
* onStart: (url) => console.log(`Server running at ${url}`)
|
|
74
|
-
* })
|
|
75
|
-
* ```
|
|
76
|
-
*/
|
|
77
|
-
const serve = (router, layer, options = {}) => {
|
|
78
|
-
const { port = 4000, host = "0.0.0.0", onStart, subscriptions } = options;
|
|
79
|
-
if (subscriptions) {
|
|
80
|
-
// With WebSocket subscriptions - we need to manage the HTTP server ourselves
|
|
81
|
-
serveWithSubscriptions(router, layer, port, host, subscriptions, onStart);
|
|
82
|
-
}
|
|
83
|
-
else {
|
|
84
|
-
// Without subscriptions - use the standard Effect approach
|
|
85
|
-
const app = router.pipe(effect_1.Effect.catchAllCause((cause) => effect_1.Effect.die(cause)), platform_1.HttpServer.serve());
|
|
86
|
-
const serverLayer = platform_node_1.NodeHttpServer.layer(() => (0, node_http_1.createServer)(), { port });
|
|
87
|
-
const fullLayer = effect_1.Layer.merge(serverLayer, layer);
|
|
88
|
-
if (onStart) {
|
|
89
|
-
onStart(`http://${host === "0.0.0.0" ? "localhost" : host}:${port}`);
|
|
90
|
-
}
|
|
91
|
-
platform_node_1.NodeRuntime.runMain(effect_1.Layer.launch(effect_1.Layer.provide(app, fullLayer)));
|
|
92
|
-
}
|
|
93
|
-
};
|
|
94
|
-
exports.serve = serve;
|
|
95
|
-
/**
|
|
96
|
-
* Internal implementation for serving with WebSocket subscriptions.
|
|
97
|
-
* Uses a custom HTTP server setup to enable WebSocket upgrade handling.
|
|
98
|
-
*/
|
|
99
|
-
function serveWithSubscriptions(router, layer, port, host, subscriptions, onStart) {
|
|
100
|
-
// Dynamically import ws module to keep it optional
|
|
101
|
-
const importWs = effect_1.Effect.tryPromise({
|
|
102
|
-
try: () => Promise.resolve().then(() => __importStar(require("./ws"))),
|
|
103
|
-
catch: (error) => error,
|
|
104
|
-
});
|
|
105
|
-
effect_1.Effect.runPromise(importWs.pipe(effect_1.Effect.catchAll((error) => effect_1.Effect.logError("Failed to load WebSocket support", error).pipe(effect_1.Effect.andThen(effect_1.Effect.logError("Make sure 'ws' package is installed: npm install ws")), effect_1.Effect.andThen(effect_1.Effect.sync(() => process.exit(1))), effect_1.Effect.andThen(effect_1.Effect.fail(error)))))).then(({ createGraphQLWSServer }) => {
|
|
106
|
-
// Create the web handler from the Effect router
|
|
107
|
-
const { handler } = platform_1.HttpApp.toWebHandlerLayer(router, layer);
|
|
108
|
-
// Create the HTTP server
|
|
109
|
-
const httpServer = (0, node_http_1.createServer)(async (req, res) => {
|
|
110
|
-
try {
|
|
111
|
-
// Collect request body
|
|
112
|
-
const chunks = [];
|
|
113
|
-
for await (const chunk of req) {
|
|
114
|
-
chunks.push(chunk);
|
|
115
|
-
}
|
|
116
|
-
const body = Buffer.concat(chunks).toString();
|
|
117
|
-
// Convert Node.js request to web standard Request
|
|
118
|
-
// Use URL constructor for safe URL parsing (avoids injection via req.url)
|
|
119
|
-
const baseUrl = `http://${host === "0.0.0.0" ? "localhost" : host}:${port}`;
|
|
120
|
-
const url = new URL(req.url || "/", baseUrl).href;
|
|
121
|
-
const headers = (0, http_utils_1.toWebHeaders)(req.headers);
|
|
122
|
-
const webRequest = new Request(url, {
|
|
123
|
-
method: req.method,
|
|
124
|
-
headers,
|
|
125
|
-
body: ["GET", "HEAD"].includes(req.method) ? undefined : body,
|
|
126
|
-
});
|
|
127
|
-
// Process through Effect handler
|
|
128
|
-
const webResponse = await handler(webRequest);
|
|
129
|
-
// Write response
|
|
130
|
-
res.statusCode = webResponse.status;
|
|
131
|
-
webResponse.headers.forEach((value, key) => {
|
|
132
|
-
res.setHeader(key, value);
|
|
133
|
-
});
|
|
134
|
-
const responseBody = await webResponse.text();
|
|
135
|
-
res.end(responseBody);
|
|
136
|
-
}
|
|
137
|
-
catch (error) {
|
|
138
|
-
res.statusCode = 500;
|
|
139
|
-
res.end(JSON.stringify({ error: String(error) }));
|
|
140
|
-
}
|
|
141
|
-
});
|
|
142
|
-
// Create WebSocket server for subscriptions
|
|
143
|
-
const { handleUpgrade, close: closeWS } = createGraphQLWSServer(subscriptions.schema, layer, {
|
|
144
|
-
path: subscriptions.path,
|
|
145
|
-
complexity: subscriptions.complexity,
|
|
146
|
-
fieldComplexities: subscriptions.fieldComplexities,
|
|
147
|
-
onConnect: subscriptions.onConnect,
|
|
148
|
-
onDisconnect: subscriptions.onDisconnect,
|
|
149
|
-
onSubscribe: subscriptions.onSubscribe,
|
|
150
|
-
onComplete: subscriptions.onComplete,
|
|
151
|
-
onError: subscriptions.onError,
|
|
152
|
-
});
|
|
153
|
-
// Attach WebSocket upgrade handler
|
|
154
|
-
httpServer.on("upgrade", (request, socket, head) => {
|
|
155
|
-
handleUpgrade(request, socket, head);
|
|
156
|
-
});
|
|
157
|
-
// Handle shutdown
|
|
158
|
-
process.on("SIGINT", async () => {
|
|
159
|
-
await closeWS();
|
|
160
|
-
httpServer.close();
|
|
161
|
-
process.exit(0);
|
|
162
|
-
});
|
|
163
|
-
process.on("SIGTERM", async () => {
|
|
164
|
-
await closeWS();
|
|
165
|
-
httpServer.close();
|
|
166
|
-
process.exit(0);
|
|
167
|
-
});
|
|
168
|
-
// Start listening
|
|
169
|
-
httpServer.listen(port, host, () => {
|
|
170
|
-
if (onStart) {
|
|
171
|
-
onStart(`http://${host === "0.0.0.0" ? "localhost" : host}:${port}`);
|
|
172
|
-
}
|
|
173
|
-
});
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
//# sourceMappingURL=serve.js.map
|
package/dist/serve.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"serve.js","sourceRoot":"","sources":["../src/serve.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mCAAsC;AACtC,+CAAkE;AAClE,yDAAmE;AACnE,yCAAwC;AAGxC,6CAA2C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,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,IAAI,IAAI,EAAE,CAAC,CAAA;YACtE,CAAC;QACH,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC"}
|
package/dist/sse.d.ts
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { Layer } from "effect";
|
|
2
|
-
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
3
|
-
import { GraphQLSchema } from "graphql";
|
|
4
|
-
import { type GraphQLSSEOptions } from "@effect-gql/core";
|
|
5
|
-
/**
|
|
6
|
-
* Options for Node.js SSE handler
|
|
7
|
-
*/
|
|
8
|
-
export interface NodeSSEOptions<R> extends GraphQLSSEOptions<R> {
|
|
9
|
-
/**
|
|
10
|
-
* Path for SSE connections.
|
|
11
|
-
* @default "/graphql/stream"
|
|
12
|
-
*/
|
|
13
|
-
readonly path?: string;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Create an SSE handler for Node.js HTTP server.
|
|
17
|
-
*
|
|
18
|
-
* This function creates a handler that can process SSE subscription requests.
|
|
19
|
-
* It handles:
|
|
20
|
-
* - Parsing the GraphQL subscription request from the HTTP body
|
|
21
|
-
* - Setting up the SSE connection with proper headers
|
|
22
|
-
* - Streaming subscription events to the client
|
|
23
|
-
* - Detecting client disconnection and cleaning up
|
|
24
|
-
*
|
|
25
|
-
* @param schema - The GraphQL schema with subscription definitions
|
|
26
|
-
* @param layer - Effect layer providing services required by resolvers
|
|
27
|
-
* @param options - Optional lifecycle hooks and configuration
|
|
28
|
-
* @returns A request handler function
|
|
29
|
-
*
|
|
30
|
-
* @example
|
|
31
|
-
* ```typescript
|
|
32
|
-
* import { createServer } from "node:http"
|
|
33
|
-
* import { createSSEHandler } from "@effect-gql/node"
|
|
34
|
-
*
|
|
35
|
-
* const sseHandler = createSSEHandler(schema, serviceLayer, {
|
|
36
|
-
* path: "/graphql/stream",
|
|
37
|
-
* onConnect: (request, headers) => Effect.gen(function* () {
|
|
38
|
-
* const user = yield* AuthService.validateToken(headers.get("authorization"))
|
|
39
|
-
* return { user }
|
|
40
|
-
* }),
|
|
41
|
-
* })
|
|
42
|
-
*
|
|
43
|
-
* const server = createServer((req, res) => {
|
|
44
|
-
* const url = new URL(req.url, `http://${req.headers.host}`)
|
|
45
|
-
* if (url.pathname === "/graphql/stream" && req.method === "POST") {
|
|
46
|
-
* sseHandler(req, res)
|
|
47
|
-
* } else {
|
|
48
|
-
* // Handle other requests...
|
|
49
|
-
* }
|
|
50
|
-
* })
|
|
51
|
-
*
|
|
52
|
-
* server.listen(4000)
|
|
53
|
-
* ```
|
|
54
|
-
*/
|
|
55
|
-
export declare const createSSEHandler: <R>(schema: GraphQLSchema, layer: Layer.Layer<R>, options?: NodeSSEOptions<R>) => ((req: IncomingMessage, res: ServerResponse) => Promise<void>);
|
|
56
|
-
/**
|
|
57
|
-
* Create SSE middleware that can be used with the serve() function.
|
|
58
|
-
*
|
|
59
|
-
* This returns an object that can be used to integrate SSE subscriptions
|
|
60
|
-
* with the HTTP server when using the custom subscription mode.
|
|
61
|
-
*
|
|
62
|
-
* @param schema - The GraphQL schema with subscription definitions
|
|
63
|
-
* @param layer - Effect layer providing services required by resolvers
|
|
64
|
-
* @param options - Optional lifecycle hooks and configuration
|
|
65
|
-
*
|
|
66
|
-
* @example
|
|
67
|
-
* ```typescript
|
|
68
|
-
* // In serve.ts with custom HTTP server setup
|
|
69
|
-
* const sseServer = createSSEServer(schema, layer, { path: "/graphql/stream" })
|
|
70
|
-
*
|
|
71
|
-
* httpServer.on("request", (req, res) => {
|
|
72
|
-
* if (sseServer.shouldHandle(req)) {
|
|
73
|
-
* sseServer.handle(req, res)
|
|
74
|
-
* }
|
|
75
|
-
* })
|
|
76
|
-
* ```
|
|
77
|
-
*/
|
|
78
|
-
export declare const createSSEServer: <R>(schema: GraphQLSchema, layer: Layer.Layer<R>, options?: NodeSSEOptions<R>) => {
|
|
79
|
-
/** Path this SSE server handles */
|
|
80
|
-
readonly path: string;
|
|
81
|
-
/** Check if a request should be handled by this SSE server */
|
|
82
|
-
shouldHandle: (req: IncomingMessage) => boolean;
|
|
83
|
-
/** Handle an SSE request */
|
|
84
|
-
handle: (req: IncomingMessage, res: ServerResponse) => Promise<void>;
|
|
85
|
-
};
|
|
86
|
-
//# sourceMappingURL=sse.d.ts.map
|
package/dist/sse.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sse.d.ts","sourceRoot":"","sources":["../src/sse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,EAAoB,MAAM,QAAQ,CAAA;AACxD,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAChE,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AACvC,OAAO,EAIL,KAAK,iBAAiB,EAGvB,MAAM,kBAAkB,CAAA;AAGzB;;GAEG;AACH,MAAM,WAAW,cAAc,CAAC,CAAC,CAAE,SAAQ,iBAAiB,CAAC,CAAC,CAAC;IAC7D;;;OAGG;IACH,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CACvB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,eAAO,MAAM,gBAAgB,GAAI,CAAC,EAChC,QAAQ,aAAa,EACrB,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,EACrB,UAAU,cAAc,CAAC,CAAC,CAAC,KAC1B,CAAC,CAAC,GAAG,EAAE,eAAe,EAAE,GAAG,EAAE,cAAc,KAAK,OAAO,CAAC,IAAI,CAAC,CAyG/D,CAAA;AAcD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,eAAe,GAAI,CAAC,EAC/B,QAAQ,aAAa,EACrB,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,EACrB,UAAU,cAAc,CAAC,CAAC,CAAC,KAC1B;IACD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