-
Hi, I'm using CASL for my authorization rules and pothos for my queries. When I define a many relation like the one below I can easily inject the CASL rules into the query: builder.prismaObject('Committee', {
fields: (t) =>
nations: t.relation('nations', {
query: (_args, ctx) => ({
where: ctx.permissions.allowDatabaseAccessTo('list').Nation // <-- This evaluates to a prisma WHERE condition object
})
})
})
}); Now I would like to check if the user can read the conference: builder.prismaObject('Committee', {
fields: (t) =>
conference: t.relation('conference'),
})
}); I think I cannot inject a WHERE into the query, but I didn't manage to get anything working beyond this simple call. Can I somehow at least run some logic before including? Like just a true/false evaluation? What are good approaches to handle this? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
I'm not sure I understand the question. What's preventing you from adding a query the same way as you did for the nations field? |
Beta Was this translation helpful? Give feedback.
I see. Unfortunately if it's not supported in Prisma there isn't anything we can do in Pothos in t.relation.
The queries are computed before data is resolved/queried from the db.
There are 2 options here, each with their own drawbacks:
You can use the auth plugin and add an auth check to the field. This would be enforced before the resolver runs, but the data will already be fetched from the db. It prevents it from being returned in the query, but not from being queried from the db
The other option is to replace t.relation with t.prismaField and load the conference with a prisma.conference.findUniqie call, and add your where clause there.