Details
-
Story
-
Resolution: Fixed
-
High
-
2.5.0-beta1
-
None
Description
Optimize loading of data in the GraphQL API to avoid multiple loadings of the same item.
Summary of data loading
For the following query:
{ content { blogPosts { title body { html5 } } } }
data loading goes that way:
- the blog post content items are loaded using `ContentService::findContentInfo()`
- for each requested field (title, body), the content item is loaded using contentService::loadContent(), and the field's value is returned.
This results in an n*m complexity, with n the number of content items and m the number of requested fields.
Options
In-memory caching
Add a data-loader layer that is always used to load items, and have it cache each loaded item in memory, and return that item when it gets loaded.
Pro
- Generalizing a data-loader matches the GraphQL server implementation standards
Cons
- It adds an extra layer
Load content instead of content info
If instead of findContentInfo() we use findContent(), the underlying fields would receive the full `Content` item, and wouldn't have to fetch it again.
Pros
- doesn't require an extra layer
Cons
- doesn't separate the data loading logic from the resolvers
- might not always be applicable as it is limited to loading content (content type already has its own in-memory cache)