Comments (3)
am hoping there's some prior art from others I can learn from
Sorry, this isn't something that much to us since we use IdentityCache to cache whole rows, so haven't implemented it.
I am struggling to understand if / how its possible to have the sub-fields of the field requested affect the loader's strategy.
It could be implemented by doing the loads at the field level for the specific column that you need. In this case your cache key would be an [id, column_name] pair. E.g. it could have an interface like this
ColumnLoader.for(User).load([user_id, :first_name])
Then in ColumnLoader#perform you could collect the set of columns to use in the query.
If you need a different set of columns for each record, then you get into the question of whether it is better to over-fetch by doing a single query for the superset of fields for all records, or whether you would prefer to do separate queries for each group of records that are loading the same set of columns.
from graphql-batch.
Another option would be to use GraphQL::Execution::Lookahead to figure out what subfields are requested to have it influence the query.
I think the simplest way to handle this would be to group by ast nodes (e.g. lookahead.ast_nodes
) so that it performs a single query for that field selection for all of its parent objects. GraphQL::Batch::Loader could overridden to be able to pass in the Lookahead object but use the Lookahead#ast_nodes
for the key for grouping.
The more difficult part is to determine what database columns are needed based on the GraphQL subfield selections. This is also something that is outside the scope of this library.
from graphql-batch.
I think this is an interesting discussion as I am as well looking for a solution to eager load records while selecting only requested columns. I believe Lookahead
is the right approach to that as it serves exactly that purpose.
I understand and respect why it's outside the scope of this library to implement a proper mechanism for selecting. As you already said the Loader needs to be overwritten. I believe it'll be quite some overwrites, probably not just one. This kind of monkey patching is definitely not my preferred way of doing it and I am wondering if you're open to investigate if there is a nice and clean way for this library to provide an interface allowing to extend the related parts.
I would also love to hear if anyone else already got a clean implementation where batch loading and selecting works side by side?
from graphql-batch.
Related Issues (20)
- Difficult to integrate graphql-ruby with graphql schema loaded from a `.graphql` file HOT 3
- Release new Gem version to fix class definition syntax? HOT 2
- through association loader order issue HOT 1
- How do you paginate responses when using AssociationLoader? HOT 7
- [graphql v1.10.0.pre2] undefined method `target`
- clarify GraphQL::Batch.batch documentation HOT 2
- [proposal] Integrate Rubocop
- [question] Using inverse ActiveRecord associations to avoid N+1 queries? HOT 3
- Add a changelog HOT 1
- Ruby 2.7 keyword arguments warning HOT 3
- Loaders that are nested / based on another HOT 2
- How to Implement Pagination with AssociationLoader using Connections? HOT 2
- Thoughts on hashing ActiveRecord relations?
- ActiveRecord::Associations::Preloader is private API
- Loader for has_many_attached HOT 1
- Nested loader doesn't work HOT 2
- fulfilled? always returns false even if it's fulfilled with promise HOT 1
- Love HOT 1
- N+1 problem happen with using Time.current in where sentence(maybe) HOT 2
- If a loader's perform method raises an exception after all promises have been fulfilled, it's silently dropped
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 graphql-batch.