Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"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");
}
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);
}
.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);
}
});
}
.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);
}
});
}
.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);
}
});
}