@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 CHANGED
@@ -11,7 +11,33 @@ A GraphQL framework for Effect-TS that brings full type safety, composability, a
11
11
  - **Immutable Builder** - Fluent, pipe-able API for composing schemas from reusable parts
12
12
  - **Service Integration** - Use Effect's Layer system for dependency injection
13
13
 
14
- ## Installation
14
+ ## Getting Started
15
+
16
+ The easiest way to get started is with the CLI:
17
+
18
+ ```bash
19
+ # Create a new project
20
+ npx @effect-gql/cli create my-api --server-type node
21
+
22
+ # Start the dev server
23
+ cd my-api
24
+ npm run dev
25
+ ```
26
+
27
+ Your GraphQL server will be running at http://localhost:4000/graphql with a GraphiQL playground at http://localhost:4000/graphiql.
28
+
29
+ ### Server Types
30
+
31
+ The CLI supports multiple server runtimes:
32
+
33
+ | Type | Command | Best For |
34
+ |------|---------|----------|
35
+ | Node.js | `--server-type node` | General Node.js deployments |
36
+ | Bun | `--server-type bun` | Bun runtime with native WebSocket support |
37
+ | Express | `--server-type express` | Integrating into existing Express apps |
38
+ | Web | `--server-type web` | Cloudflare Workers, Deno, edge runtimes |
39
+
40
+ ## Manual Installation
15
41
 
16
42
  ```bash
17
43
  npm install @effect-gql/core effect graphql
package/index.cjs CHANGED
@@ -6,7 +6,6 @@ var S2 = require('effect/Schema');
6
6
  var AST = require('effect/SchemaAST');
7
7
  var DataLoader = require('dataloader');
8
8
  var platform = require('@effect/platform');
9
- var graphqlWs = require('graphql-ws');
10
9
 
11
10
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
12
11
 
@@ -2896,27 +2895,45 @@ var runConnectionLifecycle = (socket, wsServer, extra) => effect.Effect.gen(func
2896
2895
  effect.Effect.catchAllCause(() => effect.Effect.void),
2897
2896
  effect.Effect.scoped
2898
2897
  );
2898
+ var importGraphqlWs = effect.Effect.tryPromise({
2899
+ try: () => import('graphql-ws'),
2900
+ catch: () => new Error(
2901
+ "graphql-ws is required for WebSocket subscriptions. Install it with: npm install graphql-ws"
2902
+ )
2903
+ });
2899
2904
  var makeGraphQLWSHandler = (schema, layer, options) => {
2900
2905
  const complexityConfig = options?.complexity;
2901
2906
  const fieldComplexities = options?.fieldComplexities ?? /* @__PURE__ */ new Map();
2902
- const serverOptions = {
2903
- schema,
2904
- context: async (ctx) => {
2905
- const extra = ctx.extra;
2906
- return {
2907
- runtime: extra.runtime,
2908
- ...extra.connectionParams
2909
- };
2910
- },
2911
- subscribe: async (args) => graphql.subscribe(args),
2912
- onConnect: makeOnConnectHandler(options),
2913
- onDisconnect: makeOnDisconnectHandler(options),
2914
- onSubscribe: makeOnSubscribeHandler(options, schema, complexityConfig, fieldComplexities),
2915
- onComplete: makeOnCompleteHandler(options),
2916
- onError: makeOnErrorHandler(options)
2907
+ let wsServerPromise = null;
2908
+ const getOrCreateServer = async () => {
2909
+ if (!wsServerPromise) {
2910
+ wsServerPromise = effect.Effect.runPromise(importGraphqlWs).then(({ makeServer }) => {
2911
+ const serverOptions = {
2912
+ schema,
2913
+ context: async (ctx) => {
2914
+ const extra = ctx.extra;
2915
+ return {
2916
+ runtime: extra.runtime,
2917
+ ...extra.connectionParams
2918
+ };
2919
+ },
2920
+ subscribe: async (args) => graphql.subscribe(args),
2921
+ onConnect: makeOnConnectHandler(options),
2922
+ onDisconnect: makeOnDisconnectHandler(options),
2923
+ onSubscribe: makeOnSubscribeHandler(options, schema, complexityConfig, fieldComplexities),
2924
+ onComplete: makeOnCompleteHandler(options),
2925
+ onError: makeOnErrorHandler(options)
2926
+ };
2927
+ return makeServer(serverOptions);
2928
+ });
2929
+ }
2930
+ return wsServerPromise;
2917
2931
  };
2918
- const wsServer = graphqlWs.makeServer(serverOptions);
2919
2932
  return (socket) => effect.Effect.gen(function* () {
2933
+ const wsServer = yield* effect.Effect.tryPromise({
2934
+ try: () => getOrCreateServer(),
2935
+ catch: (error) => error
2936
+ });
2920
2937
  const runtime = yield* effect.Effect.provide(effect.Effect.runtime(), layer);
2921
2938
  const extra = {
2922
2939
  socket,