diff --git a/graphql.config.yml b/graphql.config.yml index fb2bf96..a4d71e3 100644 --- a/graphql.config.yml +++ b/graphql.config.yml @@ -22,3 +22,6 @@ generates: MetaTagAttributes: Record UploadId: string - typed-document-node + config: + namingConvention: + enumValues: './pascalCaseWithUnderscores' diff --git a/package.json b/package.json index 843266c..40b5e84 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "@graphql-codegen/typescript": "2.7.3", "@graphql-codegen/typescript-operations": "2.5.3", "@graphql-typed-document-node/core": "3.1.1", + "change-case-all": "^1.0.15", "graphql": "16.6.0", "graphql-request": "5.0.0", "next": "12.3.0", @@ -26,14 +27,14 @@ "@types/node": "18.7.17", "@types/react": "18.0.19", "@types/react-dom": "18.0.6", - "typescript": "4.8.3", + "@typescript-eslint/eslint-plugin": "5.33.1", + "@typescript-eslint/parser": "5.33.1", "eslint": "8.22.0", "eslint-config-next": "12.2.5", "eslint-config-prettier": "8.5.0", "eslint-plugin-next": "0.0.0", "eslint-plugin-prettier": "4.2.1", "prettier": "2.7.1", - "@typescript-eslint/eslint-plugin": "5.33.1", - "@typescript-eslint/parser": "5.33.1" + "typescript": "4.8.3" } } diff --git a/pascalCaseWithUnderscores.js b/pascalCaseWithUnderscores.js new file mode 100644 index 0000000..adb9f58 --- /dev/null +++ b/pascalCaseWithUnderscores.js @@ -0,0 +1,17 @@ +const { pascalCase } = require("change-case-all") + +function pascalCaseWithUnderscores(str) { + const result = pascalCase(str) + + if (!result) { + return str + } + + // if there is a leading underscore but it's not in the converted string, add it + if (str.indexOf("_") === 0 && result.substring(0, 1) !== "_") { + return `_${result}` + } + return result +} + +module.exports = pascalCaseWithUnderscores