Query dynamDB table for messaging app

-1

I'm trying to create a messaging feature for my app using DynamoDB. However, I can only see the messages that I send. I can't seem to query the messages that are sent to me.

In the appsync console, When I run this query I get a result:

query MyQuery {
  messagesByFriendIDAndUserID(friendID: "b99e4488-4061-704f-af2a-69560ee0f184", userID: {eq: "39ae94c8-4041-7016-157d-53ab46b8c1bd"}) {
    nextToken
    startedAt
    items {
      id
      friendID
      userID
      content
    }
  }
}

However when I switch the friendID and userID like this, I don't get a result, even though there is relevant data in the messages table.

query MyQuery {
  messagesByFriendIDAndUserID(friendID: "39ae94c8-4041-7016-157d-53ab46b8c1bd", userID: {eq: "b99e4488-4061-704f-af2a-69560ee0f184"}) {
    nextToken
    startedAt
    items {
      id
      friendID
      userID
      content
    }
  }
}

Does anyone know why this would be the case?

Luke
asked a year ago206 views
2 Answers
0

It would difficult to provide exact answer when schema of the table is not know but I can see that you have swapped the values in the query but did not swap the keys, so there might be a possibility that the value you provided with respect to the key does not exist in the table. Please check the schema of the table and try to rewrite your query.

AWS
answered a year ago
-1

Thanks. I solved this by adding private read access to the message table. If the friendID was the logged in cognito user ID, it wouldn't fetch the results.

Luke
answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions