I'm using the "Viewer pattern" to fetch images that belong to the authenticated user:
type Query {
me: User! @auth
}
type User {
name: String!
images: [Image] @hasMany
}
And I fetch with:
{
me {
images {
id
url
}
}
}
This all works well, but it returns me all the images from the user.
My question is: How to get a single image from the authenticated user by its ID?
I tried this:
type User {
name: String!
images: [Image] @hasMany
"Fetch image by its ID"
image(id: ID @eq): Image @find
}
And I fetch with:
{
me {
image(id: 4) {
id
url
}
}
}
While this works, it creates a huge security issue. Anyone logged in can access any image from any user.
I tried to mix @find
and @whereAuth
but I got this
exception:
Call to a member function getRelationExistenceQuery() on null
Ideas?