Skip to content

refactor(codegen): accept WsClient via config instead of require('graphql-ws')#1102

Merged
pyramation merged 3 commits intomainfrom
feat/realtime-inline-graphql-ws-types
May 10, 2026
Merged

refactor(codegen): accept WsClient via config instead of require('graphql-ws')#1102
pyramation merged 3 commits intomainfrom
feat/realtime-inline-graphql-ws-types

Conversation

@pyramation
Copy link
Copy Markdown
Contributor

@pyramation pyramation commented May 10, 2026

Summary

The orm-realtime.ts codegen template previously did require('graphql-ws') inside the RealtimeManager constructor, which:

  • Fails in ESM environments
  • Forces graphql-ws as a hidden dependency even when subscriptions aren't used

New approach: RealtimeConfig now accepts a client: WsClient property. The consumer creates and passes in their own graphql-ws client instance:

import { createClient } from 'graphql-ws';

const orm = createOrmClient({
  endpoint: 'https://api.example.com/graphql',
  realtime: {
    client: createClient({ url: 'wss://api.example.com/graphql' }),
  },
});

The SDK defines only a minimal WsClient interface — no import, no require, no dependency on graphql-ws at all. If the developer never uses subscriptions, they never need the package.

Changes:

  • RealtimeConfig simplified to { client: WsClient } — all WS connection options (url, auth, retry, etc.) are now the consumer's responsibility when creating the client
  • WsClient exported as a public type so consumers can reference the interface
  • RealtimeManager constructor reduced to this.wsClient = config.client
  • Snapshot updated for the new WsClient export

Review & Testing Checklist for Human

  • Verify the WsClient interface shape (subscribe + dispose) stays compatible with graphql-ws's Client type
  • After merging, run codegen in constructive-db to confirm the regenerated realtime.ts files match the new template
  • Check that any existing subscription usage in downstream apps is updated to pass client: createClient(...) instead of the old url/getToken/etc. config

Notes

Companion fix already pushed to constructive-db PR #1089 (deps-update/20260510-105803) with the same changes applied to all 13 generated realtime.ts files.

Link to Devin session: https://app.devin.ai/sessions/37cd48fd674844c8b6fa1be2b7995746
Requested by: @pyramation

…-realtime template

The orm-realtime.ts template used `type WsClient = import('graphql-ws').Client`
which requires graphql-ws to be resolvable at compile time in every SDK
consumer, even though the actual require() is lazy inside the
RealtimeManager constructor.

Replace with minimal inline type definitions (WsClient, WsClientOptions,
WsSink, WsExecutionResult) so generated code compiles without graphql-ws
as a dependency. Consumers that never use subscriptions never need the
package at all.
@devin-ai-integration
Copy link
Copy Markdown
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

…phql-ws')

Instead of the generated RealtimeManager doing require('graphql-ws')
internally (which fails in ESM and forces a hidden dependency), the
consumer now passes a WsClient instance via RealtimeConfig.client:

  import { createClient } from 'graphql-ws';
  const orm = createOrmClient({
    endpoint: '...',
    realtime: { client: createClient({ url: 'wss://...' }) },
  });

This gives the developer full control over WS connection options,
auth, and transport. If subscriptions aren't used, graphql-ws is
never imported at all.
@devin-ai-integration devin-ai-integration Bot changed the title fix(codegen): replace graphql-ws type import with inline shims in orm-realtime template refactor(codegen): accept WsClient via config instead of require('graphql-ws') May 10, 2026
@blacksmith-sh

This comment has been minimized.

@pyramation pyramation merged commit 3019808 into main May 10, 2026
55 checks passed
@pyramation pyramation deleted the feat/realtime-inline-graphql-ws-types branch May 10, 2026 20:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant