Skip to content

Commit b4bd930

Browse files
authored
Merge pull request #697 from constructive-io/feat/codegen-cleanup-trailing-commas
refactor(codegen): remove dead maxFieldDepth code and enforce trailing commas
2 parents 013a736 + 6cde977 commit b4bd930

215 files changed

Lines changed: 17156 additions & 14409 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Examples Integration
2+
on:
3+
pull_request:
4+
branches: [ main, v1 ]
5+
paths:
6+
- 'examples/**'
7+
- 'graphql/codegen/**'
8+
workflow_dispatch:
9+
10+
jobs:
11+
examples-types:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v4
15+
- uses: actions/setup-node@v4
16+
with:
17+
node-version: '20'
18+
- uses: pnpm/action-setup@v2
19+
with:
20+
version: 10
21+
- run: pnpm install
22+
- name: Build codegen and dependencies
23+
run: pnpm run build
24+
- run: pnpm -r --filter @constructive-io/examples-codegen-integration run test:codegen

CLAUDE.md

Lines changed: 81 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,22 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
55
## Build & Development Commands
66

77
```bash
8-
# Install dependencies
9-
pnpm install
10-
11-
# Build all packages
12-
pnpm build
13-
14-
# Build all packages (dev mode - faster, no optimizations)
15-
pnpm build:dev
16-
17-
# Lint all packages (auto-fix enabled)
18-
pnpm lint
19-
20-
# Clean build artifacts
21-
pnpm clean
22-
23-
# Update dependencies interactively
24-
pnpm deps
8+
pnpm install # Install dependencies
9+
pnpm build # Build all packages
10+
pnpm build:dev # Build all packages (dev mode - faster, no optimizations)
11+
pnpm lint # Lint all packages (auto-fix enabled)
12+
pnpm clean # Clean build artifacts
13+
pnpm deps # Update dependencies interactively (pnpm up -r -i -L)
2514
```
2615

2716
### Per-Package Commands
2817

29-
Navigate to any package directory (e.g., `cd pgpm/cli`) and run:
18+
From any package directory (e.g., `cd pgpm/cli`):
3019

3120
```bash
32-
pnpm build # Build the package
21+
pnpm build # Build the package (uses makage)
3322
pnpm lint # Lint with auto-fix
34-
pnpm test # Run tests
23+
pnpm test # Run tests (Jest)
3524
pnpm test:watch # Run tests in watch mode
3625
pnpm dev # Run in development mode (where available)
3726
```
@@ -41,54 +30,74 @@ pnpm dev # Run in development mode (where available)
4130
```bash
4231
cd packages/cli
4332
pnpm test -- path/to/test.test.ts
44-
# or with pattern matching:
4533
pnpm test -- --testNamePattern="test name pattern"
4634
```
4735

36+
### Publishing
37+
38+
Lerna with independent versioning and conventional commits. Publishing only from `main` branch:
39+
40+
```bash
41+
npx lerna version # Bump versions
42+
npx lerna publish # Publish to npm
43+
```
44+
4845
## Project Architecture
4946

50-
This is a **pnpm monorepo** using Lerna for versioning/publishing. The workspace is organized into domain-specific directories:
47+
A **pnpm monorepo** with Lerna for versioning. PostgreSQL-first framework: design your database schema, manage it with pgpm, and get a production-ready GraphQL API automatically via PostGraphile.
48+
49+
### Data Flow
50+
51+
```
52+
PostgreSQL (schema + RLS policies, managed by pgpm migrations)
53+
54+
PostGraphile (graphql/server + graphile/* plugins)
55+
56+
GraphQL Schema (auto-generated from database)
57+
58+
graphql/codegen (--react-query mode OR --orm mode)
59+
60+
React Query Hooks or Prisma-like ORM Client
61+
```
5162

52-
### Core Package Groups
63+
### Workspace Groups
5364

5465
| Directory | Purpose |
5566
|-----------|---------|
56-
| `pgpm/` | PostgreSQL Package Manager - CLI, core engine, types |
57-
| `graphql/` | GraphQL layer - server, codegen, React hooks, testing |
58-
| `graphile/` | PostGraphile plugins - filters, i18n, meta-schema, PostGIS |
59-
| `postgres/` | PostgreSQL utilities - introspection, testing, seeding, AST |
60-
| `packages/` | Shared utilities - CLI, ORM, query builder |
61-
| `uploads/` | File streaming - S3, ETags, content-type detection |
62-
| `jobs/` | Job scheduling and worker infrastructure |
67+
| `pgpm/` | PostgreSQL Package Manager - CLI (`pgpm`), core engine, types, env, logger |
68+
| `graphql/` | GraphQL layer - server, codegen, query builder, explorer, AST utilities |
69+
| `graphile/` | PostGraphile plugins - filters, i18n, meta-schema, PostGIS, search, uploads, settings |
70+
| `postgres/` | PostgreSQL utilities - introspection, testing (pgsql-test), seeding, AST, query context |
71+
| `packages/` | Shared utilities - CLI (`cnc`), ORM base, query builder, server utils, client |
72+
| `uploads/` | File streaming - S3/MinIO, ETags, content-type detection, UUID hashing |
73+
| `jobs/` | Knative job scheduling - worker, scheduler, service, functions |
74+
| `functions/` | Knative cloud functions (e.g., send-email-link) |
6375

64-
### Key Packages
76+
### Key Packages & CLIs
6577

66-
**pgpm (PostgreSQL Package Manager)**
67-
- `pgpm/cli` - Main CLI tool (`pgpm` command)
68-
- `pgpm/core` - Migration engine, dependency resolution, deployment
78+
**`pgpm` CLI** (`pgpm/cli`) - PostgreSQL Package Manager. Commands: `init`, `add`, `deploy`, `revert`, `verify`, `plan`, `install`, `export`, `docker`, `dump`, `tag`. Manages SQL migrations in Sqitch-compatible format with dependency resolution.
6979

70-
**GraphQL Stack**
71-
- `graphql/server` - Express + PostGraphile API server
72-
- `graphql/codegen` - SDK generator (React Query hooks or Prisma-like ORM)
73-
- `graphql/query` - Fluent GraphQL query builder
80+
**`cnc` CLI** (`packages/cli`, binary: `cnc` or `constructive`) - Full dev toolkit. Commands: `server` (start PostGraphile), `explorer` (GraphiQL UI), `codegen` (generate SDK), `get-graphql-schema`, `jobs`, `context`, `auth`, `execute`.
7481

75-
**Testing Infrastructure**
76-
- `postgres/pgsql-test` - Isolated PostgreSQL test environments with transaction rollback
77-
- `graphile/graphile-test` - GraphQL testing utilities
82+
**`graphql/codegen`** - Generates type-safe clients from GraphQL schema or endpoint:
83+
- `--react-query` mode: TanStack Query v5 hooks with query key factories
84+
- `--orm` mode: Prisma-like fluent API with `InferSelectResult<T, S>` type inference, discriminated union error handling (`.unwrap()`, `.unwrapOr()`)
85+
- Sources: GraphQL endpoint URL, .graphql schema file, or direct database introspection
7886

79-
### Testing Pattern
87+
**`graphql/server`** - Express + PostGraphile. Supports multi-endpoint routing via subdomain/host detection (schema builder with app-public/auth/admin sub-endpoints). Uses `LISTEN/NOTIFY` for schema cache invalidation.
8088

81-
Tests use `pgsql-test` for database testing with per-test transaction rollback:
89+
**`graphile/graphile-settings`** - Centralizes all PostGraphile plugin config: connection filters, full-text search, PostGIS, i18n, meta-schema, many-to-many, search, upload plugin. Single `getGraphileSettings(opts)` entry point.
8290

83-
```typescript
84-
import { getConnections } from 'pgsql-test';
91+
**`packages/query-builder`** - Fluent SQL query builder for SELECT/INSERT/UPDATE/DELETE with JOINs, WHERE, GROUP BY. Schema-qualified tables.
8592

86-
let db, teardown;
93+
### Testing Infrastructure
8794

88-
beforeAll(async () => {
89-
({ db, teardown } = await getConnections());
90-
});
95+
**`postgres/pgsql-test`** - Isolated PostgreSQL test environments with per-test transaction rollback:
9196

97+
```typescript
98+
import { getConnections } from 'pgsql-test';
99+
let db, teardown;
100+
beforeAll(async () => ({ db, teardown } = await getConnections()));
92101
beforeEach(() => db.beforeEach());
93102
afterEach(() => db.afterEach());
94103
afterAll(() => teardown());
@@ -100,26 +109,35 @@ test('example', async () => {
100109
});
101110
```
102111

112+
**`graphile/graphile-test`** - GraphQL testing with PostGraphile snapshot support.
113+
114+
### Job System
115+
116+
Background jobs use Knative: jobs are added to `app_jobs.jobs` table → `knative-job-worker` polls and picks up → POSTs to Knative function URL → function executes (e.g., send email) → returns status.
117+
103118
### Database Configuration
104119

105-
Tests require PostgreSQL. Standard PG environment variables:
106-
- `PGHOST` (default: localhost)
107-
- `PGPORT` (default: 5432)
108-
- `PGUSER` (default: postgres)
109-
- `PGPASSWORD` (default: password)
120+
Tests require PostgreSQL. Standard PG env vars:
121+
- `PGHOST` (default: localhost), `PGPORT` (default: 5432)
122+
- `PGUSER` (default: postgres), `PGPASSWORD` (default: password)
110123

111124
For S3/MinIO tests: `MINIO_ENDPOINT`, `AWS_ACCESS_KEY`, `AWS_SECRET_KEY`, `AWS_REGION`
112125

113-
### Build System
126+
## Build System
114127

115-
- Uses `makage` for TypeScript compilation (handles both CJS and ESM output)
116-
- Jest with ts-jest for testing
117-
- ESLint with TypeScript support
118-
- Each package has its own `tsconfig.json` extending root config
128+
- **makage** compiles TypeScript to both CJS and ESM, outputs to `dist/`
129+
- `makage build --dev` for faster dev builds
130+
- Some packages use `copyfiles` for non-TS assets (SQL files, templates)
131+
- Jest with `ts-jest` preset per-package (`jest.config.js` in each package)
119132

120-
### Code Conventions
133+
## Code Conventions
121134

122-
- TypeScript with `strict: true` (but `strictNullChecks: false`)
123-
- Target: ES2022, Module: CommonJS
124-
- Packages publish to npm from `dist/` directory
135+
- TypeScript with `strict: true` but `strictNullChecks: false`
136+
- Target: ES2022, Module: CommonJS, ModuleResolution: node
137+
- 2-space indent, single quotes, semicolons required, no trailing commas
138+
- Imports auto-sorted by `simple-import-sort`, unused imports auto-removed
139+
- `@typescript-eslint/no-explicit-any`: allowed (turned off)
140+
- Unused var pattern: prefix with `_` (e.g., `_unused`)
125141
- Workspace dependencies use `workspace:^` protocol
142+
- Packages publish from `dist/` directory
143+
- GraphQL pinned to `15.10.1` via overrides
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
src/generated/
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { defineConfig } from "@constructive-io/graphql-codegen";
2+
3+
export default defineConfig({
4+
endpoint: "http://example.local/graphql", // not used for fixture run
5+
output: "src/generated",
6+
reactQuery: true,
7+
orm: true,
8+
codegen: {
9+
maxFieldDepth: 2,
10+
skipQueryField: true
11+
},
12+
// Use the example schema fixtures baked into the repo
13+
schemaFile: "../../graphql/codegen/examples/example.schema.graphql"
14+
});
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "@constructive-io/examples-codegen-integration",
3+
"version": "0.0.0",
4+
"private": true,
5+
"scripts": {
6+
"codegen": "tsx scripts/codegen-runner.ts",
7+
"test:types": "pnpm run codegen && tsc --noEmit",
8+
"test:codegen": "pnpm run codegen"
9+
},
10+
"dependencies": {
11+
"@0no-co/graphql.web": "^1.2.0",
12+
"@tanstack/react-query": "^5.90.20",
13+
"gql-ast": "workspace:^",
14+
"graphql": "15.10.1",
15+
"react": "^19.2.3",
16+
"react-dom": "^19.2.3"
17+
},
18+
"devDependencies": {
19+
"@constructive-io/graphql-codegen": "workspace:^",
20+
"@constructive-io/graphql-types": "workspace:^",
21+
"tsx": "^4.20.3",
22+
"typescript": "^5.1.6"
23+
}
24+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import path from 'path';
2+
import { generate } from '../../../graphql/codegen/src/core/generate';
3+
4+
const root = path.resolve(__dirname, '..');
5+
6+
async function run() {
7+
const result = await generate({
8+
schemaFile: path.resolve(root, '../../graphql/codegen/examples/example.schema.graphql'),
9+
output: path.resolve(root, 'src/generated'),
10+
reactQuery: true,
11+
orm: true
12+
});
13+
14+
if (!result.success) {
15+
console.error(result.message);
16+
process.exit(1);
17+
}
18+
19+
console.log(result.message);
20+
}
21+
22+
run();
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Placeholder file so tsc has something to include
2+
export {};
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"compilerOptions": {
3+
"target": "ES2022",
4+
"module": "ESNext",
5+
"moduleResolution": "Bundler",
6+
"strict": true,
7+
"jsx": "react-jsx",
8+
"skipLibCheck": true,
9+
"noEmit": true,
10+
"baseUrl": ".",
11+
"paths": {}
12+
},
13+
"include": ["src", "codegen.config.ts"]
14+
}

functions/send-email-link/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"build:dev": "makage build --dev"
3131
},
3232
"devDependencies": {
33-
"makage": "^0.1.10"
33+
"makage": "^0.1.12"
3434
},
3535
"dependencies": {
3636
"@constructive-io/knative-job-fn": "workspace:^",

functions/simple-email/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"build:dev": "makage build --dev"
3131
},
3232
"devDependencies": {
33-
"makage": "^0.1.10"
33+
"makage": "^0.1.12"
3434
},
3535
"dependencies": {
3636
"@constructive-io/knative-job-fn": "workspace:^",

0 commit comments

Comments
 (0)