Optimize database queries to only pull out fields actually requested
See original GitHub issueCan use the info
parameter passed to the resolver to pick out only the fields.
Eg, given this schema:
type User {
id: ID!
name: String
avatar: Blob
longVideo: Blob
}
When we do a query like:
User(id: "foobar") {
id
name
}
We don’t want to pay the cost of pulling the avatar
and longVideo
out of the database.
In the resolver, we can use the info
parameter to see what fields are actually requested:
const resolvers = {
User: (_, { id }, context, info) => {
const nodeQueryInfo = info.fieldNodes[0]; // 0th is always the currently resolving node
const fields = nodeQueryInfo.selectionSet.selections.map(({ name }) => name.value);
return db.findById(id, fields); // (or `SELECT ${fields.join()} FROM ...`, etc)
},
};
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Query optimization techniques in SQL Server: tips and tricks
In this blog post we will show you step by step some tips and tricks for successful Query optimization techniques in SQL Server....
Read more >Supercharge Your SQL Queries for Production Databases
Discover simple techniques you can start using today to optimize your SQL when querying production databases, with real-life examples.
Read more >SQL Query Optimization: 12 Useful Performance Tuning Tips ...
Read the tutorial to learn more about SQL Server performance tuning best practices that help greater improve SQL Server query optimization.
Read more >Chapter 4. Query Performance Optimization - O'Reilly
In the previous chapter, we explained how to optimize a schema, which is one of the necessary conditions for high performance.
Read more >Performance Tuning SQL Queries | Advanced SQL - Mode
Learn how to conduct SQL performance tuning by reducing table size, simplifying joins, & the EXPLAIN command in this advanced SQL tutorial.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
From https://github.com/keystonejs/keystone-5/pull/665#discussion_r
🤔 The test could be
Nope, this issue is still in the category of nice to have, but tricky to implement.