@adaptic/backend-legacy 0.0.937 → 0.0.939

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.
@@ -2,6 +2,7 @@
2
2
  // apollo-client.server.ts
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.onError = exports.setContext = exports.split = exports.ApolloError = exports.gql = exports.HttpLink = exports.InMemoryCache = exports.ApolloClient = void 0;
5
+ exports.configureKeepAliveDispatcher = configureKeepAliveDispatcher;
5
6
  const core_cjs_1 = require("@apollo/client/core/core.cjs");
6
7
  Object.defineProperty(exports, "ApolloClient", { enumerable: true, get: function () { return core_cjs_1.ApolloClient; } });
7
8
  Object.defineProperty(exports, "gql", { enumerable: true, get: function () { return core_cjs_1.gql; } });
@@ -16,4 +17,76 @@ const http_cjs_1 = require("@apollo/client/link/http/http.cjs");
16
17
  Object.defineProperty(exports, "HttpLink", { enumerable: true, get: function () { return http_cjs_1.HttpLink; } });
17
18
  const inMemoryCache_js_1 = require("@apollo/client/cache/inmemory/inMemoryCache.js");
18
19
  Object.defineProperty(exports, "InMemoryCache", { enumerable: true, get: function () { return inMemoryCache_js_1.InMemoryCache; } });
20
+ const logger_1 = require("./utils/logger.cjs");
21
+ // ─────────────────────────────────────────────────────────────────────────
22
+ // HTTP keepalive agent for outgoing fetch (server-side only)
23
+ // ─────────────────────────────────────────────────────────────────────────
24
+ //
25
+ // Without an explicit dispatcher, Node.js's built-in fetch (powered by undici)
26
+ // uses a default dispatcher whose connection lifetime defaults are tuned for
27
+ // short scripts, NOT long-running services. In long-running engine processes
28
+ // this manifests as TCP socket "mushrooming": every GraphQL operation opens
29
+ // a fresh TCP+TLS connection, and the kernel's ephemeral-port pool is
30
+ // exhausted under sustained load.
31
+ //
32
+ // Setting a single global undici Agent with `keepAliveTimeout` and a bounded
33
+ // `connections` pool ensures sockets are reused across operations and that
34
+ // at most N parallel connections per origin are kept alive — typical
35
+ // behavior for any production HTTP client. This dramatically reduces TCP
36
+ // handshake overhead and prevents the engine→backend-legacy connection
37
+ // queue from compounding under load.
38
+ //
39
+ // Tuning rationale:
40
+ // - keepAliveTimeout 30s: idle sockets stay open for 30s before being closed
41
+ // - keepAliveMaxTimeout 600s: hard cap on connection age
42
+ // - connections 64: max parallel sockets per origin (covers concurrent
43
+ // sessions × ~1 op each, with headroom for bursts)
44
+ // - pipelining 1: HTTP/1.1 pipelining (most servers don't support more)
45
+ //
46
+ // This setup is idempotent and safe to call multiple times — only the first
47
+ // call actually configures the dispatcher.
48
+ let keepAliveConfigured = false;
49
+ /**
50
+ * Configure a single global undici dispatcher with persistent keepalive
51
+ * connections for the Node.js process. Call this once during server-side
52
+ * application startup, before any GraphQL operation is made.
53
+ *
54
+ * Idempotent: subsequent calls are no-ops.
55
+ *
56
+ * Browser environments are unaffected — this function only runs on Node.js.
57
+ */
58
+ function configureKeepAliveDispatcher(opts) {
59
+ var _a, _b, _c, _d, _e, _f;
60
+ if (keepAliveConfigured) {
61
+ return;
62
+ }
63
+ // Server-only: bail in browser bundles.
64
+ if (typeof window !== 'undefined') {
65
+ return;
66
+ }
67
+ try {
68
+ // Lazy require so this file remains tree-shakable for browser consumers.
69
+ // eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires
70
+ const undici = require('undici');
71
+ const dispatcher = new undici.Agent({
72
+ keepAliveTimeout: (_a = opts === null || opts === void 0 ? void 0 : opts.keepAliveTimeoutMs) !== null && _a !== void 0 ? _a : 30000,
73
+ keepAliveMaxTimeout: (_b = opts === null || opts === void 0 ? void 0 : opts.keepAliveMaxTimeoutMs) !== null && _b !== void 0 ? _b : 600000,
74
+ connections: (_c = opts === null || opts === void 0 ? void 0 : opts.connections) !== null && _c !== void 0 ? _c : 64,
75
+ pipelining: 1,
76
+ });
77
+ undici.setGlobalDispatcher(dispatcher);
78
+ keepAliveConfigured = true;
79
+ logger_1.logger.info('Apollo client: undici global keepalive dispatcher configured', {
80
+ connections: (_d = opts === null || opts === void 0 ? void 0 : opts.connections) !== null && _d !== void 0 ? _d : 64,
81
+ keepAliveTimeoutMs: (_e = opts === null || opts === void 0 ? void 0 : opts.keepAliveTimeoutMs) !== null && _e !== void 0 ? _e : 30000,
82
+ keepAliveMaxTimeoutMs: (_f = opts === null || opts === void 0 ? void 0 : opts.keepAliveMaxTimeoutMs) !== null && _f !== void 0 ? _f : 600000,
83
+ });
84
+ }
85
+ catch (err) {
86
+ // Undici should always be available alongside Node 18+ but be defensive.
87
+ logger_1.logger.warn('Apollo client: failed to configure undici keepalive dispatcher', {
88
+ error: err instanceof Error ? err.message : String(err),
89
+ });
90
+ }
91
+ }
19
92
  //# sourceMappingURL=apollo-client.server.js.map
@@ -7,4 +7,21 @@ import { HttpLink } from '@apollo/client/link/http/http.cjs';
7
7
  import { InMemoryCache } from '@apollo/client/cache/inmemory/inMemoryCache.js';
8
8
  export { ApolloClient, InMemoryCache, HttpLink, gql, ApolloError, split, setContext, onError, };
9
9
  export type { ApolloClientType, InMemoryCacheType, HttpLinkType, NormalizedCacheObject, };
10
+ /**
11
+ * Configure a single global undici dispatcher with persistent keepalive
12
+ * connections for the Node.js process. Call this once during server-side
13
+ * application startup, before any GraphQL operation is made.
14
+ *
15
+ * Idempotent: subsequent calls are no-ops.
16
+ *
17
+ * Browser environments are unaffected — this function only runs on Node.js.
18
+ */
19
+ export declare function configureKeepAliveDispatcher(opts?: {
20
+ /** Max parallel sockets per origin. Default: 64. */
21
+ connections?: number;
22
+ /** Idle keep-alive timeout in milliseconds. Default: 30000. */
23
+ keepAliveTimeoutMs?: number;
24
+ /** Hard cap on connection age in milliseconds. Default: 600000 (10 min). */
25
+ keepAliveMaxTimeoutMs?: number;
26
+ }): void;
10
27
  //# sourceMappingURL=apollo-client.server.d.ts.map
package/client.cjs CHANGED
@@ -225,6 +225,18 @@ async function getApolloClient() {
225
225
  apolloModules = await loadApolloModules();
226
226
  }
227
227
  const { ApolloClient, InMemoryCache, HttpLink, setContext, onError } = apolloModules;
228
+ // Configure a global undici keepalive dispatcher for Node.js fetch.
229
+ // Without this, Node's built-in fetch opens a fresh TCP socket per
230
+ // request, exhausting the kernel's ephemeral port pool under sustained
231
+ // load (the engine's signature symptom on Railway with many concurrent
232
+ // GraphQL operations). This is server-only — browser bundles see a
233
+ // no-op since `apollo-client.server.ts` is only loaded on Node.js.
234
+ if (typeof window === 'undefined') {
235
+ const serverModule = apolloModules;
236
+ if (typeof serverModule.configureKeepAliveDispatcher === 'function') {
237
+ serverModule.configureKeepAliveDispatcher();
238
+ }
239
+ }
228
240
  // Determine the GraphQL endpoint.
229
241
  const isProduction = process.env.NODE_ENV === 'production';
230
242
  const httpUrl = process.env.NEXT_PUBLIC_BACKEND_HTTPS_URL ||
@@ -232,7 +244,11 @@ async function getApolloClient() {
232
244
  (isProduction
233
245
  ? 'https://api.adaptic.ai/graphql'
234
246
  : 'http://localhost:4000/graphql');
235
- // Create the HTTP link with appropriate fetch policies and timeouts
247
+ // Create the HTTP link. The `fetch` global resolves to Node.js's
248
+ // built-in undici fetch on the server (which now uses the keepalive
249
+ // dispatcher configured above) or the browser's native fetch on the
250
+ // client. Either way, sockets are reused across requests instead of
251
+ // a fresh TCP+TLS handshake per operation.
236
252
  const httpLinkInstance = new HttpLink({
237
253
  uri: httpUrl,
238
254
  fetch,
@@ -254,14 +270,62 @@ async function getApolloClient() {
254
270
  };
255
271
  });
256
272
  // Create the error handling link with retry logic.
273
+ //
274
+ // Apollo's onError link fires on every error including transient ones
275
+ // that the wrapping retryLink (and the engine-side retry-with-backoff
276
+ // queue at executeWithRetry above) handles automatically. Logging
277
+ // every transient blip at ERROR floods the consumer's error budget
278
+ // and triggers spurious alerts during checkpoint storms / brief
279
+ // network jitter. Demote known transient classes to WARN; reserve
280
+ // ERROR for genuine non-recoverable issues.
257
281
  const errorLink = onError(({ graphQLErrors, networkError }) => {
258
282
  if (graphQLErrors) {
259
283
  graphQLErrors.forEach(({ message, locations, path }) => {
260
- logger_1.logger.error(`[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`);
284
+ // Same demotion classes as the formatError handler in server.ts
285
+ // and the prismaClient $on('error') categorizer:
286
+ // - Delete/update race on already-removed rows -> INFO
287
+ // - Invalid UUID input from buggy callers -> WARN
288
+ // - Everything else -> ERROR
289
+ const isExpectedDeleteRace = message.includes('No record was found for a delete') ||
290
+ message.includes('No record was found for an update');
291
+ const isInvalidUuidInput = message.includes('Error creating UUID') ||
292
+ message.includes('Inconsistent column data: Error creating UUID');
293
+ if (isExpectedDeleteRace) {
294
+ logger_1.logger.info(`[GraphQL expected race]: Message: ${message}, Location: ${locations}, Path: ${path}`);
295
+ }
296
+ else if (isInvalidUuidInput) {
297
+ logger_1.logger.warn(`[GraphQL invalid UUID input]: Message: ${message}, Location: ${locations}, Path: ${path}`);
298
+ }
299
+ else {
300
+ logger_1.logger.error(`[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`);
301
+ }
261
302
  });
262
303
  }
263
304
  if (networkError) {
264
- logger_1.logger.error(`[Network error]: ${networkError}`);
305
+ const errMessage = String(networkError);
306
+ // Network-class transients that the wrapping retry queue at
307
+ // executeWithRetry already handles automatically. Each retry
308
+ // attempt was logging at ERROR, producing 7+ ERROR lines per
309
+ // retry sequence. Demote known transients to WARN; reserve
310
+ // ERROR for non-network failures (TLS handshake, DNS resolve,
311
+ // SSL cert validation).
312
+ const isTransient = errMessage.includes('TypeError: fetch failed') ||
313
+ errMessage.includes('TimeoutError') ||
314
+ errMessage.includes('aborted due to timeout') ||
315
+ errMessage.includes('ECONNRESET') ||
316
+ errMessage.includes('ETIMEDOUT') ||
317
+ errMessage.includes('ECONNREFUSED') ||
318
+ errMessage.includes('socket hang up') ||
319
+ errMessage.includes('status code 408') ||
320
+ errMessage.includes('status code 502') ||
321
+ errMessage.includes('status code 503') ||
322
+ errMessage.includes('status code 504');
323
+ if (isTransient) {
324
+ logger_1.logger.warn(`[Network error]: ${errMessage} (transient — caller retry queue will handle)`);
325
+ }
326
+ else {
327
+ logger_1.logger.error(`[Network error]: ${errMessage}`);
328
+ }
265
329
  }
266
330
  });
267
331
  // Default options with conservative caching and fetch policies
package/client.d.ts CHANGED
@@ -10,6 +10,16 @@ export interface ApolloModules {
10
10
  split: typeof import('@apollo/client').split;
11
11
  setContext: typeof import('@apollo/client/link/context').setContext;
12
12
  onError: typeof import('@apollo/client/link/error').onError;
13
+ /**
14
+ * Server-only helper: lazily exported only by `apollo-client.server.ts`.
15
+ * The browser variant does not export this and the runtime check above
16
+ * gates the call to `typeof window === 'undefined'`.
17
+ */
18
+ configureKeepAliveDispatcher?: (opts?: {
19
+ connections?: number;
20
+ keepAliveTimeoutMs?: number;
21
+ keepAliveMaxTimeoutMs?: number;
22
+ }) => void;
13
23
  }
14
24
  interface ConnectionPoolConfig {
15
25
  maxConcurrentOperations: number;
@@ -7,4 +7,21 @@ import { HttpLink } from '@apollo/client/link/http/http.cjs';
7
7
  import { InMemoryCache } from '@apollo/client/cache/inmemory/inMemoryCache.js';
8
8
  export { ApolloClient, InMemoryCache, HttpLink, gql, ApolloError, split, setContext, onError, };
9
9
  export type { ApolloClientType, InMemoryCacheType, HttpLinkType, NormalizedCacheObject, };
10
+ /**
11
+ * Configure a single global undici dispatcher with persistent keepalive
12
+ * connections for the Node.js process. Call this once during server-side
13
+ * application startup, before any GraphQL operation is made.
14
+ *
15
+ * Idempotent: subsequent calls are no-ops.
16
+ *
17
+ * Browser environments are unaffected — this function only runs on Node.js.
18
+ */
19
+ export declare function configureKeepAliveDispatcher(opts?: {
20
+ /** Max parallel sockets per origin. Default: 64. */
21
+ connections?: number;
22
+ /** Idle keep-alive timeout in milliseconds. Default: 30000. */
23
+ keepAliveTimeoutMs?: number;
24
+ /** Hard cap on connection age in milliseconds. Default: 600000 (10 min). */
25
+ keepAliveMaxTimeoutMs?: number;
26
+ }): void;
10
27
  //# sourceMappingURL=apollo-client.server.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"apollo-client.server.d.ts","sourceRoot":"","sources":["../../src/apollo-client.server.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,YAAY,IAAI,gBAAgB,EAChC,aAAa,IAAI,iBAAiB,EAClC,QAAQ,IAAI,YAAY,EACxB,qBAAqB,EACtB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,YAAY,EAAE,GAAG,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAC9E,OAAO,EAAE,KAAK,EAAE,MAAM,mCAAmC,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,yCAAyC,CAAC;AACrE,OAAO,EAAE,OAAO,EAAE,MAAM,qCAAqC,CAAC;AAC9D,OAAO,EAAE,QAAQ,EAAE,MAAM,mCAAmC,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,gDAAgD,CAAC;AAE/E,OAAO,EACL,YAAY,EACZ,aAAa,EACb,QAAQ,EACR,GAAG,EACH,WAAW,EACX,KAAK,EACL,UAAU,EACV,OAAO,GACR,CAAC;AAGF,YAAY,EACV,gBAAgB,EAChB,iBAAiB,EACjB,YAAY,EACZ,qBAAqB,GACtB,CAAC"}
1
+ {"version":3,"file":"apollo-client.server.d.ts","sourceRoot":"","sources":["../../src/apollo-client.server.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,YAAY,IAAI,gBAAgB,EAChC,aAAa,IAAI,iBAAiB,EAClC,QAAQ,IAAI,YAAY,EACxB,qBAAqB,EACtB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,YAAY,EAAE,GAAG,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAC9E,OAAO,EAAE,KAAK,EAAE,MAAM,mCAAmC,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,yCAAyC,CAAC;AACrE,OAAO,EAAE,OAAO,EAAE,MAAM,qCAAqC,CAAC;AAC9D,OAAO,EAAE,QAAQ,EAAE,MAAM,mCAAmC,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,gDAAgD,CAAC;AAI/E,OAAO,EACL,YAAY,EACZ,aAAa,EACb,QAAQ,EACR,GAAG,EACH,WAAW,EACX,KAAK,EACL,UAAU,EACV,OAAO,GACR,CAAC;AAGF,YAAY,EACV,gBAAgB,EAChB,iBAAiB,EACjB,YAAY,EACZ,qBAAqB,GACtB,CAAC;AAgCF;;;;;;;;GAQG;AACH,wBAAgB,4BAA4B,CAAC,IAAI,CAAC,EAAE;IAClD,oDAAoD;IACpD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,+DAA+D;IAC/D,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,4EAA4E;IAC5E,qBAAqB,CAAC,EAAE,MAAM,CAAC;CAChC,GAAG,IAAI,CAoCP"}
@@ -1 +1 @@
1
- {"version":3,"file":"apollo-client.server.js","sourceRoot":"","sources":["../../src/apollo-client.server.ts"],"names":[],"mappings":"AAAA,0BAA0B;AAU1B,OAAO,EAAE,YAAY,EAAE,GAAG,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAC9E,OAAO,EAAE,KAAK,EAAE,MAAM,mCAAmC,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,yCAAyC,CAAC;AACrE,OAAO,EAAE,OAAO,EAAE,MAAM,qCAAqC,CAAC;AAC9D,OAAO,EAAE,QAAQ,EAAE,MAAM,mCAAmC,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,gDAAgD,CAAC;AAC/E,yCAAyC;AACzC,OAAO,EACL,YAAY,EACZ,aAAa,EACb,QAAQ,EACR,GAAG,EACH,WAAW,EACX,KAAK,EACL,UAAU,EACV,OAAO,GACR,CAAC"}
1
+ {"version":3,"file":"apollo-client.server.js","sourceRoot":"","sources":["../../src/apollo-client.server.ts"],"names":[],"mappings":"AAAA,0BAA0B;AAU1B,OAAO,EAAE,YAAY,EAAE,GAAG,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAC9E,OAAO,EAAE,KAAK,EAAE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AAI,MAAM;YACpD,mBAAmB,EAAE,IAAI,EAAE,qBAAqB,IAAI,OAAO;YAC3D,WAAW,EAAE,IAAI,EAAE,WAAW,IAAI,EAAE;YACpC,UAAU,EAAE,CAAC;SACd,CAAC,CAAC;QAEH,MAAM,CAAC,mBAAmB,CAAC,UAAU,CAAC,CAAC;QACvC,mBAAmB,GAAG,IAAI,CAAC;QAE3B,MAAM,CAAC,IAAI,CAAC,8DAA8D,EAAE;YAC1E,WAAW,EAAE,IAAI,EAAE,WAAW,IAAI,EAAE;YACpC,kBAAkB,EAAE,IAAI,EAAE,kBAAkB,IAAI,MAAM;YACtD,qBAAqB,EAAE,IAAI,EAAE,qBAAqB,IAAI,OAAO;SAC9D,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,yEAAyE;QACzE,MAAM,CAAC,IAAI,CAAC,gEAAgE,EAAE;YAC5E,KAAK,EAAE,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC;SACxD,CAAC,CAAC;IACL,CAAC;AACH,CAAC"}
@@ -5,6 +5,77 @@ import { setContext } from '@apollo/client/link/context/context.cjs';
5
5
  import { onError } from '@apollo/client/link/error/error.cjs';
6
6
  import { HttpLink } from '@apollo/client/link/http/http.cjs';
7
7
  import { InMemoryCache } from '@apollo/client/cache/inmemory/inMemoryCache.js';
8
+ import { logger } from './utils/logger.mjs';
8
9
  // Re‑export the runtime implementations.
9
10
  export { ApolloClient, InMemoryCache, HttpLink, gql, ApolloError, split, setContext, onError, };
11
+ // ─────────────────────────────────────────────────────────────────────────
12
+ // HTTP keepalive agent for outgoing fetch (server-side only)
13
+ // ─────────────────────────────────────────────────────────────────────────
14
+ //
15
+ // Without an explicit dispatcher, Node.js's built-in fetch (powered by undici)
16
+ // uses a default dispatcher whose connection lifetime defaults are tuned for
17
+ // short scripts, NOT long-running services. In long-running engine processes
18
+ // this manifests as TCP socket "mushrooming": every GraphQL operation opens
19
+ // a fresh TCP+TLS connection, and the kernel's ephemeral-port pool is
20
+ // exhausted under sustained load.
21
+ //
22
+ // Setting a single global undici Agent with `keepAliveTimeout` and a bounded
23
+ // `connections` pool ensures sockets are reused across operations and that
24
+ // at most N parallel connections per origin are kept alive — typical
25
+ // behavior for any production HTTP client. This dramatically reduces TCP
26
+ // handshake overhead and prevents the engine→backend-legacy connection
27
+ // queue from compounding under load.
28
+ //
29
+ // Tuning rationale:
30
+ // - keepAliveTimeout 30s: idle sockets stay open for 30s before being closed
31
+ // - keepAliveMaxTimeout 600s: hard cap on connection age
32
+ // - connections 64: max parallel sockets per origin (covers concurrent
33
+ // sessions × ~1 op each, with headroom for bursts)
34
+ // - pipelining 1: HTTP/1.1 pipelining (most servers don't support more)
35
+ //
36
+ // This setup is idempotent and safe to call multiple times — only the first
37
+ // call actually configures the dispatcher.
38
+ let keepAliveConfigured = false;
39
+ /**
40
+ * Configure a single global undici dispatcher with persistent keepalive
41
+ * connections for the Node.js process. Call this once during server-side
42
+ * application startup, before any GraphQL operation is made.
43
+ *
44
+ * Idempotent: subsequent calls are no-ops.
45
+ *
46
+ * Browser environments are unaffected — this function only runs on Node.js.
47
+ */
48
+ export function configureKeepAliveDispatcher(opts) {
49
+ if (keepAliveConfigured) {
50
+ return;
51
+ }
52
+ // Server-only: bail in browser bundles.
53
+ if (typeof window !== 'undefined') {
54
+ return;
55
+ }
56
+ try {
57
+ // Lazy require so this file remains tree-shakable for browser consumers.
58
+ // eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires
59
+ const undici = require('undici');
60
+ const dispatcher = new undici.Agent({
61
+ keepAliveTimeout: opts?.keepAliveTimeoutMs ?? 30_000,
62
+ keepAliveMaxTimeout: opts?.keepAliveMaxTimeoutMs ?? 600_000,
63
+ connections: opts?.connections ?? 64,
64
+ pipelining: 1,
65
+ });
66
+ undici.setGlobalDispatcher(dispatcher);
67
+ keepAliveConfigured = true;
68
+ logger.info('Apollo client: undici global keepalive dispatcher configured', {
69
+ connections: opts?.connections ?? 64,
70
+ keepAliveTimeoutMs: opts?.keepAliveTimeoutMs ?? 30_000,
71
+ keepAliveMaxTimeoutMs: opts?.keepAliveMaxTimeoutMs ?? 600_000,
72
+ });
73
+ }
74
+ catch (err) {
75
+ // Undici should always be available alongside Node 18+ but be defensive.
76
+ logger.warn('Apollo client: failed to configure undici keepalive dispatcher', {
77
+ error: err instanceof Error ? err.message : String(err),
78
+ });
79
+ }
80
+ }
10
81
  //# sourceMappingURL=apollo-client.server.js.map
package/esm/client.d.ts CHANGED
@@ -10,6 +10,16 @@ export interface ApolloModules {
10
10
  split: typeof import('@apollo/client').split;
11
11
  setContext: typeof import('@apollo/client/link/context').setContext;
12
12
  onError: typeof import('@apollo/client/link/error').onError;
13
+ /**
14
+ * Server-only helper: lazily exported only by `apollo-client.server.ts`.
15
+ * The browser variant does not export this and the runtime check above
16
+ * gates the call to `typeof window === 'undefined'`.
17
+ */
18
+ configureKeepAliveDispatcher?: (opts?: {
19
+ connections?: number;
20
+ keepAliveTimeoutMs?: number;
21
+ keepAliveMaxTimeoutMs?: number;
22
+ }) => void;
13
23
  }
14
24
  interface ConnectionPoolConfig {
15
25
  maxConcurrentOperations: number;
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,YAAY,IAAI,gBAAgB,EAChC,aAAa,IAAI,iBAAiB,EAClC,qBAAqB,EAEtB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,QAAQ,IAAI,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAEpE,YAAY,EACV,gBAAgB,EAChB,iBAAiB,EACjB,YAAY,EACZ,qBAAqB,GACtB,CAAC;AAGF,MAAM,WAAW,aAAa;IAC5B,YAAY,EAAE,cAAc,gBAAgB,EAAE,YAAY,CAAC;IAC3D,aAAa,EAAE,cAAc,6CAA6C,E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AC,GAAG,EAAE,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC;QACzD,CAAC,CAAC;QAEF,OAAO,YAAY,CAAC;IACtB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,CAAC,KAAK,CAAC,kCAAkC,EAAE,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QAC3E,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB;IACpC,IAAI,CAAC,aAAa,EAAE,CAAC;QACnB,aAAa,GAAG,MAAM,iBAAiB,EAAE,CAAC;IAC5C,CAAC;IACD,OAAO,aAAa,CAAC;AACvB,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,eAAe,EAAE,CAAC"}
package/esm/client.mjs CHANGED
@@ -185,6 +185,18 @@ export async function getApolloClient() {
185
185
  apolloModules = await loadApolloModules();
186
186
  }
187
187
  const { ApolloClient, InMemoryCache, HttpLink, setContext, onError } = apolloModules;
188
+ // Configure a global undici keepalive dispatcher for Node.js fetch.
189
+ // Without this, Node's built-in fetch opens a fresh TCP socket per
190
+ // request, exhausting the kernel's ephemeral port pool under sustained
191
+ // load (the engine's signature symptom on Railway with many concurrent
192
+ // GraphQL operations). This is server-only — browser bundles see a
193
+ // no-op since `apollo-client.server.ts` is only loaded on Node.js.
194
+ if (typeof window === 'undefined') {
195
+ const serverModule = apolloModules;
196
+ if (typeof serverModule.configureKeepAliveDispatcher === 'function') {
197
+ serverModule.configureKeepAliveDispatcher();
198
+ }
199
+ }
188
200
  // Determine the GraphQL endpoint.
189
201
  const isProduction = process.env.NODE_ENV === 'production';
190
202
  const httpUrl = process.env.NEXT_PUBLIC_BACKEND_HTTPS_URL ||
@@ -192,7 +204,11 @@ export async function getApolloClient() {
192
204
  (isProduction
193
205
  ? 'https://api.adaptic.ai/graphql'
194
206
  : 'http://localhost:4000/graphql');
195
- // Create the HTTP link with appropriate fetch policies and timeouts
207
+ // Create the HTTP link. The `fetch` global resolves to Node.js's
208
+ // built-in undici fetch on the server (which now uses the keepalive
209
+ // dispatcher configured above) or the browser's native fetch on the
210
+ // client. Either way, sockets are reused across requests instead of
211
+ // a fresh TCP+TLS handshake per operation.
196
212
  const httpLinkInstance = new HttpLink({
197
213
  uri: httpUrl,
198
214
  fetch,
@@ -214,14 +230,62 @@ export async function getApolloClient() {
214
230
  };
215
231
  });
216
232
  // Create the error handling link with retry logic.
233
+ //
234
+ // Apollo's onError link fires on every error including transient ones
235
+ // that the wrapping retryLink (and the engine-side retry-with-backoff
236
+ // queue at executeWithRetry above) handles automatically. Logging
237
+ // every transient blip at ERROR floods the consumer's error budget
238
+ // and triggers spurious alerts during checkpoint storms / brief
239
+ // network jitter. Demote known transient classes to WARN; reserve
240
+ // ERROR for genuine non-recoverable issues.
217
241
  const errorLink = onError(({ graphQLErrors, networkError }) => {
218
242
  if (graphQLErrors) {
219
243
  graphQLErrors.forEach(({ message, locations, path }) => {
220
- logger.error(`[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`);
244
+ // Same demotion classes as the formatError handler in server.ts
245
+ // and the prismaClient $on('error') categorizer:
246
+ // - Delete/update race on already-removed rows -> INFO
247
+ // - Invalid UUID input from buggy callers -> WARN
248
+ // - Everything else -> ERROR
249
+ const isExpectedDeleteRace = message.includes('No record was found for a delete') ||
250
+ message.includes('No record was found for an update');
251
+ const isInvalidUuidInput = message.includes('Error creating UUID') ||
252
+ message.includes('Inconsistent column data: Error creating UUID');
253
+ if (isExpectedDeleteRace) {
254
+ logger.info(`[GraphQL expected race]: Message: ${message}, Location: ${locations}, Path: ${path}`);
255
+ }
256
+ else if (isInvalidUuidInput) {
257
+ logger.warn(`[GraphQL invalid UUID input]: Message: ${message}, Location: ${locations}, Path: ${path}`);
258
+ }
259
+ else {
260
+ logger.error(`[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`);
261
+ }
221
262
  });
222
263
  }
223
264
  if (networkError) {
224
- logger.error(`[Network error]: ${networkError}`);
265
+ const errMessage = String(networkError);
266
+ // Network-class transients that the wrapping retry queue at
267
+ // executeWithRetry already handles automatically. Each retry
268
+ // attempt was logging at ERROR, producing 7+ ERROR lines per
269
+ // retry sequence. Demote known transients to WARN; reserve
270
+ // ERROR for non-network failures (TLS handshake, DNS resolve,
271
+ // SSL cert validation).
272
+ const isTransient = errMessage.includes('TypeError: fetch failed') ||
273
+ errMessage.includes('TimeoutError') ||
274
+ errMessage.includes('aborted due to timeout') ||
275
+ errMessage.includes('ECONNRESET') ||
276
+ errMessage.includes('ETIMEDOUT') ||
277
+ errMessage.includes('ECONNREFUSED') ||
278
+ errMessage.includes('socket hang up') ||
279
+ errMessage.includes('status code 408') ||
280
+ errMessage.includes('status code 502') ||
281
+ errMessage.includes('status code 503') ||
282
+ errMessage.includes('status code 504');
283
+ if (isTransient) {
284
+ logger.warn(`[Network error]: ${errMessage} (transient — caller retry queue will handle)`);
285
+ }
286
+ else {
287
+ logger.error(`[Network error]: ${errMessage}`);
288
+ }
225
289
  }
226
290
  });
227
291
  // Default options with conservative caching and fetch policies
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adaptic/backend-legacy",
3
- "version": "0.0.937",
3
+ "version": "0.0.939",
4
4
  "description": "Backend executable CRUD functions with dynamic variables construction, and type definitions for the Adaptic AI platform.",
5
5
  "type": "module",
6
6
  "types": "index.d.ts",