@constructive-io/graphql-server 4.3.3 → 4.4.0

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.
@@ -0,0 +1,54 @@
1
+ import { getNodeEnv } from '@constructive-io/graphql-env';
2
+ import { Logger } from '@pgpmjs/logger';
3
+ import { svcCache } from '@pgpmjs/server-utils';
4
+ import { getCacheStats } from 'graphile-cache';
5
+ import { getInFlightCount, getInFlightKeys } from './graphile';
6
+ const log = new Logger('debug-memory');
7
+ const toMB = (bytes) => `${(bytes / 1024 / 1024).toFixed(1)} MB`;
8
+ /**
9
+ * Development-only debug endpoint for monitoring memory usage and cache state.
10
+ *
11
+ * Mounts GET /debug/memory which returns:
12
+ * - Node.js process memory (heap, RSS, external, array buffers)
13
+ * - Graphile cache stats (size, max, TTL, keys with ages)
14
+ * - Service cache size
15
+ * - In-flight handler creation count
16
+ * - Process uptime
17
+ *
18
+ * This endpoint is only available when NODE_ENV=development.
19
+ * In production, it returns 404.
20
+ */
21
+ export const debugMemory = (_req, res) => {
22
+ if (getNodeEnv() !== 'development') {
23
+ res.status(404).send('Not found');
24
+ return;
25
+ }
26
+ const mem = process.memoryUsage();
27
+ const cacheStats = getCacheStats();
28
+ const response = {
29
+ memory: {
30
+ heapUsed: toMB(mem.heapUsed),
31
+ heapTotal: toMB(mem.heapTotal),
32
+ rss: toMB(mem.rss),
33
+ external: toMB(mem.external),
34
+ arrayBuffers: toMB(mem.arrayBuffers),
35
+ },
36
+ graphileCache: {
37
+ size: cacheStats.size,
38
+ max: cacheStats.max,
39
+ ttl: `${(cacheStats.ttl / 1000 / 60).toFixed(0)} min`,
40
+ keys: cacheStats.keys,
41
+ },
42
+ svcCache: {
43
+ size: svcCache.size,
44
+ },
45
+ inFlight: {
46
+ count: getInFlightCount(),
47
+ keys: getInFlightKeys(),
48
+ },
49
+ uptime: `${(process.uptime() / 60).toFixed(1)} min`,
50
+ timestamp: new Date().toISOString(),
51
+ };
52
+ log.debug('Memory snapshot:', response);
53
+ res.json(response);
54
+ };
package/esm/server.js CHANGED
@@ -17,6 +17,7 @@ import { flush, flushService } from './middleware/flush';
17
17
  import { graphile } from './middleware/graphile';
18
18
  import { multipartBridge } from './middleware/multipart-bridge';
19
19
  import { createUploadAuthenticateMiddleware, uploadRoute } from './middleware/upload';
20
+ import { debugMemory } from './middleware/debug-memory';
20
21
  import { normalizeServerOptions } from './options';
21
22
  const log = new Logger('server');
22
23
  /**
@@ -103,6 +104,7 @@ class Server {
103
104
  roleName: apiOpts.roleName,
104
105
  });
105
106
  healthz(app);
107
+ app.get('/debug/memory', debugMemory);
106
108
  app.use(favicon);
107
109
  trustProxy(app, effectiveOpts.server.trustProxy);
108
110
  // Warn if a global CORS override is set in production
@@ -0,0 +1,15 @@
1
+ import type { RequestHandler } from 'express';
2
+ /**
3
+ * Development-only debug endpoint for monitoring memory usage and cache state.
4
+ *
5
+ * Mounts GET /debug/memory which returns:
6
+ * - Node.js process memory (heap, RSS, external, array buffers)
7
+ * - Graphile cache stats (size, max, TTL, keys with ages)
8
+ * - Service cache size
9
+ * - In-flight handler creation count
10
+ * - Process uptime
11
+ *
12
+ * This endpoint is only available when NODE_ENV=development.
13
+ * In production, it returns 404.
14
+ */
15
+ export declare const debugMemory: RequestHandler;
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.debugMemory = void 0;
4
+ const graphql_env_1 = require("@constructive-io/graphql-env");
5
+ const logger_1 = require("@pgpmjs/logger");
6
+ const server_utils_1 = require("@pgpmjs/server-utils");
7
+ const graphile_cache_1 = require("graphile-cache");
8
+ const graphile_1 = require("./graphile");
9
+ const log = new logger_1.Logger('debug-memory');
10
+ const toMB = (bytes) => `${(bytes / 1024 / 1024).toFixed(1)} MB`;
11
+ /**
12
+ * Development-only debug endpoint for monitoring memory usage and cache state.
13
+ *
14
+ * Mounts GET /debug/memory which returns:
15
+ * - Node.js process memory (heap, RSS, external, array buffers)
16
+ * - Graphile cache stats (size, max, TTL, keys with ages)
17
+ * - Service cache size
18
+ * - In-flight handler creation count
19
+ * - Process uptime
20
+ *
21
+ * This endpoint is only available when NODE_ENV=development.
22
+ * In production, it returns 404.
23
+ */
24
+ const debugMemory = (_req, res) => {
25
+ if ((0, graphql_env_1.getNodeEnv)() !== 'development') {
26
+ res.status(404).send('Not found');
27
+ return;
28
+ }
29
+ const mem = process.memoryUsage();
30
+ const cacheStats = (0, graphile_cache_1.getCacheStats)();
31
+ const response = {
32
+ memory: {
33
+ heapUsed: toMB(mem.heapUsed),
34
+ heapTotal: toMB(mem.heapTotal),
35
+ rss: toMB(mem.rss),
36
+ external: toMB(mem.external),
37
+ arrayBuffers: toMB(mem.arrayBuffers),
38
+ },
39
+ graphileCache: {
40
+ size: cacheStats.size,
41
+ max: cacheStats.max,
42
+ ttl: `${(cacheStats.ttl / 1000 / 60).toFixed(0)} min`,
43
+ keys: cacheStats.keys,
44
+ },
45
+ svcCache: {
46
+ size: server_utils_1.svcCache.size,
47
+ },
48
+ inFlight: {
49
+ count: (0, graphile_1.getInFlightCount)(),
50
+ keys: (0, graphile_1.getInFlightKeys)(),
51
+ },
52
+ uptime: `${(process.uptime() / 60).toFixed(1)} min`,
53
+ timestamp: new Date().toISOString(),
54
+ };
55
+ log.debug('Memory snapshot:', response);
56
+ res.json(response);
57
+ };
58
+ exports.debugMemory = debugMemory;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@constructive-io/graphql-server",
3
- "version": "4.3.3",
3
+ "version": "4.4.0",
4
4
  "author": "Constructive <developers@constructive.io>",
5
5
  "description": "Constructive GraphQL Server",
6
6
  "main": "index.js",
@@ -59,7 +59,7 @@
59
59
  "graphile-build-pg": "5.0.0-rc.5",
60
60
  "graphile-cache": "^3.1.0",
61
61
  "graphile-config": "1.0.0-rc.5",
62
- "graphile-settings": "^4.3.3",
62
+ "graphile-settings": "^4.4.0",
63
63
  "graphile-utils": "5.0.0-rc.5",
64
64
  "graphql": "^16.9.0",
65
65
  "graphql-upload": "^13.0.0",
@@ -82,10 +82,10 @@
82
82
  "@types/multer": "^1.4.12",
83
83
  "@types/pg": "^8.16.0",
84
84
  "@types/request-ip": "^0.0.41",
85
- "graphile-test": "4.2.3",
85
+ "graphile-test": "4.2.4",
86
86
  "makage": "^0.1.10",
87
87
  "nodemon": "^3.1.10",
88
88
  "ts-node": "^10.9.2"
89
89
  },
90
- "gitHead": "0deec313ff9af77b02cb749be9ef34e236e8cab8"
90
+ "gitHead": "c9364ffbc4d4a6b1b3750f0a5e347a7290d8d4ce"
91
91
  }
package/server.js CHANGED
@@ -23,6 +23,7 @@ const flush_1 = require("./middleware/flush");
23
23
  const graphile_1 = require("./middleware/graphile");
24
24
  const multipart_bridge_1 = require("./middleware/multipart-bridge");
25
25
  const upload_1 = require("./middleware/upload");
26
+ const debug_memory_1 = require("./middleware/debug-memory");
26
27
  const options_1 = require("./options");
27
28
  const log = new logger_1.Logger('server');
28
29
  /**
@@ -110,6 +111,7 @@ class Server {
110
111
  roleName: apiOpts.roleName,
111
112
  });
112
113
  (0, server_utils_1.healthz)(app);
114
+ app.get('/debug/memory', debug_memory_1.debugMemory);
113
115
  app.use(favicon_1.favicon);
114
116
  (0, server_utils_1.trustProxy)(app, effectiveOpts.server.trustProxy);
115
117
  // Warn if a global CORS override is set in production