Skip to content

Make trigger context accessible in all triggers #7058

Open

Description

@AurelienVasseur

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 ;)

Activity

  1. mtrezza commented on Dec 11, 2020

    @mtrezza
    Member

    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.

  2. AurelienVasseur commented on Dec 11, 2020

    @AurelienVasseur
    Author

    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?

  3. mtrezza commented on Dec 11, 2020

    @mtrezza
    Member

    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.

  4. AurelienVasseur commented on Dec 11, 2020

    @AurelienVasseur
    Author

    @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)

  5. Moumouls commented on Dec 12, 2020

    @Moumouls
    Member

    @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

    • First shell: npm run watch since parse server is compiled over babel
    • Second shell: npm test spec/TheSpecFileYouWantToWorkOnIt.spec.js

    You 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 😉

  6. AurelienVasseur commented on Dec 12, 2020

    @AurelienVasseur
    Author

    @Moumouls thanks a lot for your help :)
    I will try to work on it but I can't guarantee a quick result

  7. Moumouls commented on Dec 12, 2020

    @Moumouls
    Member

    No problem @AurelienVasseur, just give it a try and advance at your own speed :)

  8. dblythy commented on Dec 20, 2020

    @dblythy
    Member

    @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())

  9. AurelienVasseur commented on Dec 20, 2020

    @AurelienVasseur
    Author

    @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

  10. added
    type:featureNew feature or improvement of existing feature
    and removed on Dec 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type:featureNew feature or improvement of existing feature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions