Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions graphile/graphile-settings/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@
"test": "jest",
"test:watch": "jest --watch"
},
"dependencies": {
"@graphile-contrib/pg-many-to-many": "^1.0.2",
"@pgpmjs/env": "workspace:^",
"dependencies": {
"@graphile-contrib/pg-many-to-many": "^1.0.2",
"@launchql/env": "workspace:^",
"@launchql/types": "workspace:^",
"@pgpmjs/types": "workspace:^",
"cors": "^2.8.5",
"express": "^5.1.0",
Expand Down
6 changes: 3 additions & 3 deletions graphile/graphile-settings/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import PgManyToMany from '@graphile-contrib/pg-many-to-many';
import { getEnvOptions } from '@pgpmjs/env';
import { PgpmOptions } from '@pgpmjs/types';
import { getEnvOptions } from '@launchql/env';
import { LaunchQLOptions } from '@launchql/types';
import PgPostgis from 'graphile-postgis';
import FulltextFilterPlugin from 'graphile-plugin-fulltext-filter';
import { NodePlugin, Plugin } from 'graphile-build';
Expand All @@ -19,7 +19,7 @@ import CustomPgTypeMappingsPlugin from 'graphile-pg-type-mappings';
import UploadPostGraphilePlugin, { Uploader } from 'graphile-upload-plugin';

export const getGraphileSettings = (
rawOpts: PgpmOptions
rawOpts: LaunchQLOptions
): PostGraphileOptions => {
const opts = getEnvOptions(rawOpts);

Expand Down
6 changes: 4 additions & 2 deletions graphile/graphile-test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@
"graphql-tag": "2.12.6",
"makage": "^0.1.8"
},
"dependencies": {
"@pgpmjs/types": "workspace:^",
"dependencies": {
"@launchql/env": "workspace:^",
"@launchql/types": "workspace:^",
"@pgpmjs/types": "workspace:^",
"graphql": "15.10.1",
"mock-req": "^0.2.0",
"pg": "^8.16.3",
Expand Down
2 changes: 1 addition & 1 deletion graphile/graphile-test/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { GraphileOptions } from '@pgpmjs/types';
import type { GraphileOptions } from '@launchql/types';
import { DocumentNode, GraphQLError } from 'graphql';

export interface GraphQLQueryOptions<TVariables = Record<string, any>> {
Expand Down
2 changes: 1 addition & 1 deletion graphile/graphile-upload-plugin/__tests__/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { join } from 'path';
import { createReadStream, writeFileSync, unlinkSync } from 'fs';
import { tmpdir } from 'os';
import { S3Client } from '@aws-sdk/client-s3';
import { getEnvOptions } from '@pgpmjs/env';
import { getEnvOptions } from '@launchql/env';
import { createS3Bucket } from '@launchql/s3-utils';
import { getConnections, snapshot, seed } from 'graphile-test';
import type { PgTestClient } from 'pgsql-test/test-client';
Expand Down
8 changes: 4 additions & 4 deletions graphile/graphile-upload-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@
"bugs": {
"url": "https://github.com/constructive-io/constructive/issues"
},
"devDependencies": {
"@aws-sdk/client-s3": "^3.948.0",
"@launchql/s3-utils": "workspace:^",
"@pgpmjs/env": "workspace:^",
"devDependencies": {
"@aws-sdk/client-s3": "^3.948.0",
"@launchql/env": "workspace:^",
"@launchql/s3-utils": "workspace:^",
"@types/pg": "^8.16.0",
"graphile-test": "workspace:^",
"graphql-tag": "^2.12.6",
Expand Down
12 changes: 6 additions & 6 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@
"pg": "^8.16.3",
"ts-node": "^10.9.2"
},
"dependencies": {
"@launchql/codegen": "workspace:^",
"@launchql/explorer": "workspace:^",
"@launchql/server": "workspace:^",
"@pgpmjs/core": "workspace:^",
"@pgpmjs/env": "workspace:^",
"dependencies": {
"@launchql/codegen": "workspace:^",
"@launchql/env": "workspace:^",
"@launchql/explorer": "workspace:^",
"@launchql/server": "workspace:^",
"@pgpmjs/core": "workspace:^",
"@pgpmjs/logger": "workspace:^",
"@pgpmjs/server-utils": "workspace:^",
"@pgpmjs/types": "workspace:^",
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/explorer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getEnvOptions } from '@pgpmjs/env';
import { getEnvOptions } from '@launchql/env';
import { LaunchQLExplorer as explorer } from '@launchql/explorer';
import { Logger } from '@pgpmjs/logger';
import { PgpmOptions } from '@pgpmjs/types';
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/server.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getEnvOptions } from '@pgpmjs/env';
import { getEnvOptions } from '@launchql/env';
import { Logger } from '@pgpmjs/logger';
import { LaunchQLServer as server } from '@launchql/server';
import { PgpmOptions } from '@pgpmjs/types';
Expand Down
38 changes: 4 additions & 34 deletions packages/env/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ const parseEnvBoolean = (val?: string): boolean | undefined => {
return ['true', '1', 'yes'].includes(val.toLowerCase());
};

/**
* Parse core PGPM environment variables.
* GraphQL-related env vars (GRAPHILE_*, FEATURES_*, API_*) are handled by @launchql/env.
*/
export const getEnvVars = (): PgpmOptions => {
const {
PGROOTDATABASE,
Expand All @@ -33,19 +37,6 @@ export const getEnvVars = (): PgpmOptions => {
PGPASSWORD,
PGDATABASE,

GRAPHILE_SCHEMA,

FEATURES_SIMPLE_INFLECTION,
FEATURES_OPPOSITE_BASE_NAMES,
FEATURES_POSTGIS,
API_ENABLE_META,
API_IS_PUBLIC,
API_EXPOSED_SCHEMAS,
API_META_SCHEMAS,
API_ANON_ROLE,
API_ROLE_NAME,
API_DEFAULT_DATABASE_ID,

BUCKET_NAME,
AWS_REGION,
AWS_ACCESS_KEY,
Expand Down Expand Up @@ -90,27 +81,6 @@ export const getEnvVars = (): PgpmOptions => {
...(PGPASSWORD && { password: PGPASSWORD }),
...(PGDATABASE && { database: PGDATABASE }),
},
graphile: {
...(GRAPHILE_SCHEMA && {
schema: GRAPHILE_SCHEMA.includes(',')
? GRAPHILE_SCHEMA.split(',').map(s => s.trim())
: GRAPHILE_SCHEMA
}),
},
features: {
...(FEATURES_SIMPLE_INFLECTION && { simpleInflection: parseEnvBoolean(FEATURES_SIMPLE_INFLECTION) }),
...(FEATURES_OPPOSITE_BASE_NAMES && { oppositeBaseNames: parseEnvBoolean(FEATURES_OPPOSITE_BASE_NAMES) }),
...(FEATURES_POSTGIS && { postgis: parseEnvBoolean(FEATURES_POSTGIS) }),
},
api: {
...(API_ENABLE_META && { enableMetaApi: parseEnvBoolean(API_ENABLE_META) }),
...(API_IS_PUBLIC && { isPublic: parseEnvBoolean(API_IS_PUBLIC) }),
...(API_EXPOSED_SCHEMAS && { exposedSchemas: API_EXPOSED_SCHEMAS.split(',').map(s => s.trim()) }),
...(API_META_SCHEMAS && { metaSchemas: API_META_SCHEMAS.split(',').map(s => s.trim()) }),
...(API_ANON_ROLE && { anonRole: API_ANON_ROLE }),
...(API_ROLE_NAME && { roleName: API_ROLE_NAME }),
...(API_DEFAULT_DATABASE_ID && { defaultDatabaseId: API_DEFAULT_DATABASE_ID }),
},
cdn: {
...(BUCKET_NAME && { bucketName: BUCKET_NAME }),
...(AWS_REGION && { awsRegion: AWS_REGION }),
Expand Down
12 changes: 10 additions & 2 deletions packages/env/src/merge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,20 @@ import { pgpmDefaults, PgpmOptions, PgTestConnectionOptions, DeploymentOptions }
import { loadConfigSync } from './config';
import { getEnvVars } from './env';

/**
* Get core PGPM environment options by merging:
* 1. PGPM defaults
* 2. Config file options
* 3. Environment variables
* 4. Runtime overrides
*
* For LaunchQL applications that need GraphQL options, use @launchql/env instead.
*/
export const getEnvOptions = (overrides: PgpmOptions = {}, cwd: string = process.cwd()): PgpmOptions => {
const defaults = pgpmDefaults;
const configOptions = loadConfigSync(cwd);
const envOptions = getEnvVars();

return deepmerge.all([defaults, configOptions, envOptions, overrides]);
return deepmerge.all([pgpmDefaults, configOptions, envOptions, overrides]);
};

export const getConnEnvOptions = (overrides: Partial<PgTestConnectionOptions> = {}, cwd: string = process.cwd()): PgTestConnectionOptions => {
Expand Down
11 changes: 6 additions & 5 deletions packages/explorer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@
"test": "jest",
"test:watch": "jest --watch"
},
"dependencies": {
"@launchql/s3-streamer": "workspace:^",
"@launchql/upload-names": "workspace:^",
"@launchql/url-domains": "workspace:^",
"@pgpmjs/env": "workspace:^",
"dependencies": {
"@launchql/env": "workspace:^",
"@launchql/s3-streamer": "workspace:^",
"@launchql/types": "workspace:^",
"@launchql/upload-names": "workspace:^",
"@launchql/url-domains": "workspace:^",
"@pgpmjs/server-utils": "workspace:^",
"@pgpmjs/types": "workspace:^",
"express": "^5.1.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/explorer/src/run.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env node

import { getEnvOptions } from '@pgpmjs/env';
import { getEnvOptions } from '@launchql/env';

import { LaunchQLExplorer as server } from './server';

Expand Down
2 changes: 1 addition & 1 deletion packages/explorer/src/server.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getEnvOptions } from '@pgpmjs/env';
import { getEnvOptions } from '@launchql/env';
import { cors, healthz, poweredBy } from '@pgpmjs/server-utils';
import { PgpmOptions } from '@pgpmjs/types';
import { middleware as parseDomains } from '@launchql/url-domains';
Expand Down
6 changes: 3 additions & 3 deletions packages/explorer/src/settings.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { PgpmOptions } from '@pgpmjs/types';
import { getEnvOptions } from '@pgpmjs/env';
import { LaunchQLOptions } from '@launchql/types';
import { getEnvOptions } from '@launchql/env';
import { getGraphileSettings as getSettings } from 'graphile-settings';
import { PostGraphileOptions } from 'postgraphile';

export const getGraphileSettings = (rawOpts: PgpmOptions): PostGraphileOptions => {
export const getGraphileSettings = (rawOpts: LaunchQLOptions): PostGraphileOptions => {
const opts = getEnvOptions(rawOpts);

const baseOptions = getSettings(opts);
Expand Down
76 changes: 76 additions & 0 deletions packages/launchql-env/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# @launchql/env

LaunchQL environment configuration with GraphQL/Graphile support.

This package extends `@pgpmjs/env` with GraphQL-specific environment variable parsing and defaults for LaunchQL applications.

## Installation

```bash
npm install @launchql/env
```

## Usage

```typescript
import { getEnvOptions } from '@launchql/env';

// Get merged options (core PGPM + GraphQL defaults + env vars + config)
const options = getEnvOptions();

// With overrides
const options = getEnvOptions({
graphile: { schema: ['public', 'app'] },
features: { simpleInflection: true }
});
```

## Environment Variables

In addition to all environment variables supported by `@pgpmjs/env`, this package parses:

### GraphQL Schema
- `GRAPHILE_SCHEMA` - Comma-separated list of PostgreSQL schemas to expose

### Feature Flags
- `FEATURES_SIMPLE_INFLECTION` - Enable simple inflection plugin
- `FEATURES_OPPOSITE_BASE_NAMES` - Enable opposite base names
- `FEATURES_POSTGIS` - Enable PostGIS support

### API Configuration
- `API_ENABLE_META` - Enable meta API
- `API_IS_PUBLIC` - Whether API is public
- `API_EXPOSED_SCHEMAS` - Comma-separated list of exposed schemas
- `API_META_SCHEMAS` - Comma-separated list of meta schemas
- `API_ANON_ROLE` - Anonymous role name
- `API_ROLE_NAME` - Default role name
- `API_DEFAULT_DATABASE_ID` - Default database ID

## Defaults

GraphQL defaults are provided by `@launchql/types`:

```typescript
{
graphile: { schema: [] },
features: {
simpleInflection: true,
oppositeBaseNames: true,
postgis: true
},
api: {
enableMetaApi: true,
exposedSchemas: [],
anonRole: 'administrator',
roleName: 'administrator',
defaultDatabaseId: 'hard-coded',
isPublic: true,
metaSchemas: ['collections_public', 'meta_public']
}
}
```

## When to Use

- Use `@launchql/env` for LaunchQL applications that need GraphQL/Graphile configuration
- Use `@pgpmjs/env` for pure PGPM tooling that doesn't need GraphQL support
47 changes: 47 additions & 0 deletions packages/launchql-env/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"name": "@launchql/env",
"version": "2.7.0",
"author": "Constructive <developers@constructive.io>",
"description": "LaunchQL environment configuration with GraphQL/Graphile support",
"main": "index.js",
"module": "esm/index.js",
"types": "index.d.ts",
"homepage": "https://github.com/constructive-io/constructive",
"license": "MIT",
"publishConfig": {
"access": "public",
"directory": "dist"
},
"repository": {
"type": "git",
"url": "https://github.com/constructive-io/constructive"
},
"bugs": {
"url": "https://github.com/constructive-io/constructive/issues"
},
"scripts": {
"clean": "makage clean",
"prepack": "npm run build",
"build": "makage build",
"build:dev": "makage build --dev",
"lint": "eslint . --fix",
"test": "jest",
"test:watch": "jest --watch"
},
"dependencies": {
"@launchql/types": "workspace:^",
"@pgpmjs/env": "workspace:^",
"deepmerge": "^4.3.1"
},
"keywords": [
"env",
"environment",
"config",
"launchql",
"graphql",
"postgraphile"
],
"devDependencies": {
"makage": "^0.1.8"
}
}
Loading