-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make context available to Sequelize hooks? #77
Comments
@charlie-s we can schedule a call and I can help you with this. |
after digging in to the library a bit, I was able to accomplish this by doing a few things... want to document them here for my own benefit.
Thats it. Since this library calls the model.scope() function when performing queries, and the 'args' and 'context' graphql options are available in that scope function, this should add the 'context' property to your Sequelize options with the graphql context. You can then use this in Sequelize hooks. |
I guess i should mention that perhaps the easier way to do this is through a change to the library... for example, in Update.js, change line 173 FROM: TO: Happy to put in a PR for this, but perhaps there is a reason it is not already done... |
this approach is not future proof. With the next release being TS based, this won't be possible. The firs approach or acquiring models in a context would make more sense. But I can think of something around it, something which is also future proof :). |
Could the context be passed through to Sequelize hooks through
options
?In our authorizer function we attach the current user to ctx and use that for logging and related activity through a request's lifecycle. We can use
graphql.before.create/update
to achieve this, but that only applies to the graphql request and not any subsequent Sequelize model work.The text was updated successfully, but these errors were encountered: