Is your feature request related to a problem? Please describe.
Sometime we need to pass some context to adapt the behavior / action of a trigger.
Currently context is only available on these triggers: beforeSave - afterSave - beforeDelete - afterDelete - beforeFind
See #6459 #6626 #6666
Describe the solution you'd like
It should be possible to pass arguments from all 'actions' (e.g. find, login, liveQuery, etc...) to the triggers.
As I said the logic is already implemented for some of them and the concept seems to have been accepted.
I make sense to be able to use context in all triggers.
query.find( { context: {example: "abc"} } )
// currently we can use context with beforeFind :)
Parse.Cloud.beforeFind("myClass", async (request) => {
if request.context.example == "abc" {
// To some particular actions
}
})
// currently we can't use context with afterFind :(
Parse.Cloud.afterFind("myClass", async (request) => {
if request.context.example == "abc" {
// To some particular actions
}
})
I hope this feature will help a lot of devs ;)
Thanks for suggesting.
It surely makes sense to further extend context accessibility. Would you be willing to open a PR? It should be fairly straightforward as the existing context implementation already provides some guidance.
Yes I can open a PR to work on it but I'm not an expert parse user so I don't know if I have the capacities to do that.
But I'm totally agree to test and do my first contribution on an amazing open source project ;)
Do you have any documentation for beginner to learn how to work on the project?
Sure, the contribution guide explains how to make changes to Parse Server and contribute these changes as pull request.
Feel free to reach out if you need any guidance.
@mtrezza I tried to understand what I have to do to implement that and to be honest I'm totally lost. Can someone else work on it because we are going to wait a year if I do? x)
@AurelienVasseur i see that you have forker parse-server.
To install the project npm i then you need 2 shells to work on parse server
npm run watch since parse server is compiled over babelnpm test spec/TheSpecFileYouWantToWorkOnIt.spec.jsYou can also in a spec.js file convert a test from it to fit to tell to the jasmine test framework to focus on a particular test
Then if you run npm test Jasmine will only run the focused test.
I can suggest you to explore RestWrite.js and RestQuery.js files, you will find some trigger code 馃槈
@Moumouls thanks a lot for your help :)
I will try to work on it but I can't guarantee a quick result
No problem @AurelienVasseur, just give it a try and advance at your own speed :)
@AurelienVasseur I have merged a PR for context for afterFind, however I believe context still needs to be added for:
-LiveQuery triggers (context on query.subscribe() could possibly get passed through all LQ events)
-Login triggers (context on Parse.User.logIn())
-File Triggers (context on file.save())
@dblythy Thanks a lot 馃槂 I was a little bit lost
I didn't already find the time to work on it but I will try as fast as possible
I'm also not sure if we can use it with fetch, I will check that when I will work on it