Skip to content

Commit af2e099

Browse files
committed
feat(api): codegen for discussions
Signed-off-by: Adam Setch <[email protected]>
1 parent a2462cd commit af2e099

File tree

15 files changed

+39235
-128
lines changed

15 files changed

+39235
-128
lines changed

.env.template

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# GitHub Personal Access Token for GraphQL Codegen
2+
GITHUB_TOKEN=some-pat

.gitignore

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,15 @@ build/
55
# Dependency directories
66
node_modules/
77

8+
# Generated GraphQL Files
9+
schema.graphql
10+
811
# Coverage directory used by tools like istanbul
912
coverage
1013
*.lcov
1114

12-
# Logs
13-
logs
14-
*.log
15-
npm-debug.log*
16-
17-
# Optional npm cache directory
18-
.npm
19-
20-
# Temporary folders
21-
tmp/
22-
temp/
15+
# Environment properties
16+
.env
2317

2418
# Mac Files
2519
.DS_Store

codegen.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import type { CodegenConfig } from '@graphql-codegen/cli';
2+
import dotenv from 'dotenv';
3+
4+
dotenv.config();
5+
6+
const config: CodegenConfig = {
7+
overwrite: true,
8+
// Point the schema field to the GitHub GraphQL API endpoint
9+
schema: {
10+
'https://api.github.com/graphql': {
11+
// Add a custom header for authorization using your PAT
12+
headers: {
13+
Authorization: `Bearer ${process.env.GITHUB_TOKEN}`,
14+
'User-Agent': 'GraphQL-Codegen-GitHub-Integration', // GitHub recommends a User-Agent header
15+
},
16+
},
17+
},
18+
// Define where your application's GraphQL queries/mutations are located
19+
// documents: 'src/**/*.graphql',
20+
documents: [
21+
'src/renderer/utils/api/**/*.ts',
22+
'!src/renderer/utils/api/graphql/generated/**',
23+
'!src/renderer/utils/api/**/*.test.ts',
24+
],
25+
// Configure generated outputs and plugins
26+
generates: {
27+
'src/renderer/utils/api/graphql/generated/': {
28+
preset: 'client', // Or use specific plugins like 'typescript', 'typescript-operations'
29+
plugins: [],
30+
config: {
31+
documentMode: 'string',
32+
33+
// Additional plugin configuration, e.g. for scalars
34+
// scalars: {
35+
// DateTime: 'string',
36+
// URI: 'string',
37+
// GitTimestamp: 'string',
38+
// Html: 'string',
39+
// X509Certificate: 'string',
40+
// },
41+
},
42+
},
43+
'src/renderer/utils/api/graphql/generated/schema.graphql': {
44+
plugins: ['schema-ast'],
45+
config: {
46+
includeDirectives: true,
47+
},
48+
},
49+
},
50+
};
51+
52+
export default config;

package.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
"lint": "biome check --fix",
2121
"test": "jest",
2222
"start": "electron . --enable-logging",
23-
"prepare": "husky"
23+
"prepare": "husky",
24+
"codegen": "graphql-codegen --config codegen.ts"
2425
},
2526
"engines": {
2627
"node": ">=24"
@@ -79,6 +80,9 @@
7980
"@biomejs/biome": "2.3.8",
8081
"@discordapp/twemoji": "16.0.1",
8182
"@electron/notarize": "3.1.1",
83+
"@graphql-codegen/cli": "6.1.0",
84+
"@graphql-codegen/typescript": "5.0.6",
85+
"@graphql-codegen/typescript-operations": "5.0.6",
8286
"@primer/css": "22.0.2",
8387
"@primer/octicons-react": "19.21.1",
8488
"@primer/primitives": "11.3.1",
@@ -101,9 +105,11 @@
101105
"css-loader": "7.1.2",
102106
"css-minimizer-webpack-plugin": "7.0.3",
103107
"date-fns": "4.1.0",
108+
"dotenv": "17.2.3",
104109
"electron": "39.2.6",
105110
"electron-builder": "26.0.12",
106111
"final-form": "5.0.0",
112+
"graphql": "16.12.0",
107113
"graphql-tag": "2.12.6",
108114
"html-webpack-plugin": "5.6.5",
109115
"husky": "9.1.7",
@@ -141,4 +147,4 @@
141147
"*": "biome check --fix --no-errors-on-unmatched",
142148
"*.{js,ts,tsx}": "pnpm test --findRelatedTests --passWithNoTests --updateSnapshot"
143149
}
144-
}
150+
}

0 commit comments

Comments
 (0)