dotansimha / dotansimha/graphql-code-generator
Proposal: change `runCli` to accept parsed argv
- Dominant language
- TypeScript
- Stars
- 11.3k
- Forks
- 1.4k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 23
Description
Hello!
I'd like to integrate graphql-codegen with [Heft](https://rushstack.io/pages/heft/overview/) (a Typescript build toolchain designed to work with [Rush](https://github.com/microsoft/rushstack)). Heft has a plugin interface you can implement where I would be hooking graphql-codegen up in the `preCompile` phase, and ideally invoking it directly since Heft is also written in Typescript rather than launching a subprocess.
graphql-codegen currently exposes a `runCli` function similar to for example Jest (which Heft [uses in its Jest plugin](https://github.com/microsoft/rushstack/blob/master/heft-plugins/heft-jest-plugin/src/JestPlugin.ts#L231)). But Jest's `runCli` function takes a [structured argv](https://github.com/facebook/jest/blob/3a85065fe5604655e1337ffc1631f9999722c821/packages/jest-core/src/cli/index.ts#L38), where graphql-codegen's doesn't actually let you thread structured arguments through because [it just switches on whether you passed in the string "init" or not](https://github.com/dotansimha/graphql-code-generator/blob/master/packages/graphql-codegen-cli/src/cli.ts#L7).
Here's a [non-breaking proposal](https://github.com/robertf224/graphql-code-generator/commit/b7bdc6118873bd1ac2d1ccdd97c3673e85f77712) for making `runCli` take a structured argv (which would let me easily integrate it into Heft). We could also refactor the whole command-line arguments parsing setup by using yargs more comprehensively, i.e. something like:
```typescript
const result = yargs
// https://github.com/yargs/yargs/blob/main/docs/advanced.md#default-commands
.command(['generate', '*'], 'generate code', builder => {
builder.options(buildOptions());
})
.command('init', 'initialize code generation')
.strict()
.parse(hideBin(argv));
```
... but this would require a decent amount of refactoring + breaking changes so I figured I'd start with a simple proposal and see what y'all think.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.