Closed todda00 closed 7 years ago
modifyContext
looks good to me. @xavcz ?
Might be cleaner to copy only the relevant options over here:
https://github.com/apollographql/meteor-integration/blob/master/src/main-server.js#L80
I started working on this modifying context to accept either an object or a function, it just feels like a redundancy providing both context and modifyContext. I am working on it this way unless you strongly feel adding modifyContext is the way to go.
Would the fn be called after the user is added?
if customOptionsObject.context is an object
copy it over
addCurrentUserToContext(options)
if customOptionsObject.context is a function
options.context = customOptionsObject.context(options.context)
PR merged, thanks a lot @todda00 @lorensr! Package published 👍
I would like to modify the context after the user is added. I need to add some permission data which requires both the user object and a different object I have added to the context via options.context.
Since I am using this permission data in many resolvers, I would like to avoid a utility function in all resolvers and include this data in the context.
I am thinking the way to do this is providing a hook function in the customOptions object:
Or if the location where the context is added from customOptions.context, this option could be provided as a function which accepted the current context and returns the desired one. ( this is probably a cleaner approach if moving the context merge to after the user is added is acceptable)
Either way this will have to hook in here: https://github.com/apollographql/meteor-integration/blob/master/src/main-server.js#L93
I can come up with a PR if we can determine what we want the API to work like.