Graphql in apollo client: local data is not normalized

Graphql in apollo client: local data is not normalized


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):

Graphql in apollo client: local data is not normalized

How can I normalize my local data as well?

Share
Improve this question


Load 1 more related questions


Show fewer related questions

0

Reset to default



Leave a Reply

Your email address will not be published. Required fields are marked *