First of all, thanks for the awesome work on this project!
For a set of web applications I'm working on atm, some users need to be able to register new users. To do so, we need to insert them into the database (which postgraphile handles wonderfully), but also register new users with an external vendor via their REST API.
I thought I'd use makeWrapResolversPlugin to write a little function to do so, but encounter some questions which I can't really seem to figure out:
Thanks in advance!
Postgres 13
Node 14.14.0
Postgraphile 14.9.0
The approach you outline (performing the action after the transaction completes) is very vulnerable to temporary failures. It can mean that the user is successfully created but due to a network error never gets created on the external vendor.
If it's not reasonable to do this as part of the transaction (so that you can roll back on failure), a much better approach would be to use a job queue for this. Create a trigger on the users table that queues a job when a user is inserted, and then have the worker upload to the external vendor API, automatically retrying with exponential backoff in the case of errors.
Check out: https://github.com/graphile/worker
[semi-automated message] Thanks for your question; hopefully we're well on the way to helping you solve your issue. This doesn't currently seem to be a bug in the library so I'm going to close the issue, but please feel free to keep requesting help below and if it does turn out to be a bug we can definitely re-open it 👍
You can also ask for help in the #help-and-support channel in our Discord chat.
Thanks for your quick response @benjie ! I'll be looking into this.