require field allows you to load any external files without the need to transpile them before.
To use it, install the extensions you wish to use from npm and then specify a list of
require extensions in your root config:
require extension is useful if you are loading your
GraphQLSchema or GraphQL documents from a code file, if you wish to use custom plugins, or use a custom schema loader or a custom document loader.
If you wish to use TypeScript, just add
ts-node from npm and specify its register export in your config file:
You can also specify
require.extensions as a cli flag using
-r using a CLI flag will load your
require.extension before loading the
.yml file, and this way you can load environment variables using
dotenv and use those environment variables in your
.yml config file.
If you wish to use dotenv to load environment variables, you can install
dotenv from npm and then to use the
require cli flag to preload the
dotenv require extensions:
It will make sure to load your
.env file before executing the codegen and loading your
.yml file, so environment variables that are used in your config file will be replaced with the correct value.
To get started with this integration, make sure you have
.env file with variables,
dotenv installed, and codegen is being executed like that:
If you wish to load a file different than
.env file, please follow
dotenv library documentation.
It allows you to specify a custom file path using 2 methods.
You can either set an environment variable called
DOTENV_CONFIG_PATH with the path:
Note: You can use
cross-envlibrary if you are using Windows.
Or, you can specify it using codegen cli, like that:
Note: The env values might be saved in the generated code output. Be careful not to commit code with sensitive keys.