1 | import { defineCommand } from '@graphql-cli/common';
|
2 | import { CodegenExtension, CodegenContext, generate, updateContextWithCliFlags, buildOptions, } from '@graphql-codegen/cli';
|
3 | export default defineCommand(api => {
|
4 | return {
|
5 | command: 'codegen',
|
6 | builder(yargs) {
|
7 | return yargs.options(buildOptions());
|
8 | },
|
9 | async handler(args) {
|
10 | const config = await api.useConfig({
|
11 | rootDir: args.config || process.cwd(),
|
12 | extensions: [CodegenExtension],
|
13 | });
|
14 |
|
15 | const codegenContext = new CodegenContext({
|
16 | graphqlConfig: config,
|
17 | });
|
18 |
|
19 | updateContextWithCliFlags(codegenContext, args);
|
20 | await generate(codegenContext);
|
21 | },
|
22 | };
|
23 | });
|