Skip to content

Commit 32758e5

Browse files
committed
feat: create @launchql/env package for complete GraphQL separation
- Create new @launchql/env package that handles GraphQL env parsing and defaults - Strip GraphQL env vars from @pgpmjs/env (GRAPHILE_*, FEATURES_*, API_*) - Update @pgpmjs/env to return only core PgpmOptions (no GraphQL fields) - Update all LaunchQL consumers to use @launchql/env: - packages/server, explorer, cli - graphile/graphile-settings, graphile-test, graphile-upload-plugin - packages/launchql-test - @launchql/env exports getEnvOptions() that merges core + GraphQL options - Re-exports getNodeEnv and other utilities from @pgpmjs/env for convenience This completes the architectural separation where: - @pgpmjs/types + @pgpmjs/env = core PGPM (zero GraphQL deps) - @launchql/types + @launchql/env = LaunchQL (GraphQL features) Co-Authored-By: Dan Lynch <pyramation@gmail.com>
1 parent 59cc09d commit 32758e5

28 files changed

Lines changed: 357 additions & 155 deletions

File tree

graphile/graphile-settings/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@
2828
"test": "jest",
2929
"test:watch": "jest --watch"
3030
},
31-
"dependencies": {
32-
"@graphile-contrib/pg-many-to-many": "^1.0.2",
33-
"@launchql/types": "workspace:^",
34-
"@pgpmjs/env": "workspace:^",
31+
"dependencies": {
32+
"@graphile-contrib/pg-many-to-many": "^1.0.2",
33+
"@launchql/env": "workspace:^",
34+
"@launchql/types": "workspace:^",
3535
"@pgpmjs/types": "workspace:^",
3636
"cors": "^2.8.5",
3737
"express": "^5.1.0",

graphile/graphile-settings/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import PgManyToMany from '@graphile-contrib/pg-many-to-many';
2-
import { getEnvOptions } from '@pgpmjs/env';
2+
import { getEnvOptions } from '@launchql/env';
33
import { LaunchQLOptions } from '@launchql/types';
44
import PgPostgis from 'graphile-postgis';
55
import FulltextFilterPlugin from 'graphile-plugin-fulltext-filter';

graphile/graphile-test/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@
3333
"graphql-tag": "2.12.6",
3434
"makage": "^0.1.8"
3535
},
36-
"dependencies": {
37-
"@launchql/types": "workspace:^",
38-
"@pgpmjs/types": "workspace:^",
36+
"dependencies": {
37+
"@launchql/env": "workspace:^",
38+
"@launchql/types": "workspace:^",
39+
"@pgpmjs/types": "workspace:^",
3940
"graphql": "15.10.1",
4041
"mock-req": "^0.2.0",
4142
"pg": "^8.16.3",

graphile/graphile-upload-plugin/__tests__/plugin.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { join } from 'path';
33
import { createReadStream, writeFileSync, unlinkSync } from 'fs';
44
import { tmpdir } from 'os';
55
import { S3Client } from '@aws-sdk/client-s3';
6-
import { getEnvOptions } from '@pgpmjs/env';
6+
import { getEnvOptions } from '@launchql/env';
77
import { createS3Bucket } from '@launchql/s3-utils';
88
import { getConnections, snapshot, seed } from 'graphile-test';
99
import type { PgTestClient } from 'pgsql-test/test-client';

graphile/graphile-upload-plugin/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@
3737
"bugs": {
3838
"url": "https://github.com/constructive-io/constructive/issues"
3939
},
40-
"devDependencies": {
41-
"@aws-sdk/client-s3": "^3.948.0",
42-
"@launchql/s3-utils": "workspace:^",
43-
"@pgpmjs/env": "workspace:^",
40+
"devDependencies": {
41+
"@aws-sdk/client-s3": "^3.948.0",
42+
"@launchql/env": "workspace:^",
43+
"@launchql/s3-utils": "workspace:^",
4444
"@types/pg": "^8.16.0",
4545
"graphile-test": "workspace:^",
4646
"graphql-tag": "^2.12.6",

packages/cli/package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@
4545
"pg": "^8.16.3",
4646
"ts-node": "^10.9.2"
4747
},
48-
"dependencies": {
49-
"@launchql/codegen": "workspace:^",
50-
"@launchql/explorer": "workspace:^",
51-
"@launchql/server": "workspace:^",
52-
"@pgpmjs/core": "workspace:^",
53-
"@pgpmjs/env": "workspace:^",
48+
"dependencies": {
49+
"@launchql/codegen": "workspace:^",
50+
"@launchql/env": "workspace:^",
51+
"@launchql/explorer": "workspace:^",
52+
"@launchql/server": "workspace:^",
53+
"@pgpmjs/core": "workspace:^",
5454
"@pgpmjs/logger": "workspace:^",
5555
"@pgpmjs/server-utils": "workspace:^",
5656
"@pgpmjs/types": "workspace:^",

packages/cli/src/commands/explorer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getEnvOptions } from '@pgpmjs/env';
1+
import { getEnvOptions } from '@launchql/env';
22
import { LaunchQLExplorer as explorer } from '@launchql/explorer';
33
import { Logger } from '@pgpmjs/logger';
44
import { PgpmOptions } from '@pgpmjs/types';

packages/cli/src/commands/server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getEnvOptions } from '@pgpmjs/env';
1+
import { getEnvOptions } from '@launchql/env';
22
import { Logger } from '@pgpmjs/logger';
33
import { LaunchQLServer as server } from '@launchql/server';
44
import { PgpmOptions } from '@pgpmjs/types';

packages/env/src/env.ts

Lines changed: 5 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,5 @@
11
import { PgpmOptions } from '@pgpmjs/types';
22

3-
/**
4-
* Extended env options that include GraphQL-related fields.
5-
* These fields are parsed from environment variables but typed separately
6-
* to avoid coupling @pgpmjs/types to GraphQL dependencies.
7-
*
8-
* For full type safety with GraphQL options, use LaunchQLOptions from @launchql/types
9-
*/
10-
export interface EnvGraphQLOptions {
11-
graphile?: {
12-
schema?: string | string[];
13-
};
14-
features?: {
15-
simpleInflection?: boolean;
16-
oppositeBaseNames?: boolean;
17-
postgis?: boolean;
18-
};
19-
api?: {
20-
enableMetaApi?: boolean;
21-
isPublic?: boolean;
22-
exposedSchemas?: string[];
23-
metaSchemas?: string[];
24-
anonRole?: string;
25-
roleName?: string;
26-
defaultDatabaseId?: string;
27-
};
28-
}
29-
30-
/**
31-
* Combined environment options type that includes both PGPM core options
32-
* and GraphQL-related options parsed from environment variables.
33-
*/
34-
export type EnvOptions = PgpmOptions & EnvGraphQLOptions;
35-
363
const parseEnvNumber = (val?: string): number | undefined => {
374
const num = Number(val);
385
return !isNaN(num) ? num : undefined;
@@ -43,7 +10,11 @@ const parseEnvBoolean = (val?: string): boolean | undefined => {
4310
return ['true', '1', 'yes'].includes(val.toLowerCase());
4411
};
4512

46-
export const getEnvVars = (): EnvOptions => {
13+
/**
14+
* Parse core PGPM environment variables.
15+
* GraphQL-related env vars (GRAPHILE_*, FEATURES_*, API_*) are handled by @launchql/env.
16+
*/
17+
export const getEnvVars = (): PgpmOptions => {
4718
const {
4819
PGROOTDATABASE,
4920
PGTEMPLATE,
@@ -66,19 +37,6 @@ export const getEnvVars = (): EnvOptions => {
6637
PGPASSWORD,
6738
PGDATABASE,
6839

69-
GRAPHILE_SCHEMA,
70-
71-
FEATURES_SIMPLE_INFLECTION,
72-
FEATURES_OPPOSITE_BASE_NAMES,
73-
FEATURES_POSTGIS,
74-
API_ENABLE_META,
75-
API_IS_PUBLIC,
76-
API_EXPOSED_SCHEMAS,
77-
API_META_SCHEMAS,
78-
API_ANON_ROLE,
79-
API_ROLE_NAME,
80-
API_DEFAULT_DATABASE_ID,
81-
8240
BUCKET_NAME,
8341
AWS_REGION,
8442
AWS_ACCESS_KEY,
@@ -123,27 +81,6 @@ export const getEnvVars = (): EnvOptions => {
12381
...(PGPASSWORD && { password: PGPASSWORD }),
12482
...(PGDATABASE && { database: PGDATABASE }),
12583
},
126-
graphile: {
127-
...(GRAPHILE_SCHEMA && {
128-
schema: GRAPHILE_SCHEMA.includes(',')
129-
? GRAPHILE_SCHEMA.split(',').map(s => s.trim())
130-
: GRAPHILE_SCHEMA
131-
}),
132-
},
133-
features: {
134-
...(FEATURES_SIMPLE_INFLECTION && { simpleInflection: parseEnvBoolean(FEATURES_SIMPLE_INFLECTION) }),
135-
...(FEATURES_OPPOSITE_BASE_NAMES && { oppositeBaseNames: parseEnvBoolean(FEATURES_OPPOSITE_BASE_NAMES) }),
136-
...(FEATURES_POSTGIS && { postgis: parseEnvBoolean(FEATURES_POSTGIS) }),
137-
},
138-
api: {
139-
...(API_ENABLE_META && { enableMetaApi: parseEnvBoolean(API_ENABLE_META) }),
140-
...(API_IS_PUBLIC && { isPublic: parseEnvBoolean(API_IS_PUBLIC) }),
141-
...(API_EXPOSED_SCHEMAS && { exposedSchemas: API_EXPOSED_SCHEMAS.split(',').map(s => s.trim()) }),
142-
...(API_META_SCHEMAS && { metaSchemas: API_META_SCHEMAS.split(',').map(s => s.trim()) }),
143-
...(API_ANON_ROLE && { anonRole: API_ANON_ROLE }),
144-
...(API_ROLE_NAME && { roleName: API_ROLE_NAME }),
145-
...(API_DEFAULT_DATABASE_ID && { defaultDatabaseId: API_DEFAULT_DATABASE_ID }),
146-
},
14784
cdn: {
14885
...(BUCKET_NAME && { bucketName: BUCKET_NAME }),
14986
...(AWS_REGION && { awsRegion: AWS_REGION }),

packages/env/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,3 @@ export { getEnvVars, getNodeEnv } from './env';
44
export { walkUp } from './utils';
55

66
export type { PgpmOptions, PgTestConnectionOptions, DeploymentOptions } from '@pgpmjs/types';
7-
export type { EnvOptions, EnvGraphQLOptions } from './env';

0 commit comments

Comments
 (0)