I'm new to AWS Amplify, and have created a GraphQL API for a project that I'm working on in order to learn it & AppSync. Essentially I have a schema that looks like the following:
type User @model {
id: ID! @primaryKey
boards: [Board] @hasMany
createdAt: String!
updatedAt: String!
}
type Board @model {
id: ID! @primaryKey
createdBy: User!
title: String!
}
and I'm trying to run the following query in the AppSync console:
query MyQuery {
listUsers {
items {
boards {
items {
title
}
}
}
}
}
But for some reason I keep seeing this error:
Filter Expression can only contain non-primary key attributes: Primary key attribute: userBoardsId
I've specified the primary key in both models, and I'm aware that AppSync generates the 'userBoardsId' foreign key, but I'm not sure why it's causing an issue.
Have you tried like this? Since boards is array, you need to add items
query MyQuery {
listUsers {
items {
boards {
items {
title
}
}
}
}
}
EDIT:
type User @model {
id: ID! @primaryKey
boards: [Board] @hasMany (indexName: "byUser")
createdAt: String!
updatedAt: String!
}
type Board @model {
id: ID! @primaryKey
userID: ID! @index(name: "byUser")
createdBy: User
title: String!
}