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
已提问 1 个月前73 查看次数
1 回答
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
已回答 25 天前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则