parse-server: Make trigger context accessible in save
Is your feature request related to a problem? Please describe. Sometimes an object should be saved with custom execution in its triggers (e.g. afterSave).
Describe the solution you’d like
It should be possible to pass arguments from the save call to the triggers. There is already a context object that is passed from beforeSave to afterSave. It would be practical to make the context accessible in the save call as an option, e.g.:
object.save(null, {context: {myArg: true}});
Parse.Cloud.beforeSave('MyClass', req => {
let myArg = req.context.myArg;
});
TODOs:
- Changes in JS SDK https://github.com/parse-community/Parse-SDK-JS/pull/1150
- Changes in Parse Server https://github.com/parse-community/parse-server/pull/6626
- Changes in docs https://github.com/parse-community/docs/pull/730
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 4
- Comments: 36 (23 by maintainers)
Commits related to this issue
- fix(direct-access): save context not present if direct access enabled [Open discussion](https://github.com/parse-community/parse-server/issues/6459) for feature with other issues — committed to parse-community/parse-server by omairvaiyani 4 years ago
- fix(direct-access): save context not present if direct access enabled (#6764) * fix(direct-access): save context not present if direct access enabled [Open discussion](https://github.com/parse-com... — committed to parse-community/parse-server by omairvaiyani 4 years ago
I have created the PR for extending the context to following webhooks.
https://github.com/parse-community/parse-server/pull/6666
https://github.com/parse-community/Parse-SDK-JS/pull/1159
@yog27ray
Great job! Can you please open a new issue for these PRs as this issue will be closed with the next release of parse server. And can you please add a PR for the docs if necessary, that would put a smile on @TomWFox’s face.
@cbaker6
Correct.
I don’t understand what “multiple versions” means in this context so I can’t follow your use case.
contextis an ephemeral dictionary that is accessible during Cloud Code operations, it is not part ofParse.Object. I think the example in https://github.com/parse-community/parse-server/issues/6459#issue-574366270 describes it well.No contrary voices, so I assume we’ll expose
contextto the clients. I also just stumbled across https://github.com/parse-community/parse-server/issues/6323 which gives a use case for making the context accessible to clients.@acinader It would be great if the next release of parse server could be coordinated with the next JS SDK release to coherently introduce this feature. The JS SDK PR has already been merged.
The test cases in https://github.com/parse-community/parse-server/pull/6626 should pass with the next JS SDK release.
@jonas-db Good to see that there is demand for such a feature. That gave me some motivation to pick it up again 🙂