ScopeAuth Plugin with Prisma - Possible to Access Nested parent
Fields?
#851
-
Hi! Currently working to implement the scope auth plugin on a project that is also using the Prisma plugin. I've noticed that when using I'm assuming there's no way currently to fetch those nested fields by passing in the Prisma query manually to the scope auth plugin. Please let me know if there is; otherwise, I believe this is the best way to fetch that data as of now:
This does require extra database calls, and is likely not as performant. When Pothos fetches the data for the Edit: answering my own question for that last part -- whether Pothos caches that data. I'm going to assume that wouldn't be possible because Pothos would still need to call the resolver function to return all data the user requested. For example, if the |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
The data should be there, but there is no way to make it type-safe in the authScopes handler. The nested data is dependent on what was queried. Only data that is always selected is available in the types for If you want to always load data, you can use builder.prismaObject('User', {
include: {
organization: {
select: {
id: true
}
}
},
runScopesOnType: true,
authScopes: async (user, context) => {
console.log(user.organization.id)
},
}) |
Beta Was this translation helpful? Give feedback.
The data should be there, but there is no way to make it type-safe in the authScopes handler. The nested data is dependent on what was queried. Only data that is always selected is available in the types for
parent
, but the data should still exist on the parent object.If you want to always load data, you can use
include
orselect
on the type: