Skip to content

Commit 50a037e

Browse files
dfallingclaude
andcommitted
Take schema path as codegen arg instead of committing it
Don't check in the GraphQL schema — this is a public repo and the full introspection shouldn't leak. `bun run codegen <path-or-url>` now passes the schema through to codegen.ts via process.argv. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 801e441 commit 50a037e

5 files changed

Lines changed: 23 additions & 36 deletions

File tree

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,7 @@ package-lock.json
4646
# Test coverage
4747
/coverage
4848

49-
# GraphQL — generated TS is committed; ignore introspection dumps
49+
# GraphQL — generated TS is committed; the schema itself is NOT (public repo,
50+
# don't leak full introspection). Pass its path/URL to `bun run codegen`.
5051
/schema.json
52+
/schema.graphql

README.md

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -148,21 +148,16 @@ Reload the app on device with `R` twice (emulator) or shake (physical device).
148148
## GraphQL codegen
149149

150150
Queries/mutations live alongside the code they're used in (`src/**/*.graphql`).
151-
The schema lives in `schema.graphql` at the repo root — currently a placeholder;
152-
replace it once the Phoenix API is reachable:
151+
The schema itself is **not** committed — this is a public repo, so we don't
152+
leak full introspection. Pass a path or URL as a positional arg:
153153

154154
```sh
155-
# from this directory, with the Phoenix server running:
155+
# dump SDL locally (gitignored) and point codegen at it:
156156
bunx get-graphql-schema http://localhost:4000/api/graphql > schema.graphql
157-
```
158-
159-
Or point `codegen.ts` directly at the URL — see the comment at the top of that file.
157+
bun run codegen ./schema.graphql
160158

161-
Generate types and React hooks:
162-
163-
```sh
164-
bun run codegen # one-shot
165-
bun run codegen:watch # rebuild on schema or .graphql changes
159+
# or hit the running endpoint directly:
160+
bun run codegen http://localhost:4000/api/graphql
166161
```
167162

168163
Output: `src/graphql/__generated__/types.ts` — committed to the repo. CI fails any
@@ -282,8 +277,7 @@ src/graphql/
282277
client.ts Apollo Client setup
283278
queries/*.graphql Operations
284279
__generated__/types.ts Codegen output (committed)
285-
schema.graphql GraphQL SDL (replace with backend's real schema)
286-
codegen.ts graphql-codegen config
280+
codegen.ts graphql-codegen config (schema path passed as arg)
287281
App.tsx Root component, wraps ApolloProvider
288282
biome.json Biome lint + format config
289283
mise.toml Toolchain versions (Node, Bun, JDK)

codegen.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
import type {CodegenConfig} from '@graphql-codegen/cli';
22

3-
// Point `schema` at your Phoenix GraphQL endpoint or a local SDL file.
4-
// For early development we use a checked-in placeholder schema. Once the
5-
// Phoenix API is reachable, swap this for the URL form, e.g.
6-
// schema: { 'http://localhost:4000/api/graphql': { headers: {} } }
3+
// Schema is not committed (public repo — don't leak full introspection).
4+
// Pass a path or URL as the last arg to `bun run codegen`:
5+
// bun run codegen ./schema.graphql
6+
// bun run codegen http://localhost:4000/api/graphql
7+
const schema = process.argv.find(
8+
(a, i) => i > 1 && !a.startsWith('-') && process.argv[i - 1] !== '--config',
9+
);
10+
if (!schema) {
11+
throw new Error('Usage: bun run codegen <path-or-url-to-schema>');
12+
}
13+
714
const config: CodegenConfig = {
815
overwrite: true,
9-
schema: 'schema.graphql',
16+
schema,
1017
documents: ['src/**/*.graphql', 'src/**/*.{ts,tsx}'],
1118
generates: {
1219
'src/graphql/__generated__/types.ts': {

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
"lint": "biome check",
1010
"lint:fix": "biome check --write",
1111
"format": "biome format --write",
12-
"codegen": "graphql-codegen --config codegen.ts",
13-
"codegen:watch": "graphql-codegen --config codegen.ts --watch"
12+
"codegen": "graphql-codegen --config codegen.ts"
1413
},
1514
"dependencies": {
1615
"react": "19.2.3",

schema.graphql

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)