Skip to content

Commit 24fe3ee

Browse files
committed
fix: make graphql-ws a lazy dependency so ORM works without it
The realtime module is optional — apps that don't use subscriptions (like the CLI) should not need graphql-ws installed. Changed the top-level import to a TypeScript import() type (erased at compile time) and moved the require() call inside the RealtimeManager constructor so it only executes when realtime is actually used.
1 parent cb3bd3f commit 24fe3ee

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

graphql/codegen/src/core/codegen/templates/orm-realtime.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
* Any changes here will affect all generated ORM clients.
1010
*/
1111

12-
import { createClient as createWsClient } from 'graphql-ws';
13-
import type { Client as WsClient } from 'graphql-ws';
12+
// graphql-ws is loaded lazily so that importing this module does not
13+
// throw when the package is absent (e.g. CLI-only consumers).
14+
type WsClient = import('graphql-ws').Client;
1415

1516
// ============================================================================
1617
// Types
@@ -136,6 +137,9 @@ export class RealtimeManager {
136137
private activeSubscriptions = 0;
137138

138139
constructor(config: RealtimeConfig) {
140+
// eslint-disable-next-line @typescript-eslint/no-var-requires
141+
const { createClient: createWsClient } = require('graphql-ws') as typeof import('graphql-ws');
142+
139143
const retryWait = async (retryCount: number): Promise<void> => {
140144
if (typeof config.retryWait === 'function') {
141145
const result = config.retryWait(retryCount);

0 commit comments

Comments
 (0)