aws-amplify / amplify-cli

The AWS Amplify CLI is a toolchain for simplifying serverless web and mobile development.
Apache License 2.0
2.82k stars 821 forks source link

How to fix AppSync corrupted query schema for Amplify app' backend #12800

Closed nilyin closed 1 year ago

nilyin commented 2 years ago

Please describe which feature you have a question about? My App was deployed using Amplify Web GUI and link to git repo. After a while I have changed the code-base and merged it into the linked git repository branch. The app was automatically redeployed. My app web frontend client started giving errors. I've researched it and found that AWS corresponding resource in AppSync (actually my GraphQL query naming) was corrupted (some queries had "s" letter attached at the end)

My questions: 1) why such corruption can happen? all graphQL queries located in the git repository have the correct naming 2) how to reload the graphQL schema and queries (without manual edit in AppSync UI), provided I cannot do it through amplify-cli because I do not have S3-deployment bucket present (may be because the deployment has been from Web console / git rather than amplify-cli push. It looks like the backend is not updating the corresponding data in appsync resource from git data and I have no idea why?

3) what are the Access keys in my frontend's App.vue file? How these key connected to my account id or these keys are not related and can work with backend initialized with any AWS account id parameter?

AWS.config.update({ accessKeyId: "*********", secretAccessKey: "*****************", // "region": "sa-east-1" });

I am asking that, because following an advice of one of blog-post found on Internet, I have also tried to generate new environment called "dev" by invoking "amplify init" command and putting these Access Keys as authentication params (e.g. keys taken from from this App.vue file), at that I have fully cleaned teams-project-info.json in advance. After that I've received new backend environment deploed in the cloud, but it had resource id (arn) of another AWS account ID (may be the frontend developer own account has been used for that?). What could happen?

Provide additional details I also tried to use amplify-cli "push" from my PC but got the error due to the absence of the corresponding (as one, named in the team-provide-info.json) deployment bucket.

I tried to create such bucket manually and copy there the .zip file with content of #backend-backup folder, but got error (something like "key is not found")

What AWS Services are you utilizing? amplify with auth, storage (S3), hosting

Provide additional details e.g. code snippets appId dgzmixxw4s34v

deployment resource -"amplify-mkp-staging-112811-deployment"

one of the correct methods in master/src/graphql/queries.js

export const listComments = /* GraphQL */ query ListComments( $filter: ModelCommentsFilterInput $limit: Int $nextToken: String ) { listComments(filter: $filter, limit: $limit, nextToken: $nextToken) { items { id author rating comment componentsID like dislike title _version _deleted _lastChangedAt createdAt updatedAt } nextToken startedAt } } `;

`

the AppSync bad / corrupted query naming was "listCommentss"

josefaidt commented 1 year ago

Hey @nilyin :wave: thanks for raising this!

My app web frontend client started giving errors. I've researched it and found that AWS corresponding resource in AppSync (actually my GraphQL query naming) was corrupted (some queries had "s" letter attached at the end)

Are you using GraphQL transformer 1 or 2? Transformer version 2 is the default for newly created API's, however v1 included a feature flag called improvePluralization which can exhibit odd pluralization additions such as the one you are seeing with the extra s. You can determine the value of these flags by inspecting amplify/cli.json

why such corruption can happen? all graphQL queries located in the git repository have the correct naming

This will depend on the answer to the question above regarding transformer versions, but ideally these queries will be generated from the deployed schema.

how to reload the graphQL schema and queries (without manual edit in AppSync UI), provided I cannot do it through amplify-cli because I do not have S3-deployment bucket present (may be because the deployment has been from Web console / git rather than amplify-cli push. It looks like the backend is not updating the corresponding data in appsync resource from git data and I have no idea why?

Regardless of whether the project was deployed via the CLI or Web UI, it should create a deployment bucket for the backend state. What is the intention

what are the Access keys in my frontend's App.vue file? How these key connected to my account id or these keys are not related and can work with backend initialized with any AWS account id parameter?

You should not need to use your AWS credentials in your Vue app as this could expose your keys to the client bundle, and therefore folks visiting your website could inspect the source and view the keys. The src/aws-exports.js file is created when the project is initialized (i.e. after amplify init or amplify pull, which Amplify Hosting will perform for you). This is the file used to configure your frontend and access resources in your project's backend

nilyin commented 1 year ago

@josefaidt hi, thank you for your response and information. I did have Transformer V1 API at that moment. I've fixed the problem by migrating my project to V2 and regenerating new graphql schema. Anyway, your comments are useful. I will close the issue as it is addressed / fixed now.

github-actions[bot] commented 1 year ago

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see. If you need more assistance, please open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.