How to use @graphql-codegen/cli - 5 common examples

To help you get started, we’ve selected a few @graphql-codegen/cli examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github atomist / automation-client / bin / gql-gen.ts View on Github external
"typescript",
                        "typescript-operations",
                    ],
                    config: {
                        namingConvention: "keep",
                        avoidOptionals: false,
                    },
                },
            },
        };

        const graphqlFiles = await util.promisify(glob)(graphQlGlob);

        if (graphqlFiles && graphqlFiles.length > 0) {
            config.documents = [graphQlGlob];
            await generate(config);
            const typesContent = await fs.readFile(gqlGenOutput, "utf8");
            await fs.writeFile(gqlGenOutput, `/* tslint:disable */\n\n${typesContent}`, "utf8");
        } else {
            console.info("No GraphQL files found in project, skipping type generation.");
        }
        process.exit(0);

    } catch (e) {
        console.error(`Generating GraphQL types failed: ${e.message}`);
        process.exit(1);
    }
    throw new Error("Should never get here, process.exit() called above");
}
github Urigo / graphql-cli / packages / commands / codegen / src / index.ts View on Github external
async init({ program, loadGraphQLConfig, reportError }) {
    const commandInstance = program.command('codegen');
    // Let codegen manage our command instance with its own options
    setCommandOptions(commandInstance)
      .action(async cliFlags => {
        try {
          // Load root GraphQL Config not Project Config because Codegen will update it by looking at `project` param
          const graphqlConfig = await loadGraphQLConfig({
            extensions: [CodegenExtension]
          });
          // Create Codegen Context with our loaded GraphQL Config
          const codegenContext = new CodegenContext({
            graphqlConfig,
          });
          // This will update Codegen Context with the options provided in CLI arguments
          updateContextWithCliFlags(codegenContext, cliFlags);
          await generate(codegenContext);
        } catch (e) {
          reportError(e);
        }
github Urigo / graphql-cli / packages / commands / codegen / src / index.ts View on Github external
.action(async cliFlags => {
        try {
          // Load root GraphQL Config not Project Config because Codegen will update it by looking at `project` param
          const graphqlConfig = await loadGraphQLConfig({
            extensions: [CodegenExtension]
          });
          // Create Codegen Context with our loaded GraphQL Config
          const codegenContext = new CodegenContext({
            graphqlConfig,
          });
          // This will update Codegen Context with the options provided in CLI arguments
          updateContextWithCliFlags(codegenContext, cliFlags);
          await generate(codegenContext);
        } catch (e) {
          reportError(e);
        }
      });
  }
github Urigo / graphql-cli / packages / commands / codegen / src / index.ts View on Github external
.action(async cliFlags => {
        try {
          // Load root GraphQL Config not Project Config because Codegen will update it by looking at `project` param
          const graphqlConfig = await loadGraphQLConfig({
            extensions: [CodegenExtension]
          });
          // Create Codegen Context with our loaded GraphQL Config
          const codegenContext = new CodegenContext({
            graphqlConfig,
          });
          // This will update Codegen Context with the options provided in CLI arguments
          updateContextWithCliFlags(codegenContext, cliFlags);
          await generate(codegenContext);
        } catch (e) {
          reportError(e);
        }
      });
  }
github Urigo / graphql-cli / packages / commands / codegen / src / index.ts View on Github external
.action(async cliFlags => {
        try {
          // Load root GraphQL Config not Project Config because Codegen will update it by looking at `project` param
          const graphqlConfig = await loadGraphQLConfig({
            extensions: [CodegenExtension]
          });
          // Create Codegen Context with our loaded GraphQL Config
          const codegenContext = new CodegenContext({
            graphqlConfig,
          });
          // This will update Codegen Context with the options provided in CLI arguments
          updateContextWithCliFlags(codegenContext, cliFlags);
          await generate(codegenContext);
        } catch (e) {
          reportError(e);
        }
      });
  }

@graphql-codegen/cli

<p align="center"> <img src="https://github.com/dotansimha/graphql-code-generator/blob/master/logo.png?raw=true" /> </p>

MIT
Latest version published 3 months ago

Package Health Score

83 / 100
Full package analysis