@adaptic/backend-legacy 0.0.938 → 0.0.940
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/apollo-client.server.cjs +119 -0
- package/apollo-client.server.d.ts +20 -0
- package/client.cjs +22 -1
- package/client.d.ts +12 -0
- package/esm/apollo-client.server.d.ts +20 -0
- package/esm/apollo-client.server.d.ts.map +1 -1
- package/esm/apollo-client.server.js.map +1 -1
- package/esm/apollo-client.server.mjs +84 -0
- package/esm/client.d.ts +12 -0
- package/esm/client.d.ts.map +1 -1
- package/esm/client.js.map +1 -1
- package/esm/client.mjs +22 -1
- package/package.json +1 -1
package/apollo-client.server.cjs
CHANGED
|
@@ -1,7 +1,41 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// apollo-client.server.ts
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
+
}) : function(o, v) {
|
|
17
|
+
o["default"] = v;
|
|
18
|
+
});
|
|
19
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
20
|
+
var ownKeys = function(o) {
|
|
21
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
22
|
+
var ar = [];
|
|
23
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
24
|
+
return ar;
|
|
25
|
+
};
|
|
26
|
+
return ownKeys(o);
|
|
27
|
+
};
|
|
28
|
+
return function (mod) {
|
|
29
|
+
if (mod && mod.__esModule) return mod;
|
|
30
|
+
var result = {};
|
|
31
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
32
|
+
__setModuleDefault(result, mod);
|
|
33
|
+
return result;
|
|
34
|
+
};
|
|
35
|
+
})();
|
|
3
36
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
37
|
exports.onError = exports.setContext = exports.split = exports.ApolloError = exports.gql = exports.HttpLink = exports.InMemoryCache = exports.ApolloClient = void 0;
|
|
38
|
+
exports.configureKeepAliveDispatcher = configureKeepAliveDispatcher;
|
|
5
39
|
const core_cjs_1 = require("@apollo/client/core/core.cjs");
|
|
6
40
|
Object.defineProperty(exports, "ApolloClient", { enumerable: true, get: function () { return core_cjs_1.ApolloClient; } });
|
|
7
41
|
Object.defineProperty(exports, "gql", { enumerable: true, get: function () { return core_cjs_1.gql; } });
|
|
@@ -16,4 +50,89 @@ const http_cjs_1 = require("@apollo/client/link/http/http.cjs");
|
|
|
16
50
|
Object.defineProperty(exports, "HttpLink", { enumerable: true, get: function () { return http_cjs_1.HttpLink; } });
|
|
17
51
|
const inMemoryCache_js_1 = require("@apollo/client/cache/inmemory/inMemoryCache.js");
|
|
18
52
|
Object.defineProperty(exports, "InMemoryCache", { enumerable: true, get: function () { return inMemoryCache_js_1.InMemoryCache; } });
|
|
53
|
+
const logger_1 = require("./utils/logger.cjs");
|
|
54
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
55
|
+
// HTTP keepalive agent for outgoing fetch (server-side only)
|
|
56
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
57
|
+
//
|
|
58
|
+
// Without an explicit dispatcher, Node.js's built-in fetch (powered by undici)
|
|
59
|
+
// uses a default dispatcher whose connection lifetime defaults are tuned for
|
|
60
|
+
// short scripts, NOT long-running services. In long-running engine processes
|
|
61
|
+
// this manifests as TCP socket "mushrooming": every GraphQL operation opens
|
|
62
|
+
// a fresh TCP+TLS connection, and the kernel's ephemeral-port pool is
|
|
63
|
+
// exhausted under sustained load.
|
|
64
|
+
//
|
|
65
|
+
// Setting a single global undici Agent with `keepAliveTimeout` and a bounded
|
|
66
|
+
// `connections` pool ensures sockets are reused across operations and that
|
|
67
|
+
// at most N parallel connections per origin are kept alive — typical
|
|
68
|
+
// behavior for any production HTTP client. This dramatically reduces TCP
|
|
69
|
+
// handshake overhead and prevents the engine→backend-legacy connection
|
|
70
|
+
// queue from compounding under load.
|
|
71
|
+
//
|
|
72
|
+
// Tuning rationale:
|
|
73
|
+
// - keepAliveTimeout 30s: idle sockets stay open for 30s before being closed
|
|
74
|
+
// - keepAliveMaxTimeout 600s: hard cap on connection age
|
|
75
|
+
// - connections 64: max parallel sockets per origin (covers concurrent
|
|
76
|
+
// sessions × ~1 op each, with headroom for bursts)
|
|
77
|
+
// - pipelining 1: HTTP/1.1 pipelining (most servers don't support more)
|
|
78
|
+
//
|
|
79
|
+
// This setup is idempotent and safe to call multiple times — only the first
|
|
80
|
+
// call actually configures the dispatcher.
|
|
81
|
+
let keepAliveConfigured = false;
|
|
82
|
+
let keepAliveConfigurePromise;
|
|
83
|
+
/**
|
|
84
|
+
* Configure a single global undici dispatcher with persistent keepalive
|
|
85
|
+
* connections for the Node.js process. Call this once during server-side
|
|
86
|
+
* application startup, before any GraphQL operation is made.
|
|
87
|
+
*
|
|
88
|
+
* Idempotent and safe to call multiple times — only the first call actually
|
|
89
|
+
* configures the dispatcher; subsequent calls return the same in-flight or
|
|
90
|
+
* resolved promise so concurrent callers don't double-configure.
|
|
91
|
+
*
|
|
92
|
+
* Browser environments are unaffected — this function only runs on Node.js
|
|
93
|
+
* and bails out early if invoked in a browser context.
|
|
94
|
+
*/
|
|
95
|
+
function configureKeepAliveDispatcher(opts) {
|
|
96
|
+
if (keepAliveConfigured) {
|
|
97
|
+
return Promise.resolve();
|
|
98
|
+
}
|
|
99
|
+
if (keepAliveConfigurePromise) {
|
|
100
|
+
return keepAliveConfigurePromise;
|
|
101
|
+
}
|
|
102
|
+
// Server-only: bail in browser bundles.
|
|
103
|
+
if (typeof window !== 'undefined') {
|
|
104
|
+
return Promise.resolve();
|
|
105
|
+
}
|
|
106
|
+
// Use dynamic ESM import (works in both CJS and ESM Node contexts) instead
|
|
107
|
+
// of require(), which fails at runtime when this module is loaded as ESM.
|
|
108
|
+
// Cache the in-flight promise so concurrent callers join the same load.
|
|
109
|
+
keepAliveConfigurePromise = (async () => {
|
|
110
|
+
var _a, _b, _c, _d, _e, _f;
|
|
111
|
+
try {
|
|
112
|
+
const undici = (await Promise.resolve().then(() => __importStar(require('undici'))));
|
|
113
|
+
const dispatcher = new undici.Agent({
|
|
114
|
+
keepAliveTimeout: (_a = opts === null || opts === void 0 ? void 0 : opts.keepAliveTimeoutMs) !== null && _a !== void 0 ? _a : 30000,
|
|
115
|
+
keepAliveMaxTimeout: (_b = opts === null || opts === void 0 ? void 0 : opts.keepAliveMaxTimeoutMs) !== null && _b !== void 0 ? _b : 600000,
|
|
116
|
+
connections: (_c = opts === null || opts === void 0 ? void 0 : opts.connections) !== null && _c !== void 0 ? _c : 64,
|
|
117
|
+
pipelining: 1,
|
|
118
|
+
});
|
|
119
|
+
undici.setGlobalDispatcher(dispatcher);
|
|
120
|
+
keepAliveConfigured = true;
|
|
121
|
+
logger_1.logger.info('Apollo client: undici global keepalive dispatcher configured', {
|
|
122
|
+
connections: (_d = opts === null || opts === void 0 ? void 0 : opts.connections) !== null && _d !== void 0 ? _d : 64,
|
|
123
|
+
keepAliveTimeoutMs: (_e = opts === null || opts === void 0 ? void 0 : opts.keepAliveTimeoutMs) !== null && _e !== void 0 ? _e : 30000,
|
|
124
|
+
keepAliveMaxTimeoutMs: (_f = opts === null || opts === void 0 ? void 0 : opts.keepAliveMaxTimeoutMs) !== null && _f !== void 0 ? _f : 600000,
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
catch (err) {
|
|
128
|
+
// Undici should always be available alongside Node 18+ but be defensive.
|
|
129
|
+
logger_1.logger.warn('Apollo client: failed to configure undici keepalive dispatcher', {
|
|
130
|
+
error: err instanceof Error ? err.message : String(err),
|
|
131
|
+
});
|
|
132
|
+
// Reset so a future call can retry once the failure cause clears.
|
|
133
|
+
keepAliveConfigurePromise = undefined;
|
|
134
|
+
}
|
|
135
|
+
})();
|
|
136
|
+
return keepAliveConfigurePromise;
|
|
137
|
+
}
|
|
19
138
|
//# sourceMappingURL=apollo-client.server.js.map
|
|
@@ -7,4 +7,24 @@ 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 and safe to call multiple times — only the first call actually
|
|
16
|
+
* configures the dispatcher; subsequent calls return the same in-flight or
|
|
17
|
+
* resolved promise so concurrent callers don't double-configure.
|
|
18
|
+
*
|
|
19
|
+
* Browser environments are unaffected — this function only runs on Node.js
|
|
20
|
+
* and bails out early if invoked in a browser context.
|
|
21
|
+
*/
|
|
22
|
+
export declare function configureKeepAliveDispatcher(opts?: {
|
|
23
|
+
/** Max parallel sockets per origin. Default: 64. */
|
|
24
|
+
connections?: number;
|
|
25
|
+
/** Idle keep-alive timeout in milliseconds. Default: 30000. */
|
|
26
|
+
keepAliveTimeoutMs?: number;
|
|
27
|
+
/** Hard cap on connection age in milliseconds. Default: 600000 (10 min). */
|
|
28
|
+
keepAliveMaxTimeoutMs?: number;
|
|
29
|
+
}): Promise<void>;
|
|
10
30
|
//# sourceMappingURL=apollo-client.server.d.ts.map
|
package/client.cjs
CHANGED
|
@@ -225,6 +225,23 @@ 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
|
+
//
|
|
235
|
+
// Awaited so the dispatcher is installed BEFORE the HttpLink below
|
|
236
|
+
// issues its first fetch — otherwise the very first request races the
|
|
237
|
+
// async undici import and goes out on the default (non-keepalive)
|
|
238
|
+
// dispatcher.
|
|
239
|
+
if (typeof window === 'undefined') {
|
|
240
|
+
const serverModule = apolloModules;
|
|
241
|
+
if (typeof serverModule.configureKeepAliveDispatcher === 'function') {
|
|
242
|
+
await serverModule.configureKeepAliveDispatcher();
|
|
243
|
+
}
|
|
244
|
+
}
|
|
228
245
|
// Determine the GraphQL endpoint.
|
|
229
246
|
const isProduction = process.env.NODE_ENV === 'production';
|
|
230
247
|
const httpUrl = process.env.NEXT_PUBLIC_BACKEND_HTTPS_URL ||
|
|
@@ -232,7 +249,11 @@ async function getApolloClient() {
|
|
|
232
249
|
(isProduction
|
|
233
250
|
? 'https://api.adaptic.ai/graphql'
|
|
234
251
|
: 'http://localhost:4000/graphql');
|
|
235
|
-
// Create the HTTP link
|
|
252
|
+
// Create the HTTP link. The `fetch` global resolves to Node.js's
|
|
253
|
+
// built-in undici fetch on the server (which now uses the keepalive
|
|
254
|
+
// dispatcher configured above) or the browser's native fetch on the
|
|
255
|
+
// client. Either way, sockets are reused across requests instead of
|
|
256
|
+
// a fresh TCP+TLS handshake per operation.
|
|
236
257
|
const httpLinkInstance = new HttpLink({
|
|
237
258
|
uri: httpUrl,
|
|
238
259
|
fetch,
|
package/client.d.ts
CHANGED
|
@@ -10,6 +10,18 @@ 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'`. Returns a Promise so
|
|
17
|
+
* callers can await the dispatcher being installed before issuing the
|
|
18
|
+
* first GraphQL operation.
|
|
19
|
+
*/
|
|
20
|
+
configureKeepAliveDispatcher?: (opts?: {
|
|
21
|
+
connections?: number;
|
|
22
|
+
keepAliveTimeoutMs?: number;
|
|
23
|
+
keepAliveMaxTimeoutMs?: number;
|
|
24
|
+
}) => Promise<void>;
|
|
13
25
|
}
|
|
14
26
|
interface ConnectionPoolConfig {
|
|
15
27
|
maxConcurrentOperations: number;
|
|
@@ -7,4 +7,24 @@ 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 and safe to call multiple times — only the first call actually
|
|
16
|
+
* configures the dispatcher; subsequent calls return the same in-flight or
|
|
17
|
+
* resolved promise so concurrent callers don't double-configure.
|
|
18
|
+
*
|
|
19
|
+
* Browser environments are unaffected — this function only runs on Node.js
|
|
20
|
+
* and bails out early if invoked in a browser context.
|
|
21
|
+
*/
|
|
22
|
+
export declare function configureKeepAliveDispatcher(opts?: {
|
|
23
|
+
/** Max parallel sockets per origin. Default: 64. */
|
|
24
|
+
connections?: number;
|
|
25
|
+
/** Idle keep-alive timeout in milliseconds. Default: 30000. */
|
|
26
|
+
keepAliveTimeoutMs?: number;
|
|
27
|
+
/** Hard cap on connection age in milliseconds. Default: 600000 (10 min). */
|
|
28
|
+
keepAliveMaxTimeoutMs?: number;
|
|
29
|
+
}): Promise<void>;
|
|
10
30
|
//# 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;
|
|
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,EA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AC,GAAG,CAAC;aACxD,CAAC,CAAC;YACH,kEAAkE;YAClE,yBAAyB,GAAG,SAAS,CAAC;QACxC,CAAC;IACH,CAAC,CAAC,EAAE,CAAC;IAEL,OAAO,yBAAyB,CAAC;AACnC,CAAC"}
|
|
@@ -5,6 +5,90 @@ 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
|
+
let keepAliveConfigurePromise;
|
|
40
|
+
/**
|
|
41
|
+
* Configure a single global undici dispatcher with persistent keepalive
|
|
42
|
+
* connections for the Node.js process. Call this once during server-side
|
|
43
|
+
* application startup, before any GraphQL operation is made.
|
|
44
|
+
*
|
|
45
|
+
* Idempotent and safe to call multiple times — only the first call actually
|
|
46
|
+
* configures the dispatcher; subsequent calls return the same in-flight or
|
|
47
|
+
* resolved promise so concurrent callers don't double-configure.
|
|
48
|
+
*
|
|
49
|
+
* Browser environments are unaffected — this function only runs on Node.js
|
|
50
|
+
* and bails out early if invoked in a browser context.
|
|
51
|
+
*/
|
|
52
|
+
export function configureKeepAliveDispatcher(opts) {
|
|
53
|
+
if (keepAliveConfigured) {
|
|
54
|
+
return Promise.resolve();
|
|
55
|
+
}
|
|
56
|
+
if (keepAliveConfigurePromise) {
|
|
57
|
+
return keepAliveConfigurePromise;
|
|
58
|
+
}
|
|
59
|
+
// Server-only: bail in browser bundles.
|
|
60
|
+
if (typeof window !== 'undefined') {
|
|
61
|
+
return Promise.resolve();
|
|
62
|
+
}
|
|
63
|
+
// Use dynamic ESM import (works in both CJS and ESM Node contexts) instead
|
|
64
|
+
// of require(), which fails at runtime when this module is loaded as ESM.
|
|
65
|
+
// Cache the in-flight promise so concurrent callers join the same load.
|
|
66
|
+
keepAliveConfigurePromise = (async () => {
|
|
67
|
+
try {
|
|
68
|
+
const undici = (await import('undici'));
|
|
69
|
+
const dispatcher = new undici.Agent({
|
|
70
|
+
keepAliveTimeout: opts?.keepAliveTimeoutMs ?? 30_000,
|
|
71
|
+
keepAliveMaxTimeout: opts?.keepAliveMaxTimeoutMs ?? 600_000,
|
|
72
|
+
connections: opts?.connections ?? 64,
|
|
73
|
+
pipelining: 1,
|
|
74
|
+
});
|
|
75
|
+
undici.setGlobalDispatcher(dispatcher);
|
|
76
|
+
keepAliveConfigured = true;
|
|
77
|
+
logger.info('Apollo client: undici global keepalive dispatcher configured', {
|
|
78
|
+
connections: opts?.connections ?? 64,
|
|
79
|
+
keepAliveTimeoutMs: opts?.keepAliveTimeoutMs ?? 30_000,
|
|
80
|
+
keepAliveMaxTimeoutMs: opts?.keepAliveMaxTimeoutMs ?? 600_000,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
catch (err) {
|
|
84
|
+
// Undici should always be available alongside Node 18+ but be defensive.
|
|
85
|
+
logger.warn('Apollo client: failed to configure undici keepalive dispatcher', {
|
|
86
|
+
error: err instanceof Error ? err.message : String(err),
|
|
87
|
+
});
|
|
88
|
+
// Reset so a future call can retry once the failure cause clears.
|
|
89
|
+
keepAliveConfigurePromise = undefined;
|
|
90
|
+
}
|
|
91
|
+
})();
|
|
92
|
+
return keepAliveConfigurePromise;
|
|
93
|
+
}
|
|
10
94
|
//# sourceMappingURL=apollo-client.server.js.map
|
package/esm/client.d.ts
CHANGED
|
@@ -10,6 +10,18 @@ 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'`. Returns a Promise so
|
|
17
|
+
* callers can await the dispatcher being installed before issuing the
|
|
18
|
+
* first GraphQL operation.
|
|
19
|
+
*/
|
|
20
|
+
configureKeepAliveDispatcher?: (opts?: {
|
|
21
|
+
connections?: number;
|
|
22
|
+
keepAliveTimeoutMs?: number;
|
|
23
|
+
keepAliveMaxTimeoutMs?: number;
|
|
24
|
+
}) => Promise<void>;
|
|
13
25
|
}
|
|
14
26
|
interface ConnectionPoolConfig {
|
|
15
27
|
maxConcurrentOperations: number;
|
package/esm/client.d.ts.map
CHANGED
|
@@ -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,EAAE,aAAa,CAAC;IAC1F,QAAQ,EAAE,cAAc,0BAA0B,EAAE,QAAQ,CAAC;IAC7D,GAAG,EAAE,cAAc,gBAAgB,EAAE,GAAG,CAAC;IACzC,WAAW,EAAE,cAAc,gBAAgB,EAAE,WAAW,CAAC;IACzD,KAAK,EAAE,cAAc,gBAAgB,EAAE,KAAK,CAAC;IAC7C,UAAU,EAAE,cAAc,6BAA6B,EAAE,UAAU,CAAC;IACpE,OAAO,EAAE,cAAc,2BAA2B,EAAE,OAAO,CAAC;
|
|
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,CA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O,CAC9C,gBAAgB,CAAC,qBAAqB,CAAC,CACxC,CAwLA;AAED;;;;;GAKG;AACH,wBAAsB,gBAAgB,IAAI,OAAO,CAAC,aAAa,CAAC,CAK/D;AAED;;;;GAIG;AACH,eAAO,MAAM,MAAM,kDAAoB,CAAC"}
|
package/esm/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAAA,YAAY;AAEZ,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAAA,YAAY;AAEZ,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAmDxC,MAAM,mBAAmB,GAAyB;IAChD,uBAAuB,EAAE,GAAG,EAAE,gDAAgD;IAC9E,aAAa,EAAE,CAAC,EAAE,iDAAiD;IACnE,UAAU,EAAE,IAAI,EAAE,kEAAkE;IACpF,iBAAiB,EAAE,KAAK,EAAE,2BAA2B;CACtD,CAAC;AASF,yBAAyB;AACzB,IAAI,aAAwC,CAAC;AAC7C,IAAI,YAAiE,CAAC;AACtE,IAAI,iBAAiB,GAAG,CAAC,CAAC;AAC1B,MAAM,cAAc,GAA+B,EAAE,CAAC;AACtD,IAAI,UAAU,GAAyB,mBAAmB,CAAC;AAC3D,IAAI,mBAA8C,CAAC;AAanD;;GAEG;AACH,KAAK,UAAU,iBAAiB;IAC9B,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,OAAO,CAAC,GAAG,CAAC,iBAAiB,EAAE,CAAC;QACnE,mEAAmE;QACnE,OAAO,CAAC,MAAM,MAAM,CAAC,wBAAwB,CAAC,CAAkB,CAAC;IACnE,CAAC;SAAM,CAAC;QACN,kDAAkD;QAClD,OAAO,CAAC,MAAM,MAAM,CAAC,wBAAwB,CAAC,CAAkB,CAAC;IACnE,CAAC;AACH,CAAC;A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EH,wEAAwE;QACxE,MAAM,aAAa,GAAG,YAAY,CAAC,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QAC5D,MAAM,cAAc,GAAG,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QAE9D,YAAY,CAAC,KAAK,GAAG,CAAC,OAAO,EAAE,EAAE;YAC/B,OAAO,gBAAgB,CAAC,GAAG,EAAE,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC;QACxD,CAAC,CAAC;QAEF,YAAY,CAAC,MAAM,GAAG,CAAC,OAAO,EAAE,EAAE;YAChC,OAAO,gBAAgB,CAAC,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,23 @@ 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
|
+
//
|
|
195
|
+
// Awaited so the dispatcher is installed BEFORE the HttpLink below
|
|
196
|
+
// issues its first fetch — otherwise the very first request races the
|
|
197
|
+
// async undici import and goes out on the default (non-keepalive)
|
|
198
|
+
// dispatcher.
|
|
199
|
+
if (typeof window === 'undefined') {
|
|
200
|
+
const serverModule = apolloModules;
|
|
201
|
+
if (typeof serverModule.configureKeepAliveDispatcher === 'function') {
|
|
202
|
+
await serverModule.configureKeepAliveDispatcher();
|
|
203
|
+
}
|
|
204
|
+
}
|
|
188
205
|
// Determine the GraphQL endpoint.
|
|
189
206
|
const isProduction = process.env.NODE_ENV === 'production';
|
|
190
207
|
const httpUrl = process.env.NEXT_PUBLIC_BACKEND_HTTPS_URL ||
|
|
@@ -192,7 +209,11 @@ export async function getApolloClient() {
|
|
|
192
209
|
(isProduction
|
|
193
210
|
? 'https://api.adaptic.ai/graphql'
|
|
194
211
|
: 'http://localhost:4000/graphql');
|
|
195
|
-
// Create the HTTP link
|
|
212
|
+
// Create the HTTP link. The `fetch` global resolves to Node.js's
|
|
213
|
+
// built-in undici fetch on the server (which now uses the keepalive
|
|
214
|
+
// dispatcher configured above) or the browser's native fetch on the
|
|
215
|
+
// client. Either way, sockets are reused across requests instead of
|
|
216
|
+
// a fresh TCP+TLS handshake per operation.
|
|
196
217
|
const httpLinkInstance = new HttpLink({
|
|
197
218
|
uri: httpUrl,
|
|
198
219
|
fetch,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adaptic/backend-legacy",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.940",
|
|
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",
|