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:

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 4
  • Comments: 36 (23 by maintainers)

Commits related to this issue

Most upvoted comments

I have created the PR for extending the context to following webhooks.

  1. beforeDelete
  2. afterDelete
  3. beforeFind
  4. Cloud Function

https://github.com/parse-community/parse-server/pull/6666

https://github.com/parse-community/Parse-SDK-JS/pull/1159

@yog27ray

I have created the PR for extending the context to following webhooks.

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

context (…) it’s never actually passed to the storage adapter

Correct.

if there are multiple versions of an PFObject stored on a parse-server

I don’t understand what “multiple versions” means in this context so I can’t follow your use case. context is an ephemeral dictionary that is accessible during Cloud Code operations, it is not part of Parse.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 context to 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 🙂