How to use the amplify-codegen.switchToSDLSchema function in amplify-codegen

To help you get started, we’ve selected a few amplify-codegen 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 aws-amplify / amplify-cli / packages / amplify-util-mock / src / api / api.ts View on Github external
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}`);
    }
  }