Open hcharley opened 4 years ago
Is there a reason to not simply const helpers = require('../helpers')
inside the worker?
No, that seems like a good solution. I can try that out. Thanks!
[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.
@benjie Just encountered this.
The TODO is still there and I believe that in certain situations this would allow for much more pleasurable DX.
For example in our case we have set up nodemailer instance for fastify route plugin consumption. All setup and "service" init is defined in server.ts
. All works beautifully.
But then I integrated Graphile Worker and now I need the nodemailer instance in my tasks to send e-mails. Would be elegant as heck with helpers
object augmentation. Without it, I have to refactor.
Not the end of the world, don't get me wrong, Graphile Worker is an amazing alternative to pg-boss
!
But this little thing would definitely make it even better.
Usecase
Give users of graphile-worker the ability to pass in custom helpers. This could include custom database connection objects, metadata, application-specific helpers, etc...
For example:
My specific usecase is to pass a Slonik database connection object.
Implementation
https://github.com/graphile/worker/blob/1d4fa8c08f10f49eaca2343365a5db2b477206bf/src/helpers.ts#L71
It looks like if this TODO was done, this usecase could be satisified.
I'm not sure what the ultimate implementation would look like. Would there be a specific file like
helpers.ts
that would be loaded and named exports would automatically be included?Pitfalls/Things to watch out for