Giter Club home page Giter Club logo

Comments (3)

Mando75 avatar Mando75 commented on May 30, 2024

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.

shajeeck avatar shajeeck commented on May 30, 2024

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.

Mando75 avatar Mando75 commented on May 30, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.