UNPKG

939 BJavaScriptView Raw
1import { defineCommand } from '@graphql-cli/common';
2import { CodegenExtension, CodegenContext, generate, updateContextWithCliFlags, buildOptions, } from '@graphql-codegen/cli';
3export 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 // Create Codegen Context with our loaded GraphQL Config
15 const codegenContext = new CodegenContext({
16 graphqlConfig: config,
17 });
18 // This will update Codegen Context with the options provided in CLI arguments
19 updateContextWithCliFlags(codegenContext, args);
20 await generate(codegenContext);
21 },
22 };
23});