7 Optimizing data fetching
This chapter covers
- Caching and batching data-fetch operations
- Using the DataLoader library with primary keys and custom IDs
- Using GraphQL’s union type and field arguments
- Reading data from MongoDB
Now that we have a GraphQL service with a multimodel schema, we can look at one of GraphQL’s most famous problems, the N+1 queries problem. We ended the previous chapter with a GraphQL query that fetches data from three database tables.
{ taskMainList { // ·-·-· author { // ·-·-· } approachList { // ·-·-· author { // ·-·-· } } } }
Because the GraphQL runtime traverses the tree field by field and resolves each field on its own as it does, this simple GraphQL query resulted in a lot more ...
Get GraphQL in Action now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.