-
Notifications
You must be signed in to change notification settings - Fork 0
Added graphql directory with codegen example #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
NorOldBurden
wants to merge
2
commits into
main
Choose a base branch
from
update/graphql-codegen-boilerplate
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| # macOS | ||
| .DS_Store | ||
|
|
||
| # Node.js | ||
| node_modules/ | ||
| *.log | ||
|
|
||
| # Build outputs | ||
| dist/ | ||
| build/ | ||
|
|
||
| # IDE | ||
| .vscode/ | ||
| .idea/ | ||
|
|
||
| # Temporary files | ||
| *.tmp | ||
| *.temp |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| { | ||
| "type": "module", | ||
| "requiresWorkspace": "pnpm", | ||
| "questions": [ | ||
| { | ||
| "name": "____fullName____", | ||
| "message": "Enter author full name", | ||
| "setFrom": "workspace.author.name", | ||
| "defaultFrom": "git.user.name", | ||
| "required": true | ||
| }, | ||
| { | ||
| "name": "____email____", | ||
| "message": "Enter author email", | ||
| "setFrom": "workspace.author.email", | ||
| "defaultFrom": "git.user.email", | ||
| "required": true | ||
| }, | ||
| { | ||
| "name": "____moduleName____", | ||
| "message": "Enter the module name", | ||
| "required": true | ||
| }, | ||
| { | ||
| "name": "____moduleDesc____", | ||
| "message": "Enter the module description", | ||
| "required": true | ||
| }, | ||
| { | ||
| "name": "____repoName____", | ||
| "message": "Enter the repository name", | ||
| "setFrom": "workspace.name", | ||
| "required": true | ||
| }, | ||
| { | ||
| "name": "____username____", | ||
| "message": "Enter your github username", | ||
| "setFrom": "workspace.organization.name", | ||
| "defaultFrom": "npm.whoami", | ||
| "required": true | ||
| }, | ||
| { | ||
| "name": "____access____", | ||
| "message": "Module access?", | ||
| "options": [ | ||
| "public", | ||
| "restricted" | ||
| ], | ||
| "type": "list", | ||
| "default": "public", | ||
| "required": true | ||
| }, | ||
| { | ||
| "name": "____license____", | ||
| "message": "Choose a license", | ||
| "type": "list", | ||
| "optionsFrom": "licenses", | ||
| "setFrom": "workspace.license", | ||
| "required": true | ||
| } | ||
| ] | ||
| } | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
|
||
| # dependencies | ||
| /node_modules | ||
|
|
||
| # production | ||
| /dist | ||
|
|
||
| # env files (can opt-in for committing if needed) | ||
| .env* | ||
|
|
||
| # typescript | ||
| *.tsbuildinfo | ||
| next-env.d.ts |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| # GraphQL Codegen Boilerplate | ||
|
|
||
| This directory contains the GraphQL code generation boilerplate for Constructive. | ||
|
|
||
| Usage: | ||
|
|
||
| - Make sure you have GraphQL server running for codegen to work | ||
|
|
||
| - Run `pnpm run codegen` from this directory to generate the SDK into `src/generated`. | ||
|
|
||
| Notes: | ||
|
|
||
| - Requires `pnpm` installed. | ||
| - The codegen script is defined in `generate.ts` and can be customized if needed. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import { defineConfig } from '@constructive-io/graphql-codegen'; | ||
|
|
||
| export default defineConfig({ | ||
| endpoint: 'http://api.localhost:3000/graphql', | ||
| output: './src/generated/', | ||
| reactQuery: { | ||
| enabled: false, | ||
| }, | ||
| orm: { | ||
| output: './src/generated/', | ||
| }, | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| #!/usr/bin/env ts-node | ||
| /** | ||
| * GraphQL Code Generation Script | ||
| * | ||
| * Usage: | ||
| * pnpm run codegen | ||
| * | ||
| */ | ||
|
|
||
| import { generateOrmCommand } from '@constructive-io/graphql-codegen'; | ||
|
|
||
| async function main() { | ||
| console.log('Starting GraphQL code generation...\n'); | ||
|
|
||
| const result = await generateOrmCommand({ | ||
| config: './codegen.config.ts', | ||
| verbose: true, | ||
| }); | ||
|
|
||
| if (!result.success) { | ||
| console.error('\n❌', result.message); | ||
| if (result.errors?.length) { | ||
| result.errors.forEach((e) => console.error(' -', e)); | ||
| } | ||
| process.exit(1); | ||
| } | ||
|
|
||
| console.log('\n✓', result.message); | ||
| console.log('\nGeneration complete!'); | ||
| } | ||
|
|
||
| main().catch((err) => { | ||
| console.error('Fatal error:', err); | ||
| process.exit(1); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| { | ||
| "name": "@constructive-templates/graphql-codegen", | ||
| "version": "0.0.1", | ||
| "author": "____fullName____ <____email____>", | ||
| "private": true, | ||
| "main": "index.js", | ||
| "module": "esm/index.js", | ||
| "types": "index.d.ts", | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "https://github.com/____username____/____repoName____" | ||
| }, | ||
| "license": "____license____", | ||
| "description": "____moduleDesc____", | ||
| "scripts": { | ||
| "copy": "copyfiles -f ../../LICENSE README.md package.json dist", | ||
| "clean": "rimraf dist/**", | ||
| "build": "pnpm run clean; tsc; tsc -p tsconfig.esm.json; pnpm run copy", | ||
| "codegen": "ts-node generate.ts" | ||
| }, | ||
| "keywords": [], | ||
| "devDependencies": { | ||
| "@constructive-io/graphql-codegen": "^2.31.0", | ||
| "@types/node": "^20.19.29", | ||
| "copyfiles": "^2", | ||
| "esbuild": "^0.27.2", | ||
| "rimraf": "^5", | ||
| "ts-node": "^10.9.2", | ||
| "typescript": "^5" | ||
| }, | ||
| "dependencies": { | ||
| "@0no-co/graphql.web": "^1.1.2", | ||
| "@constructive-io/graphql-types": "^2.14.0", | ||
| "gql-ast": "^2.6.0", | ||
| "graphql": "^15.10.1" | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's the point of this file generate.ts? Can't we just stick a script into the "scripts" object in package.json?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried in my local. The package doesn't provide a standalone CLI binary - it only exposes programmatic functions. It might be caused by previous change that moved generate out of cli?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally, I think it's more clear to demo how to use it programmatically in actual file instead hide it inside the package.json script.