-
Notifications
You must be signed in to change notification settings - Fork 16
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Given this schema:
directive @auth(
role: String
) on OBJECT
type Query {
searchData: Grid
}
union Grid = AdminGrid | ModeratorGrid | UserGrid
type AdminGrid @auth(role: "admin") {
totalRevenue: Float
}
type ModeratorGrid @auth(role: "moderator") {
banHammer: Boolean
}
type UserGrid @auth(role: "user") {
basicColumn: String
}and this plugin setup:
app.register(require('mercurius-auth'), {
authContext (context) {
// you can validate the headers here
return {
identity: context.reply.request.headers['x-user-type']
}
},
async applyPolicy (policy, parent, args, context, info) {
const role = policy.arguments[0].value.value
app.log.info('Applying policy %s on user %s', role, context.auth.identity)
// we compare the schema role directive with the user role
return context.auth.identity === role
},
authDirective: 'auth'
})
The applyPolicy function is never executed.
If I change the schema to:
type Query {
- searchData: Grid
+ searchData: AdminGrid
}The function is executed instead.
Here a complete code example + test (skipped) Eomm/blog-posts@7ec5f23
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working