Wednesday 18 December 2019

Sharing DB connection in GraphQL

I’m re-writing a terrible hand rolled di injection container at work to share our aws-sdk client, amongst other things. We’re using GraphQL so I first thought, why not put it in Context? The further I got, I found services being instanced above resolver scope with access to Context, so then I moved it up to instanciating in a function that creates the schema. But then, I had another idea.. why am I doing this at all? Can’t I just do:// dB.js export default createConnection(); // service.js import dB from dB Create an effectively singleton instance, then import where needed? It looks perfectly testable and massively more convenient than passing through function calls. Is this actually a bad idea for any reason?

Submitted December 18, 2019 at 04:38PM by stashrx

No comments:

Post a Comment