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

Prisma2 CRUD: "before" and "after" hooks #541

Closed
eWert-Online opened this issue Nov 23, 2019 · 5 comments · Fixed by #674
Closed

Prisma2 CRUD: "before" and "after" hooks #541

eWert-Online opened this issue Nov 23, 2019 · 5 comments · Fixed by #674
Labels
type/feat Add a new capability or enhance an existing one

Comments

@eWert-Online
Copy link

When using the crud functionality of nexus-prisma I would like to do something before or after the mutation is executed.
Maybe this can also be used to manipulate the result, which is returned to the client.

For Example:
I am using the t.crud.createOneTicket(); functionality to give the client the ability to create a new ticket.
After the ticket is created I have to create one or multiple stages, the ticket has to go through based on some calculations.

Right now the client would have to do the calculations and send multiple mutations to be able to do this. Which could lead to a corrupted application state on a flaky network.

It would be great, if the crud methods would provide some kind of hooks before and after they are executed. Kind of like how https://github.com/mickhansen/graphql-sequelize#options is doing it:

t.crud.createOneTicket({
  before: (root, args, context) => {
    // do something in here
  },
  after: (result, args, context) => {
    // do something in here
  },
});

This way the crud operations would become much more flexible and operations which are dependent on each other could be executed with just one network request.

@xd-luke
Copy link

xd-luke commented Apr 7, 2020

Yes please!

@mohe2015
Copy link

mohe2015 commented Apr 7, 2020

It would be great if they would also support some authorization hook.

@BjoernRave
Copy link

I could also really use this to log the actions being taken. + 1

@cclaflin89
Copy link

+1

@Weakky Weakky linked a pull request Jun 5, 2020 that will close this issue
@Weakky
Copy link
Member

Weakky commented Jun 5, 2020

This feature was implemented in #674. It's slightly different than this proposal, check out the PR to see the final implementation.

We've just released [email protected].
You can try the feature by installing nexus-prisma@next right now. Feel free to report any bug related to it in here. I'll re-open the issue if needed 🙏

@jasonkuhrt jasonkuhrt added the type/feat Add a new capability or enhance an existing one label Jun 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/feat Add a new capability or enhance an existing one
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants