Skip to content
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

Add codegen for enums #273

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
5 changes: 5 additions & 0 deletions .changeset/thick-lizards-add.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@saleor/app-sdk": patch
---

Added script to generate TyoeScript enums from GraphQL schema.
33 changes: 33 additions & 0 deletions codegen.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import type { CodegenConfig } from "@graphql-codegen/cli";

const config: CodegenConfig = {
schema: "https://raw.githubusercontent.com/saleor/saleor/main/saleor/graphql/schema.graphql",
documents: [], // No need to search for documents, we are only generating enums
ignoreNoDocuments: true, // Prevents throwing error on generating types in project without typed queries
generates: {
"./src/generated-enums.ts": {
plugins: [
"typescript",
{
add: {
content: [
"/**",
" * Generated file, do not modify it by hand.",
" * To update it to the current schema, use `pnpm generate` script.",
" */",
],
},
},
],
config: {
onlyEnums: true,
enumsAsTypes: true,
typesPrefix: "Generated", // Added the prefix since we export only subset of all enums
},
},
},
hooks: {
afterAllFileWrite: "prettier --write",
},
};
export default config;
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"prepare": "husky install",
"lint": "tsc --noEmit && prettier --loglevel warn --write . && eslint --fix .",
"copy-readme": "cp README.md dist/README.md",
"publish:ci": "pnpm publish && npx changeset tag && git push --follow-tags"
"publish:ci": "pnpm publish && npx changeset tag && git push --follow-tags",
"generate": "graphql-codegen"
},
"keywords": [],
"author": "",
Expand All @@ -35,6 +36,9 @@
"uuid": "^8.3.2"
},
"devDependencies": {
"@graphql-codegen/add": "^5.0.0",
"@graphql-codegen/cli": "^5.0.0",
"@graphql-codegen/typescript": "^4.0.1",
"@testing-library/dom": "^8.17.1",
"@testing-library/react": "^13.4.0",
"@types/debug": "^4.1.7",
Expand Down
Loading