Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .gitignore
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
63 changes: 63 additions & 0 deletions graphql/codegen-orm/.boilerplate.json
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
}
]
}

14 changes: 14 additions & 0 deletions graphql/codegen-orm/.gitignore
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
14 changes: 14 additions & 0 deletions graphql/codegen-orm/README.md
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.
12 changes: 12 additions & 0 deletions graphql/codegen-orm/codegen.config.ts
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/',
},
});
35 changes: 35 additions & 0 deletions graphql/codegen-orm/generate.ts
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';
Copy link
Contributor

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?

Copy link
Author

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?

Copy link
Author

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.


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);
});
37 changes: 37 additions & 0 deletions graphql/codegen-orm/package.json
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"
}
}
Loading