Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private async generateCode(context, transformerOutput = null) {
try {
context.print.info('Running GraphQL codegen');
const { projectPath } = context.amplify.getEnvInfo();
const schemaPath = path.join(projectPath, 'amplify', 'backend', 'api', this.apiName, 'build', 'schema.graphql');
if (transformerOutput) {
fs.writeFileSync(schemaPath, transformerOutput.schema);
}
if (!isCodegenConfigured(context, this.apiName)) {
await add(context);
} else {
switchToSDLSchema(context, this.apiName);
await generate(context);
}
} catch (e) {
context.print.info(`Failed to run GraphQL codegen with following error:\n${e.message}`);
}
}