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 天前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南