Skip to content
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 trigger context accessible in all triggers #7058

Open
AurelienVasseur opened this issue Dec 11, 2020 · 9 comments
Open

Make trigger context accessible in all triggers #7058

AurelienVasseur opened this issue Dec 11, 2020 · 9 comments
Labels
type:feature New feature or improvement of existing feature

Comments

@AurelienVasseur
Copy link

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

@mtrezza
Copy link
Member

mtrezza commented Dec 11, 2020

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.

@AurelienVasseur
Copy link
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?

@mtrezza
Copy link
Member

mtrezza commented Dec 11, 2020

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.

@AurelienVasseur
Copy link
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)

@Moumouls
Copy link
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 😉

@AurelienVasseur
Copy link
Author

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

@Moumouls
Copy link
Member

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

This was referenced Dec 16, 2020
@dblythy
Copy link
Member

dblythy commented Dec 20, 2020

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

@AurelienVasseur
Copy link
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

@mtrezza mtrezza added type:feature New feature or improvement of existing feature and removed type:improvement labels Dec 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:feature New feature or improvement of existing feature
Projects
None yet
Development

No branches or pull requests

4 participants