Data store aws amplify can not get data

67 Views Asked by At

Hello guys this i my data store schema:

type ChatUser {
  _id: Int
  name: String
  avatar: AWSURL
  status: String
}

type Message {
  _id: Int!
  text: String
  createdAt: AWSDateTime
  sent: Boolean
  received: Boolean
  pending: Boolean
  user: ChatUser
}

type User {
  id: String
}

type Conversation @model @auth(rules: [{allow: public}]) {
  id: ID!
  users: [User!]
  tableID: ID! @index(name: "byTable")
  messages: [Message!]
}

type Table @model @auth(rules: [{allow: public}]) {
  id: ID!
  tableId: String! @index(name: "byTableId")
  Conversations: [Conversation] @hasMany(indexName: "byTable", fields: ["id"])
  users: [ChatUser]
}

I want to get table by tableId

 const getTable = async (tableId) => {
    try {
      const table = await DataStore.query(Table, tableId);
      console.log('Table retrieved successfully!', table);
    } catch (error) {
      console.log('Error retrieving table', error);
    }
  }

Table is always undefined but when i fetch all tables from db I see this:

Tables retrieved successfully! [{"_deleted": undefined, "_lastChangedAt": undefined, "_version": undefined, "createdAt": null, "id": "20287b9c-46a0-4ab8-85e9-592f526ca57c", "tableId": "770", "updatedAt": null, "users": [[Object], [Object], [Object], [Object], [Object], [Object]]}]

Not sure what I am doing wrong if maybe someone can help

0

There are 0 best solutions below