-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for embedding and prefetching #10270
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Problem Pages aggregating data from more than one resource always have to fetch more than one API endpoint in cascade, and with a slow backend this leads to a blinking UI. For example, the Comment detail page in the simple example has to call `dataProvider.getOne('comments', { id })`, then `dataProvider.getMany('posts', { ids: [comment.postId] })`. Some backends are capable of embedding related records (e.g. the post of a comment). Populating the cache based on these embeds is possible, but cumbersome. ## Solution Add first-class support for the `_embed` key in response metadata, and populate query cache from it. ## TODO - [x] Allow every data provider method to return a response `meta` - [x] Update `useDataProvider` to populate query cache when a response contains a `meta: { _embed }` - [x] Update the fakerest data provider to support embeds. - [x] Update the simple example to use embeds in the comment list and show views. - [ ] add tests - [ ] Add doc
Note: json-server supports embeds |
djhi
reviewed
Oct 11, 2024
fzaninotto
changed the title
Add support for embeds in query responses
Add support for embedding and prefetching
Oct 11, 2024
djhi
requested changes
Oct 14, 2024
Co-authored-by: Gildas Garcia <1122076+djhi@users.noreply.github.com>
slax57
requested changes
Oct 15, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Incredible feature! And the actual implementation is actually not as hard as I would have imagined.
Love it!
Co-authored-by: Jean-Baptiste Kaiser <jb@marmelab.com>
djhi
approved these changes
Oct 16, 2024
slax57
approved these changes
Oct 16, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
Pages aggregating data from more than one resource always have to fetch more than one API endpoint in cascade, and with a slow backend this leads to an incomplete and blinking UI.
For example, the Comment list page in the simple example shows the post for each comment. So it has to fetch
dataProvider.getList('comments')
, thendataProvider.getMany('posts', { ids: [comment postIds] })
(via<ReferenceField>
).Some backends are capable of embedding related records (e.g. the post of a comment). However, populating the cache based on these embeds is cumbersome.
Solution
TODO
meta
useDataProvider
to populate query cache when a response contains ameta: { prefetched }
ra-data-fakerest
ra-data-json-server
[ ] Add support for embedding and prefetching to(out of scope)ra-data-simplerest
prefetch
in the comment list and show views.