Error from codegen Module '"@aws-amplify/api-graphql"' has no exported member 'API'.

0

I have created AWS app sync graphql API - nd generated the code of API in angular application using command - npx @aws-amplify/cli codegen add --apiId mnafjbbr55g3fkwufedwba7efa --region us-east-1

But this code generated one line - import { API } from '@aws-amplify/api-graphql'; is giving error - Module '"@aws-amplify/api-graphql"' has no exported member 'API'.

Nupur
asked 10 days ago54 views
1 Answer
0

Hi,

  1. although npx @aws-amplify/cli codegen add script generates client helper code, it doesn't add NPM module references to the package.json file and doesn't install the modules;
  2. I assume that you answered angular to the Choose the code generation language target question when running the npx @aws-amplify/cli codegen add and it produced client code using Amplify v5 version, which is not compatible with the Amplify v6 library. See this GitHub issue discussion for more details: V6 TypeScript strict mode error with API.

That said, you should be able to generate just the client types (having no dependencies on any GraphQL client at all) by using npx @aws-amplify/cli codegen add and selecting typescript, instead of angular, when answering the question Choose the code generation language target. Once you have your client types added to the Angular project, you can use AWS Console to navigate to your AppSync instance API landing page and review the suggested code changes to your project there.

For example:

  • add Amplify NPM module to the Angular project: npm install aws-amplify
  • import the Amplify Library and your configuration to set up Amplify:
    import { Amplify } from 'aws-amplify';
    import config from './aws-exports.js';
    
    Amplify.configure(config);
    or
    import { Amplify } from 'aws-amplify';
    
    Amplify.configure({
      API: {
        GraphQL: {
          endpoint: '<endpoint_url>',
          region: '<region>',
          defaultAuthMode: '<auth_mode>',
        }
      }
    });
  • once you have Amplify library configured for your application, you should be able to add client code to the components, e.g.
    import { generateClient } from 'aws-amplify/api';
    
    const client = generateClient();

See Configure the Amplify Library in your app code for more examples.

Regards

AWS
answered 10 days ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions