aws / aws-appsync-community

The AWS AppSync community
https://aws.amazon.com/appsync
Apache License 2.0
506 stars 32 forks source link

Error: Body must be a string. Received: undefined. #317

Closed BuildingFiles closed 1 year ago

BuildingFiles commented 1 year ago

At some point a previosuly functioning system stoped working. Unfortunetly the bug slipped through our testing teams process. As a result I dont know the exact time frame the bug became active.

However the code in question has not been changed in our application in several years and was operational untill fairly recerntly.

I believe the issue may be related to one the the amplify dynamo or graph ql updates taken place recently.

At this time when we run this get query it returns the following Error: Body must be a string. Received: undefined.

I can run the same query in the AppSync console, and it works fine. I am at a loss as to what could be wrong here.

Here is the query as it is in application.

const userQry = await API.graphql({ query: queries.getUserByEmail, variables: { email: Email}, authMode: 'AMAZON_COGNITO_USER_POOLS' }); const emailCheck = userQry.data.GetUserByEmail.items[0];

Here is the query in schema.graphql

type Users @model @key(fields: ["username"]) @key(name: "getUserByEmail", fields: ["email"], queryField: "GetUserByEmail") @auth(rules: [ { allow: owner, operations: [create, update, read] } { allow: private, operations: [read] } ]){ username: ID! sub: String name: String email: String email_verified: Boolean cognitoGroups: AWSJSON customOwner: String customManaging: String customProjects: String customFollowing: String customBookmarked: String phone_number: String phone_number_verified: Boolean }

Attached are the log files we are seeing. Screenshot 2023-08-16 144018

localhost-1692211140907.log

BuildingFiles commented 1 year ago

So as a temp fix, I copied the graphql generated query from queries.js to custom/queries.js. trimmed out the bits not needed for the custom query, and it works without error.

Origonal in queries.js:

export const GetUserByEmail = / GraphQL / query GetUserByEmail( $email: String $sortDirection: ModelSortDirection $filter: ModelUsersFilterInput $limit: Int $nextToken: String ) { GetUserByEmail( email: $email sortDirection: $sortDirection filter: $filter limit: $limit nextToken: $nextToken ) { items { username sub name email email_verified cognitoGroups customOwner customManaging customProjects customFollowing customBookmarked phone_number phone_number_verified createdAt updatedAt owner __typename } nextToken __typename } } ;

Custom queries.js:

export const getUserByEmail = / GraphQL / query GetUserByEmail($email: String) { GetUserByEmail(email: $email) { items { username sub name email email_verified cognitoGroups customOwner customManaging customProjects customFollowing customBookmarked phone_number phone_number_verified createdAt updatedAt owner } } } ;

onlybakam commented 1 year ago

Hi, was this issue start occuring after an amplify update? if so, did you open an issue in the Amplify repo?

or is the situation that nothing changed in your code and the query started having issues?

thanks

BuildingFiles commented 1 year ago

Hi, was this issue start occuring after an amplify update? if so, did you open an issue in the Amplify repo?

or is the situation that nothing changed in your code and the query started having issues?

thanks

Unfortunately, I can't say for certain. The bug slipped past our testers. We recently did the mandatory upgrade to cdk2 from not using a cdk at all, and at least 1 amplify update. But since I don't know the exact point, the issue started its impossible to be absolutely positive.

BuildingFiles commented 1 year ago

With the help of AWS support, we found that deleting the graphql folder, then running the following codgen commands fixes the problem.

$ amplify configure codegen $ amplify codegen

Which regenerates the graphql scripts. I was then able to copy our graphql/custom folder back in and the application worked as it had previously.