@constructive-io/graphql-env 3.37.7 → 3.38.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.
package/README.md CHANGED
@@ -91,6 +91,18 @@ PostgreSQL extensions or change the API's exposed schemas.
91
91
  Each cache limit must be a safe integer of at least `2`. When omitted, Grafast's
92
92
  upstream default for that cache remains in effect.
93
93
 
94
+ ### Schema Build Limits
95
+ - `GRAPHILE_BUILD_CONCURRENCY` - Handler builds that may run at once in the process (default `2`, at least `1`)
96
+ - `GRAPHILE_BUILD_QUEUE_MAX` - Builds that may wait for a slot (default `64`; `0` refuses at once while every slot is busy)
97
+ - `GRAPHILE_BUILD_QUEUE_WAIT_MS` - How long a build may wait for a slot (default `30000`; `0` never waits)
98
+
99
+ A request whose API has no cached handler waits for a build slot. When the
100
+ queue is full or the wait expires, the request is refused with HTTP 503, a
101
+ `Retry-After` header (the queue wait in seconds, at most 60) and the
102
+ `SCHEMA_BUILD_UNAVAILABLE` error code, so clients and load balancers can retry. A build that cannot reach the database is
103
+ answered the same way. Invalid values fail option resolution with the variable
104
+ name.
105
+
94
106
  ### Grafast Explain
95
107
  - `GRAPHILE_EXPLAIN` - Allow clients to request Grafast plan/SQL output via the `x-graphql-explain` header (off unless set)
96
108
 
@@ -0,0 +1,5 @@
1
+ import type { GraphileBuildLimits } from '@constructive-io/graphql-types';
2
+ /** Build limits set through `GRAPHILE_BUILD_*`; absent when none is set. */
3
+ export declare const getBuildLimitsEnv: (env: NodeJS.ProcessEnv) => GraphileBuildLimits | undefined;
4
+ /** Validate every configuration source before the bounds reach the server. */
5
+ export declare const normalizeGraphileBuildLimits: (limits: GraphileBuildLimits | undefined) => Readonly<GraphileBuildLimits> | undefined;
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.normalizeGraphileBuildLimits = exports.getBuildLimitsEnv = void 0;
4
+ const _12factor_env_1 = require("12factor-env");
5
+ const BOUNDS = {
6
+ concurrency: { min: 1, env: 'GRAPHILE_BUILD_CONCURRENCY' },
7
+ queueMax: { min: 0, env: 'GRAPHILE_BUILD_QUEUE_MAX' },
8
+ // setTimeout fires at once for longer delays, so a larger wait never waits.
9
+ queueWaitMs: { min: 0, max: 2_147_483_647, env: 'GRAPHILE_BUILD_QUEUE_WAIT_MS' }
10
+ };
11
+ const KEYS = Object.keys(BOUNDS);
12
+ const assertBuildLimit = (key, value, label) => {
13
+ const { min, max } = BOUNDS[key];
14
+ if (!Number.isSafeInteger(value) ||
15
+ value < min ||
16
+ (max !== undefined && value > max)) {
17
+ throw new Error(max === undefined
18
+ ? `${label} must be a safe integer of at least ${min}`
19
+ : `${label} must be an integer from ${min} to ${max}`);
20
+ }
21
+ return value;
22
+ };
23
+ /** Build limits set through `GRAPHILE_BUILD_*`; absent when none is set. */
24
+ const getBuildLimitsEnv = (env) => {
25
+ const limits = {};
26
+ for (const key of KEYS) {
27
+ const { env: name } = BOUNDS[key];
28
+ const raw = env[name];
29
+ if (raw !== undefined)
30
+ limits[key] = assertBuildLimit(key, (0, _12factor_env_1.parseEnvNumber)(raw), name);
31
+ }
32
+ return Object.keys(limits).length > 0 ? limits : undefined;
33
+ };
34
+ exports.getBuildLimitsEnv = getBuildLimitsEnv;
35
+ /** Validate every configuration source before the bounds reach the server. */
36
+ const normalizeGraphileBuildLimits = (limits) => {
37
+ if (limits === undefined)
38
+ return undefined;
39
+ if (typeof limits !== 'object' || limits === null || Array.isArray(limits)) {
40
+ throw new Error('graphile.buildLimits must be an object');
41
+ }
42
+ for (const key of Object.keys(limits)) {
43
+ if (!KEYS.includes(key)) {
44
+ throw new Error(`graphile.buildLimits contains unsupported setting '${key}'`);
45
+ }
46
+ }
47
+ const normalized = {};
48
+ for (const key of KEYS) {
49
+ const value = limits[key];
50
+ if (value !== undefined) {
51
+ normalized[key] = assertBuildLimit(key, value, `graphile.buildLimits.${key}`);
52
+ }
53
+ }
54
+ return Object.freeze(normalized);
55
+ };
56
+ exports.normalizeGraphileBuildLimits = normalizeGraphileBuildLimits;
package/env.js CHANGED
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getGraphQLEnvVars = void 0;
4
4
  const _12factor_env_1 = require("12factor-env");
5
+ const build_limits_1 = require("./build-limits");
5
6
  const grafast_cache_limits_1 = require("./grafast-cache-limits");
6
7
  const scoped_introspection_1 = require("./scoped-introspection");
7
8
  /**
@@ -9,6 +10,7 @@ const scoped_introspection_1 = require("./scoped-introspection");
9
10
  */
10
11
  const getGraphQLEnvVars = (env = process.env) => {
11
12
  const scopedIntrospection = (0, scoped_introspection_1.getScopedIntrospectionEnv)(env);
13
+ const buildLimits = (0, build_limits_1.getBuildLimitsEnv)(env);
12
14
  const { GRAPHILE_SCHEMA, GRAPHILE_EXPLAIN, GRAPHILE_GRAPHIQL, GRAPHILE_QUERY_CACHE_MAX_LENGTH, GRAPHILE_OPERATIONS_CACHE_MAX_LENGTH, GRAPHILE_OPERATION_PLANS_CACHE_MAX_LENGTH, FEATURES_SIMPLE_INFLECTION, FEATURES_OPPOSITE_BASE_NAMES, FEATURES_POSTGIS, API_IS_PUBLIC, API_EXPOSED_SCHEMAS, API_META_SCHEMAS, API_ANON_ROLE, API_ROLE_NAME, API_FLUSH_TOKEN, API_INTROSPECTION_ROLE, EMBEDDER_PROVIDER, EMBEDDER_MODEL, EMBEDDER_BASE_URL, CHAT_PROVIDER, CHAT_MODEL, CHAT_BASE_URL, SMS_PROVIDER, SMS_SENDER_ID, SMS_REQUEST_TIMEOUT_MS, SEND_SMS_DRY_RUN, DEVSMS_BASE_URL } = env;
13
15
  // Keep this function as a partial env-override parser. SMS runtime defaults
14
16
  // belong to the consuming application; injecting them here would incorrectly
@@ -42,6 +44,7 @@ const getGraphQLEnvVars = (env = process.env) => {
42
44
  operationOperationPlansCacheMaxLength: (0, grafast_cache_limits_1.parseGrafastCacheLimitEnv)(GRAPHILE_OPERATION_PLANS_CACHE_MAX_LENGTH, 'GRAPHILE_OPERATION_PLANS_CACHE_MAX_LENGTH')
43
45
  })
44
46
  }),
47
+ ...(buildLimits !== undefined && { buildLimits }),
45
48
  ...(GRAPHILE_EXPLAIN && { explain: (0, _12factor_env_1.parseEnvBoolean)(GRAPHILE_EXPLAIN) }),
46
49
  ...(graphiql !== undefined && { graphiql }),
47
50
  ...(GRAPHILE_SCHEMA && {
@@ -0,0 +1,5 @@
1
+ import type { GraphileBuildLimits } from '@constructive-io/graphql-types';
2
+ /** Build limits set through `GRAPHILE_BUILD_*`; absent when none is set. */
3
+ export declare const getBuildLimitsEnv: (env: NodeJS.ProcessEnv) => GraphileBuildLimits | undefined;
4
+ /** Validate every configuration source before the bounds reach the server. */
5
+ export declare const normalizeGraphileBuildLimits: (limits: GraphileBuildLimits | undefined) => Readonly<GraphileBuildLimits> | undefined;
@@ -0,0 +1,51 @@
1
+ import { parseEnvNumber } from '12factor-env';
2
+ const BOUNDS = {
3
+ concurrency: { min: 1, env: 'GRAPHILE_BUILD_CONCURRENCY' },
4
+ queueMax: { min: 0, env: 'GRAPHILE_BUILD_QUEUE_MAX' },
5
+ // setTimeout fires at once for longer delays, so a larger wait never waits.
6
+ queueWaitMs: { min: 0, max: 2_147_483_647, env: 'GRAPHILE_BUILD_QUEUE_WAIT_MS' }
7
+ };
8
+ const KEYS = Object.keys(BOUNDS);
9
+ const assertBuildLimit = (key, value, label) => {
10
+ const { min, max } = BOUNDS[key];
11
+ if (!Number.isSafeInteger(value) ||
12
+ value < min ||
13
+ (max !== undefined && value > max)) {
14
+ throw new Error(max === undefined
15
+ ? `${label} must be a safe integer of at least ${min}`
16
+ : `${label} must be an integer from ${min} to ${max}`);
17
+ }
18
+ return value;
19
+ };
20
+ /** Build limits set through `GRAPHILE_BUILD_*`; absent when none is set. */
21
+ export const getBuildLimitsEnv = (env) => {
22
+ const limits = {};
23
+ for (const key of KEYS) {
24
+ const { env: name } = BOUNDS[key];
25
+ const raw = env[name];
26
+ if (raw !== undefined)
27
+ limits[key] = assertBuildLimit(key, parseEnvNumber(raw), name);
28
+ }
29
+ return Object.keys(limits).length > 0 ? limits : undefined;
30
+ };
31
+ /** Validate every configuration source before the bounds reach the server. */
32
+ export const normalizeGraphileBuildLimits = (limits) => {
33
+ if (limits === undefined)
34
+ return undefined;
35
+ if (typeof limits !== 'object' || limits === null || Array.isArray(limits)) {
36
+ throw new Error('graphile.buildLimits must be an object');
37
+ }
38
+ for (const key of Object.keys(limits)) {
39
+ if (!KEYS.includes(key)) {
40
+ throw new Error(`graphile.buildLimits contains unsupported setting '${key}'`);
41
+ }
42
+ }
43
+ const normalized = {};
44
+ for (const key of KEYS) {
45
+ const value = limits[key];
46
+ if (value !== undefined) {
47
+ normalized[key] = assertBuildLimit(key, value, `graphile.buildLimits.${key}`);
48
+ }
49
+ }
50
+ return Object.freeze(normalized);
51
+ };
package/esm/env.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { parseEnvBoolean, parseEnvNumber } from '12factor-env';
2
+ import { getBuildLimitsEnv } from './build-limits';
2
3
  import { normalizeGrafastCacheLimits, parseGrafastCacheLimitEnv } from './grafast-cache-limits';
3
4
  import { getScopedIntrospectionEnv } from './scoped-introspection';
4
5
  /**
@@ -6,6 +7,7 @@ import { getScopedIntrospectionEnv } from './scoped-introspection';
6
7
  */
7
8
  export const getGraphQLEnvVars = (env = process.env) => {
8
9
  const scopedIntrospection = getScopedIntrospectionEnv(env);
10
+ const buildLimits = getBuildLimitsEnv(env);
9
11
  const { GRAPHILE_SCHEMA, GRAPHILE_EXPLAIN, GRAPHILE_GRAPHIQL, GRAPHILE_QUERY_CACHE_MAX_LENGTH, GRAPHILE_OPERATIONS_CACHE_MAX_LENGTH, GRAPHILE_OPERATION_PLANS_CACHE_MAX_LENGTH, FEATURES_SIMPLE_INFLECTION, FEATURES_OPPOSITE_BASE_NAMES, FEATURES_POSTGIS, API_IS_PUBLIC, API_EXPOSED_SCHEMAS, API_META_SCHEMAS, API_ANON_ROLE, API_ROLE_NAME, API_FLUSH_TOKEN, API_INTROSPECTION_ROLE, EMBEDDER_PROVIDER, EMBEDDER_MODEL, EMBEDDER_BASE_URL, CHAT_PROVIDER, CHAT_MODEL, CHAT_BASE_URL, SMS_PROVIDER, SMS_SENDER_ID, SMS_REQUEST_TIMEOUT_MS, SEND_SMS_DRY_RUN, DEVSMS_BASE_URL } = env;
10
12
  // Keep this function as a partial env-override parser. SMS runtime defaults
11
13
  // belong to the consuming application; injecting them here would incorrectly
@@ -39,6 +41,7 @@ export const getGraphQLEnvVars = (env = process.env) => {
39
41
  operationOperationPlansCacheMaxLength: parseGrafastCacheLimitEnv(GRAPHILE_OPERATION_PLANS_CACHE_MAX_LENGTH, 'GRAPHILE_OPERATION_PLANS_CACHE_MAX_LENGTH')
40
42
  })
41
43
  }),
44
+ ...(buildLimits !== undefined && { buildLimits }),
42
45
  ...(GRAPHILE_EXPLAIN && { explain: parseEnvBoolean(GRAPHILE_EXPLAIN) }),
43
46
  ...(graphiql !== undefined && { graphiql }),
44
47
  ...(GRAPHILE_SCHEMA && {
package/esm/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export { normalizeGraphileBuildLimits } from './build-limits';
1
2
  export { getGraphQLEnvVars } from './env';
2
3
  export { normalizeGrafastCacheLimits } from './grafast-cache-limits';
3
4
  export { getConstructiveEnvOptions, getEnvOptions } from './merge';
package/esm/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  // Export Constructive-specific env functions
2
+ export { normalizeGraphileBuildLimits } from './build-limits';
2
3
  export { getGraphQLEnvVars } from './env';
3
4
  export { normalizeGrafastCacheLimits } from './grafast-cache-limits';
4
5
  export { getConstructiveEnvOptions, getEnvOptions } from './merge';
package/esm/merge.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { constructiveGraphqlDefaults } from '@constructive-io/graphql-types';
2
2
  import { getEnvOptions as getPgpmEnvOptions, loadConfigSync, replaceArrays } from '@pgpmjs/env';
3
3
  import deepmerge from 'deepmerge';
4
+ import { normalizeGraphileBuildLimits } from './build-limits';
4
5
  import { getGraphQLEnvVars } from './env';
5
6
  import { normalizeGrafastCacheLimits } from './grafast-cache-limits';
6
7
  /**
@@ -47,6 +48,10 @@ export const getEnvOptions = (overrides = {}, cwd = process.cwd(), env = process
47
48
  if (grafastCache !== undefined && options.graphile) {
48
49
  options.graphile = { ...options.graphile, grafastCache };
49
50
  }
51
+ const buildLimits = normalizeGraphileBuildLimits(options.graphile?.buildLimits);
52
+ if (buildLimits !== undefined && options.graphile) {
53
+ options.graphile = { ...options.graphile, buildLimits };
54
+ }
50
55
  return options;
51
56
  };
52
57
  /**
package/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export { normalizeGraphileBuildLimits } from './build-limits';
1
2
  export { getGraphQLEnvVars } from './env';
2
3
  export { normalizeGrafastCacheLimits } from './grafast-cache-limits';
3
4
  export { getConstructiveEnvOptions, getEnvOptions } from './merge';
package/index.js CHANGED
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getEnvOptions = exports.getConstructiveEnvOptions = exports.normalizeGrafastCacheLimits = exports.getGraphQLEnvVars = void 0;
3
+ exports.getEnvOptions = exports.getConstructiveEnvOptions = exports.normalizeGrafastCacheLimits = exports.getGraphQLEnvVars = exports.normalizeGraphileBuildLimits = void 0;
4
4
  // Export Constructive-specific env functions
5
+ var build_limits_1 = require("./build-limits");
6
+ Object.defineProperty(exports, "normalizeGraphileBuildLimits", { enumerable: true, get: function () { return build_limits_1.normalizeGraphileBuildLimits; } });
5
7
  var env_1 = require("./env");
6
8
  Object.defineProperty(exports, "getGraphQLEnvVars", { enumerable: true, get: function () { return env_1.getGraphQLEnvVars; } });
7
9
  var grafast_cache_limits_1 = require("./grafast-cache-limits");
package/merge.js CHANGED
@@ -7,6 +7,7 @@ exports.getConstructiveEnvOptions = exports.getEnvOptions = void 0;
7
7
  const graphql_types_1 = require("@constructive-io/graphql-types");
8
8
  const env_1 = require("@pgpmjs/env");
9
9
  const deepmerge_1 = __importDefault(require("deepmerge"));
10
+ const build_limits_1 = require("./build-limits");
10
11
  const env_2 = require("./env");
11
12
  const grafast_cache_limits_1 = require("./grafast-cache-limits");
12
13
  /**
@@ -53,6 +54,10 @@ const getEnvOptions = (overrides = {}, cwd = process.cwd(), env = process.env) =
53
54
  if (grafastCache !== undefined && options.graphile) {
54
55
  options.graphile = { ...options.graphile, grafastCache };
55
56
  }
57
+ const buildLimits = (0, build_limits_1.normalizeGraphileBuildLimits)(options.graphile?.buildLimits);
58
+ if (buildLimits !== undefined && options.graphile) {
59
+ options.graphile = { ...options.graphile, buildLimits };
60
+ }
56
61
  return options;
57
62
  };
58
63
  exports.getEnvOptions = getEnvOptions;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@constructive-io/graphql-env",
3
- "version": "3.37.7",
3
+ "version": "3.38.0",
4
4
  "author": "Constructive <developers@constructive.io>",
5
5
  "description": "Constructive environment configuration with GraphQL/Graphile support",
6
6
  "main": "index.js",
@@ -21,9 +21,9 @@
21
21
  },
22
22
  "dependencies": {
23
23
  "deepmerge": "^4.3.1",
24
- "@constructive-io/graphql-types": "^3.36.6",
25
- "@pgpmjs/env": "^2.48.5",
26
- "12factor-env": "^1.34.1"
24
+ "12factor-env": "^1.34.1",
25
+ "@constructive-io/graphql-types": "^3.37.0",
26
+ "@pgpmjs/env": "^2.49.0"
27
27
  },
28
28
  "keywords": [
29
29
  "env",