@effect-gql/core 1.1.0 → 1.1.1
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 +27 -1
- package/index.cjs +34 -17
- package/index.cjs.map +1 -1
- package/index.js +34 -17
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/server/index.cjs +34 -17
- package/server/index.cjs.map +1 -1
- package/server/index.js +36 -19
- package/server/index.js.map +1 -1
package/index.js
CHANGED
|
@@ -5,7 +5,6 @@ import * as S2 from 'effect/Schema';
|
|
|
5
5
|
import * as AST from 'effect/SchemaAST';
|
|
6
6
|
import DataLoader from 'dataloader';
|
|
7
7
|
import { HttpIncomingMessage, HttpServerResponse, HttpServerRequest, HttpRouter } from '@effect/platform';
|
|
8
|
-
import { makeServer } from 'graphql-ws';
|
|
9
8
|
|
|
10
9
|
// src/builder/index.ts
|
|
11
10
|
var isIntegerType = (ast) => {
|
|
@@ -2871,27 +2870,45 @@ var runConnectionLifecycle = (socket, wsServer, extra) => Effect.gen(function* (
|
|
|
2871
2870
|
Effect.catchAllCause(() => Effect.void),
|
|
2872
2871
|
Effect.scoped
|
|
2873
2872
|
);
|
|
2873
|
+
var importGraphqlWs = Effect.tryPromise({
|
|
2874
|
+
try: () => import('graphql-ws'),
|
|
2875
|
+
catch: () => new Error(
|
|
2876
|
+
"graphql-ws is required for WebSocket subscriptions. Install it with: npm install graphql-ws"
|
|
2877
|
+
)
|
|
2878
|
+
});
|
|
2874
2879
|
var makeGraphQLWSHandler = (schema, layer, options) => {
|
|
2875
2880
|
const complexityConfig = options?.complexity;
|
|
2876
2881
|
const fieldComplexities = options?.fieldComplexities ?? /* @__PURE__ */ new Map();
|
|
2877
|
-
|
|
2878
|
-
|
|
2879
|
-
|
|
2880
|
-
|
|
2881
|
-
|
|
2882
|
-
|
|
2883
|
-
|
|
2884
|
-
|
|
2885
|
-
|
|
2886
|
-
|
|
2887
|
-
|
|
2888
|
-
|
|
2889
|
-
|
|
2890
|
-
|
|
2891
|
-
|
|
2882
|
+
let wsServerPromise = null;
|
|
2883
|
+
const getOrCreateServer = async () => {
|
|
2884
|
+
if (!wsServerPromise) {
|
|
2885
|
+
wsServerPromise = Effect.runPromise(importGraphqlWs).then(({ makeServer }) => {
|
|
2886
|
+
const serverOptions = {
|
|
2887
|
+
schema,
|
|
2888
|
+
context: async (ctx) => {
|
|
2889
|
+
const extra = ctx.extra;
|
|
2890
|
+
return {
|
|
2891
|
+
runtime: extra.runtime,
|
|
2892
|
+
...extra.connectionParams
|
|
2893
|
+
};
|
|
2894
|
+
},
|
|
2895
|
+
subscribe: async (args) => subscribe(args),
|
|
2896
|
+
onConnect: makeOnConnectHandler(options),
|
|
2897
|
+
onDisconnect: makeOnDisconnectHandler(options),
|
|
2898
|
+
onSubscribe: makeOnSubscribeHandler(options, schema, complexityConfig, fieldComplexities),
|
|
2899
|
+
onComplete: makeOnCompleteHandler(options),
|
|
2900
|
+
onError: makeOnErrorHandler(options)
|
|
2901
|
+
};
|
|
2902
|
+
return makeServer(serverOptions);
|
|
2903
|
+
});
|
|
2904
|
+
}
|
|
2905
|
+
return wsServerPromise;
|
|
2892
2906
|
};
|
|
2893
|
-
const wsServer = makeServer(serverOptions);
|
|
2894
2907
|
return (socket) => Effect.gen(function* () {
|
|
2908
|
+
const wsServer = yield* Effect.tryPromise({
|
|
2909
|
+
try: () => getOrCreateServer(),
|
|
2910
|
+
catch: (error) => error
|
|
2911
|
+
});
|
|
2895
2912
|
const runtime = yield* Effect.provide(Effect.runtime(), layer);
|
|
2896
2913
|
const extra = {
|
|
2897
2914
|
socket,
|