Also, is there any way to pass data from a directi...
# orm-help
g
Also, is there any way to pass data from a directive-resolver to its corresponding resolver function? IE. if I have an auth directive-resolver but need auth info inside my query/mutation resolver is there some way to use the nextFn to pass authentication data from the directive-resolver?
l
Directive resolvers are called after the application resolvers. I get around this issue by using express middleware to append a user object to the request, then it's available all over context.
g
Oooo, good idea. I'll give that a try. Thank you!
f
@Greyson This uses express middleware to check header token -> get user from DB and attach it to
req
object -> do authorization based on directives -> and finally run resolvers: https://github.com/frandiox/vue-graphql-enterprise-boilerplate/blob/master/server/src/
l
That example uses schema directives which is a new API. That is the preferred API (for now), but directive resolvers still work.
f
@lawjolla Actually it has both schemaDirectives and directiveResolvers in
directives/index.js
. Both are permitted in
makeExecutableSchema
🙂