@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@effect-gql/core",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "Core GraphQL framework for Effect-TS - schema building, type mapping, and execution",
5
5
  "repository": {
6
6
  "url": "https://github.com/nrf110/effect-gql"
package/server/index.cjs CHANGED
@@ -3,7 +3,6 @@
3
3
  var effect = require('effect');
4
4
  var platform = require('@effect/platform');
5
5
  var graphql = require('graphql');
6
- var graphqlWs = require('graphql-ws');
7
6
 
8
7
  // src/server/config.ts
9
8
  var defaultConfig = {
@@ -1228,27 +1227,45 @@ var runConnectionLifecycle = (socket, wsServer, extra) => effect.Effect.gen(func
1228
1227
  effect.Effect.catchAllCause(() => effect.Effect.void),
1229
1228
  effect.Effect.scoped
1230
1229
  );
1230
+ var importGraphqlWs = effect.Effect.tryPromise({
1231
+ try: () => import('graphql-ws'),
1232
+ catch: () => new Error(
1233
+ "graphql-ws is required for WebSocket subscriptions. Install it with: npm install graphql-ws"
1234
+ )
1235
+ });
1231
1236
  var makeGraphQLWSHandler = (schema, layer, options) => {
1232
1237
  const complexityConfig = options?.complexity;
1233
1238
  const fieldComplexities = options?.fieldComplexities ?? /* @__PURE__ */ new Map();
1234
- const serverOptions = {
1235
- schema,
1236
- context: async (ctx) => {
1237
- const extra = ctx.extra;
1238
- return {
1239
- runtime: extra.runtime,
1240
- ...extra.connectionParams
1241
- };
1242
- },
1243
- subscribe: async (args) => graphql.subscribe(args),
1244
- onConnect: makeOnConnectHandler(options),
1245
- onDisconnect: makeOnDisconnectHandler(options),
1246
- onSubscribe: makeOnSubscribeHandler(options, schema, complexityConfig, fieldComplexities),
1247
- onComplete: makeOnCompleteHandler(options),
1248
- onError: makeOnErrorHandler(options)
1239
+ let wsServerPromise = null;
1240
+ const getOrCreateServer = async () => {
1241
+ if (!wsServerPromise) {
1242
+ wsServerPromise = effect.Effect.runPromise(importGraphqlWs).then(({ makeServer }) => {
1243
+ const serverOptions = {
1244
+ schema,
1245
+ context: async (ctx) => {
1246
+ const extra = ctx.extra;
1247
+ return {
1248
+ runtime: extra.runtime,
1249
+ ...extra.connectionParams
1250
+ };
1251
+ },
1252
+ subscribe: async (args) => graphql.subscribe(args),
1253
+ onConnect: makeOnConnectHandler(options),
1254
+ onDisconnect: makeOnDisconnectHandler(options),
1255
+ onSubscribe: makeOnSubscribeHandler(options, schema, complexityConfig, fieldComplexities),
1256
+ onComplete: makeOnCompleteHandler(options),
1257
+ onError: makeOnErrorHandler(options)
1258
+ };
1259
+ return makeServer(serverOptions);
1260
+ });
1261
+ }
1262
+ return wsServerPromise;
1249
1263
  };
1250
- const wsServer = graphqlWs.makeServer(serverOptions);
1251
1264
  return (socket) => effect.Effect.gen(function* () {
1265
+ const wsServer = yield* effect.Effect.tryPromise({
1266
+ try: () => getOrCreateServer(),
1267
+ catch: (error) => error
1268
+ });
1252
1269
  const runtime = yield* effect.Effect.provide(effect.Effect.runtime(), layer);
1253
1270
  const extra = {
1254
1271
  socket,