Skip to content

Commit 2818607

Browse files
authored
feat(api): simplify discussions enrichment and use graphql-codegen for types (#2444)
* feat(api): codegen for discussions Signed-off-by: Adam Setch <[email protected]> * feat(api): codegen for discussions Signed-off-by: Adam Setch <[email protected]> * feat(api): codegen for discussions Signed-off-by: Adam Setch <[email protected]> * feat(api): codegen for discussions Signed-off-by: Adam Setch <[email protected]> * feat(api): codegen for discussions Signed-off-by: Adam Setch <[email protected]> * feat(api): codegen for discussions Signed-off-by: Adam Setch <[email protected]> * Merge branch 'main' into feat/codegen-discussions Signed-off-by: Adam Setch <[email protected]> * feat(api): codegen for discussions Signed-off-by: Adam Setch <[email protected]> * feat(api): codegen for discussions Signed-off-by: Adam Setch <[email protected]> * feat(api): codegen for discussions Signed-off-by: Adam Setch <[email protected]> * feat(api): codegen for discussions Signed-off-by: Adam Setch <[email protected]> * feat(api): codegen for discussions Signed-off-by: Adam Setch <[email protected]> * feat(api): codegen for discussions Signed-off-by: Adam Setch <[email protected]> * feat(api): codegen for discussions Signed-off-by: Adam Setch <[email protected]> * remove comment Signed-off-by: Adam Setch <[email protected]> * feat(api): codegen for discussions Signed-off-by: Adam Setch <[email protected]> * Merge branch 'main' into feat/codegen-discussions Signed-off-by: Adam Setch <[email protected]> * feat(api): codegen for discussions Signed-off-by: Adam Setch <[email protected]> * Update helpers.ts * Update helpers.ts * reduce fetch size Signed-off-by: Adam Setch <[email protected]> * type Signed-off-by: Adam Setch <[email protected]> --------- Signed-off-by: Adam Setch <[email protected]>
1 parent d03f0c9 commit 2818607

27 files changed

+39148
-376
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: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +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-
# Environment configuration
15+
# Environment properties
1816
.env
1917

20-
# Optional npm cache directory
21-
.npm
22-
23-
# Temporary folders
24-
tmp/
25-
temp/
26-
2718
# Mac Files
2819
.DS_Store

.vscode/extensions.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
"recommendations": [
33
"biomejs.biome",
44
"bradlc.vscode-tailwindcss",
5+
"GraphQL.vscode-graphql",
6+
"GraphQL.vscode-graphql-syntax",
57
"SonarSource.sonarlint-vscode"
68
]
79
}

CONTRIBUTING.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ pnpm install
1818
> OAUTH_CLIENT_ID="123" OAUTH_CLIENT_SECRET="456789" pnpm build
1919
> ```
2020
21+
Copy the `.env.template` to `.env` and add update `GITHUB_TOKEN` with a GitHub Personal Access Token. This is used for fetching the latest GitHub GraphQL API schema for `graphql-codegen`.
22+
```shell
23+
GITHUB_TOKEN=<some personal access token>
24+
```
25+
2126
To watch for changes (`webpack`) in the `src` directory:
2227

2328
```shell

biome.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
{
22
"$schema": "https://biomejs.dev/schemas/2.3.10/schema.json",
3+
"files": {
4+
"includes": ["**", "!**/generated/**/*"]
5+
},
36
"assist": {
47
"actions": {
58
"source": {

codegen.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
schema: {
9+
'https://api.github.com/graphql': {
10+
// Add a custom header for authorization using your PAT
11+
headers: {
12+
Authorization: `Bearer ${process.env.GITHUB_TOKEN}`,
13+
},
14+
},
15+
},
16+
documents: ['src/renderer/utils/api/**/*.graphql'],
17+
generates: {
18+
'src/renderer/utils/api/graphql/generated/': {
19+
preset: 'client',
20+
presetConfig: {
21+
fragmentMasking: false, // Disables masking
22+
},
23+
config: {
24+
documentMode: 'string',
25+
useTypeImports: true,
26+
},
27+
},
28+
'src/renderer/utils/api/graphql/generated/schema.graphql': {
29+
plugins: ['schema-ast'],
30+
config: {
31+
includeDirectives: true,
32+
},
33+
},
34+
},
35+
};
36+
37+
export default config;

graphql.config.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import type { IGraphQLConfig } from 'graphql-config';
2+
3+
const config: IGraphQLConfig = {
4+
schema: './src/renderer/utils/api/graphql/generated/schema.graphql',
5+
};
6+
7+
export default config;

package.json

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"build:main": "webpack --config ./config/webpack.config.main.prod.ts",
1010
"build:preload": "webpack --config ./config/webpack.config.preload.prod.ts",
1111
"build:renderer": "webpack --config ./config/webpack.config.renderer.prod.ts",
12-
"watch": "concurrently --names \"main,preload,renderer\" --prefix-colors \"blue,magenta,green\" \"pnpm watch:main\" \"pnpm watch:preload\" \"pnpm watch:renderer\"",
12+
"watch": "concurrently --names \"main,preload,renderer,codegen\" --prefix-colors \"blue,magenta,green,cyan\" \"pnpm watch:main\" \"pnpm watch:preload\" \"pnpm watch:renderer\" \"pnpm watch:codegen\"",
13+
"watch:codegen": "pnpm codegen --watch",
1314
"watch:main": "webpack --watch --config ./config/webpack.config.main.base.ts",
1415
"watch:preload": "webpack --watch --config ./config/webpack.config.preload.base.ts",
1516
"watch:renderer": "webpack --watch --config ./config/webpack.config.renderer.base.ts",
@@ -20,7 +21,8 @@
2021
"lint": "biome check --fix",
2122
"test": "jest",
2223
"start": "electron . --enable-logging",
23-
"prepare": "husky"
24+
"prepare": "husky",
25+
"codegen": "graphql-codegen --config codegen.ts"
2426
},
2527
"engines": {
2628
"node": ">=24"
@@ -79,6 +81,9 @@
7981
"@biomejs/biome": "2.3.10",
8082
"@discordapp/twemoji": "16.0.1",
8183
"@electron/notarize": "3.1.1",
84+
"@graphql-codegen/cli": "6.1.0",
85+
"@graphql-codegen/schema-ast": "5.0.0",
86+
"@parcel/watcher": "2.5.1",
8287
"@primer/css": "22.0.2",
8388
"@primer/octicons-react": "19.21.1",
8489
"@primer/primitives": "11.3.2",
@@ -101,10 +106,11 @@
101106
"css-loader": "7.1.2",
102107
"css-minimizer-webpack-plugin": "7.0.4",
103108
"date-fns": "4.1.0",
109+
"dotenv": "17.2.3",
104110
"electron": "39.2.7",
105111
"electron-builder": "26.0.12",
106112
"final-form": "5.0.0",
107-
"graphql-tag": "2.12.6",
113+
"graphql": "16.12.0",
108114
"html-webpack-plugin": "5.6.5",
109115
"husky": "9.1.7",
110116
"identity-obj-proxy": "3.0.0",
@@ -132,9 +138,9 @@
132138
"pnpm": {
133139
"onlyBuiltDependencies": [
134140
"@biomejs/biome",
141+
"@parcel/watcher",
135142
"@tailwindcss/oxide",
136-
"electron",
137-
"esbuild"
143+
"electron"
138144
]
139145
},
140146
"lint-staged": {

0 commit comments

Comments
 (0)