Comments (3)
Yes you could. If you wanted to, you can just initialize a new loader inside your resolver and/or service layer as long as it has access to the query info object. However, if you follow this approach you will lose most of the caching abilities the loader provides. The loader uses memoization to cache queries, so creating a new instance breaks that. Facebook's dataloader does something similar, so take a look at their docs if you want a more in-depth explanation https://github.com/graphql/dataloader#caching.
I can take a look at adding in the ability to pass in a custom connection somewhere in the loader chain, but I feel like it may take some significant work.
from typeorm-graphql-loader.
Well, Facebook's dataloader is the approach i am using now with TypeOrm.
A sample project for extracting Args and Fields ready for where, select and pagination
to build queries using TypeOrm Repository createQueryBuilder
from the GraphQL at service level would be a great help, for a decoupled TypeOrm query builder from GraphQL
something like https://join-monster.readthedocs.io/
from typeorm-graphql-loader.
I've looked into this a bit and adding the ability to submit a custom connection per query is going to interfere with some of the underlying queue logic that is used to cache/resolve queries. I only just finished refactoring most of the code-base and don't really have time to do it all over again at the moment. Perhaps down the line for a v2.
without knowing a lot about your service layer implementation, my thought would be to just initialize a loader in each of your services on each request and either add it to your service context, or attach it to your request object. That way at least the caching will work on a per-service level.
If you would like to see how this project extracts the fields and relations that need to be joined, see the GraphQLInfoParser class.
I believe there are also packages out there that you can use to pull these things out of the info object. I chose to implement my own to prevent having to monitor another dependency.
from typeorm-graphql-loader.
Related Issues (16)
- export builder and other important types in the entry file please HOT 2
- Support for named columns HOT 4
- column "createdat" does not exist HOT 5
- use a related table for where() and order() HOT 12
- Thanks! HOT 1
- ConfigureLoader Not working! HOT 13
- Support Data Mapper entities HOT 1
- Ordering of sub relations
- Redundant typeof BaseEntity typing HOT 1
- How to properly implement resolvers? HOT 5
- [Question] How does this library handle field resolvers? HOT 2
- Small fix for graphqlQueryBuilder.ts HOT 2
- Pagination query not selecting correct fields HOT 5
- Support nested/inherited types fields HOT 10
- Incorrect typing for `where` HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from typeorm-graphql-loader.