type-graphql-dataloader icon indicating copy to clipboard operation
type-graphql-dataloader copied to clipboard

Allow specifying multiple connections or a ConnectionManager in ApolloServerLoaderPlugin

Open mscofield0 opened this issue 5 years ago • 4 comments

mscofield0 avatar Dec 14 '20 22:12 mscofield0

What kind of use cases do you assume?

slaypni avatar Jan 11 '21 20:01 slaypni

I have a sqlite in-memory database and a PostgreSQL persistent database at the same time.

rb123454321 avatar Jan 12 '21 10:01 rb123454321

Can you try this PR and see if it works for you.

https://github.com/slaypni/type-graphql-dataloader/pull/14

malisetti avatar Mar 15 '21 14:03 malisetti

I think maybe my use case is different than the OP, but I think passing context into typeormGetConnection in ImplicitLoaderImpl would allow people like myself who want all queries for a given request to go over the same connection to be possible.

I do some initialization of connections from the pool by setting mysql connection variables, so a connection has been pulled from the pool and stored on the context. I can make all other load operations use this context connection, but since the data-loaders use the top level pool, they will 'randomly' grab another connection, which can cause issues with mysql connection TIME_ZONE, etc. I think this would be as simple as changing line 37 of ImplicitLoaderImpl.js from:

            const relation = tgdContext
                .typeormGetConnection()
                .getMetadata(target.constructor)
                .findRelationWithPropertyPath(propertyKey.toString());

to:

            const relation = tgdContext
                .typeormGetConnection(context)
                .getMetadata(target.constructor)
                .findRelationWithPropertyPath(propertyKey.toString());

This would give a program access to any context-specific information/connections/etc when handling the loading operations for a given request.

DillonSadofsky avatar Mar 24 '22 14:03 DillonSadofsky