Describe the bug
There is a --template argument, but there is no documented way to pass arguments to that template programmatically. For example: I want to make use of graphql-codegen-typescript-template's interfacePrefix setting. I currently have no documented way for passing that setting in.
To Reproduce
Look at the docs, under the 'template' option. There is no mention of how to pass args to said template. The programmatic usage section also makes no mention of how to pass args to templates.
Expected behavior
I should be able to pass arguments to the underlying template programmatically.
Schema/Documents
N/A
Environment:
N/A
Additional context
I am using the library programmatically in a Typescript environment.
EDIT: I found the section on how to use a gql-gen.json file to do this via the CLI. However, there is no documented way to do this programmatically.
Thanks @robbyemmert !
I guess we need to document it better.
I think it's not only documentation bug, but it should also be an option for generate method.
For now, as a workaround, you can set process.env.CODEGEN_XYZ to pass generator-specific config.
BTW, after walking around the source code, I found the way to pass documents... | [String] in programmatically way is to set args field of GenerateOptions.
Example usage that works for me:
import { generate } from 'graphql-code-generator'
generate({
schema: 'introspection_from_servier.json',
// vvv this is actually used as documents in CLI options
args: 'path/to/client_gql_documents/*.ts',
out: 'generated_schema.ts',
template: 'graphql-codegen-typescript-template',
})
Context: According to types, GenerateOptions extends CLIOptions, I read https://github.com/dotansimha/graphql-code-generator#cli-options to figure out the usage of each field. I want to use the last documents... argument in CLI options to specify the documents to process, but there are no similar fields on type CLIOptions. Finally, I found args field is for that thing.
Should that args be mentioned in the docs (or be described in type definition), too?
fixed in 0.13.0 :) You can use templateConfig