Naming Convention
GraphQL Code Generator is a tool for generating code from GraphQL schema and operations.
GraphQL Code Generation provides a namingConvention option to control the naming convention of the
different code elements generated (types, enum values, …).
namingConvention
type: NamingConvention default: change-case-all#pascalCase
Allow you to override the naming convention of the output.
You can either override all namings or specify an object with a specific custom naming convention
per output. The converter format must be a valid module#method.
Allowed values for specific output are: typeNames, enumValues. You can also use “keep” to keep
all GraphQL names as-is. Additionally, you can set transformUnderscore to true if you want to
override the default behavior to preserve underscores.
Usage Examples
Override All Names
Upper-case enum values
Keep names as is
Remove Underscores
Using external modules
All the examples you saw so far were using change-case-all package.
The change-case-all package being a direct dependency of graphql-codegen, you can use it directly.
However, you can use any other package as long as it is installed as a dependency. The same syntax needs to be used:
For example, if you want to use camelCase from lodash, given that you have it already installed,
you will do it like this:
Providing your own naming function
As you may have guessed already, there is nothing fancy about naming functions. They are just functions that take a string as input and produce it as output.
If you stick to that signature, you can provide your own naming function. You need to provide a CJS module with a default export of a function that takes a string and returns a string.
The following example provides a workaround to a limitation of change-case-all:
Then, just provide the path to your custom naming module in the configuration:
This also applies when you want a specific custom naming convention per output. Specify your custom naming function on the output or outputs you want to apply: