1 Answer
- Newest
- Most votes
- Most comments
0
Hi,
- although
npx @aws-amplify/cli codegen add
script generates client helper code, it doesn't add NPM module references to thepackage.json
file and doesn't install the modules; - I assume that you answered
angular
to theChoose the code generation language target
question when running thenpx @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:
orimport { Amplify } from 'aws-amplify'; import config from './aws-exports.js'; Amplify.configure(config);
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
answered 10 days ago
Relevant content
- asked 5 years ago
- asked 3 years ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 2 years ago