Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function prePushGraphQLCodegen(context, createResources, updateResources) {
createResources = createResources.filter(resource => resource.service === 'AppSync');
// There can only be one appsync resource
if (createResources.length > 0) {
const resource = createResources[0];
const { resourceName } = resource;
graphQLConfig = await prePushAddGraphQLCodegenHook(context, resourceName);
return;
}
if (updateResources.length > 0) {
const resource = updateResources[0];
const { resourceName } = resource;
graphQLConfig = await prePushUpdateGraphQLCodegenHook(context, resourceName);
}
}
async function prePushGraphQLCodegen(context, createResources, updateResources) {
createResources = createResources.filter(resource => resource.service === 'AppSync');
// There can only be one appsync resource
if (createResources.length > 0) {
const resource = createResources[0];
const { resourceName } = resource;
graphQLConfig = await prePushAddGraphQLCodegenHook(context, resourceName);
return;
}
if (updateResources.length > 0) {
const resource = updateResources[0];
const { resourceName } = resource;
graphQLConfig = await prePushUpdateGraphQLCodegenHook(context, resourceName);
}
}
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}`);
}
}
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}`);
}
}
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}`);
}
}
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}`);
}
}
async function postPushGraphQLCodegen(context) {
await postPushGraphQLCodegenHook(context, graphQLConfig);
}