0
I want to normalize (i.e. flatten nested elements) my graphql’s local cache for efficiency reasons (otherwise a change in a nested item would redraw all components). My understanding was that Apollo would automatically normalize the cache… but apparently it seems like I misunderstood. Indeed, if I do:
const IS_LOGGED_IN = gql`
query IsUserLoggedIn {
isLoggedIn @client
items @client {
name @client
quantity @client
}
}
`;
client.writeQuery({
query: IS_LOGGED_IN,
data: {
isLoggedIn: false,
items: [
{name: "Oranges", quantity: "5"},
{name: "Pears", quantity: "10"},
]
},
});
then the dev tools shows non-normalized items (the structure is nested instead of flat) which are nested (for comparison, the Location
items are normalized elements, coming from a query to an external database):
How can I normalize my local data as well?