Related Resources
Endpoints frequently return more than one resource type in a single response. For instance, a request for a single author
may also include the author's books
.
Because different backends return related resources in many different ways, Redux Resource couldn't possibly include a single built-in solution that works for every API. Instead, plugins can be used to support related resources in a way that works for your specific backend.
The rest of this guide will describe supporting related resources for the following technologies:
Would you like us to include a guide for a technology not listed here? Just open an issue!
normalizr
The Included Resources Plugin works well with normalizr data. Refer to the Included Resources Plugin documentation to familiarize yourself with its API.
Here's an example demonstrating using Redux Resource with normalizr on a slice that has the Included Resources Plugin:
If you're using the redux-resource-xhr
library, you can perform this normalization in the onSucceeded
callback:
JSON API
At the moment, the easiest way to support JSON API compound documents is to use the jsonapi-normalizr library, and then follow the normalizr guide above.
An official JSON API plugin is being planned. We would love your help!
If you would like to try your hand at writing a JSON API relationship plugin, here are a few tips. In short, you would need to interpet the included
member of a compound document. This would likely work in 2 steps:
Filter the Array of
included
resources to find just the resources whoseJSON API
type
matches theresourceType
of the slice.Use
upsertResources
to add those resources to the slice.
You would also want to place the each individual resource's meta
into the meta
section of the slice.
GraphQL
We would love to support GraphQL, but we need your help. If you're interested in helping out, please open an issue to chat about it. Thank you!
Last updated