pg-promise-demo | : eyeglasses : Advanced example of using pg-promise | Runtime Evironment library
kandi X-RAY | pg-promise-demo Summary
kandi X-RAY | pg-promise-demo Summary
This is an advanced demo of the best practices of using [pg-promise], and managing your database architecture. It shows how to organize an enterprise-level database application, with consideration for ever-growing complexity of the database and queries.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of pg-promise-demo
pg-promise-demo Key Features
pg-promise-demo Examples and Code Snippets
Community Discussions
Trending Discussions on pg-promise-demo
QUESTION
First thing is to say that I have seen this question Sharing a pg-promise task across parts of an http request and read the answer. I'd like to revisit the question with some added complication.
I am working on a typescript graphql server on apollo-server-express
using a postgres database as the backend and pg-promise
as the database interface library. I have query resolvers using dataloaders using the pattern described here: https://github.com/graphql/dataloader#creating-a-new-dataloader-per-request.
All database access occurs via a single instance of pg-promise
as recommended e.g. https://github.com/vitaly-t/pg-promise-demo/blob/master/TypeScript/db/index.ts.
Like the original question, I am trying to find a good way to create a Task that can be incorporated into the dataloaders (or passed as a param when the dataloader is called) such that query resolvers operate within a single database connection. I don't know which resolvers will be called or in which order they will be called so I can't say that a certain resolver should create the task.
I've been trying to figure a way to use the graphql Context
to share the task as I am currently using the Context
to share the dataloaders object but as was noted, all calls in the task happen within a callback function so sharing the task via the Context
is out. Here's an example of how the context is setup:
ANSWER
Answered 2020-Sep-22 at 03:02The fact that you're using DataLoader here is largely irrelevant. Like you already suggested, you just need to pass whatever instance you're using to call the query
method to createLoaders
. If you weren't using DataLoader, you would still be left with the same question, namely, how do we create a Task and make it available to all our resolvers.
As far as I'm aware, the only way to do that with Apollo Server is to create a custom plugin. You can check out this gist which demonstrated the same principle except with transactions. Effectively, you'd do something like:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install pg-promise-demo
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page