Why are GraphQL __typename fragments needed in queries?

I canโ€™t find, or Iโ€™m looking in the wrong place where you can find documentation on how the fragments match. When I use the vanilla Apollo client, if I turn off the option addTypename, when I use fragments, I get a warning heuristic fragment matching going on!, and if I add it, it will disappear, but my answer contains many fields __typenamethat I do not use if necessary. Why do they help?

+9
source share
1 answer

The reason for this is that ApolloClient, like Relay, uses global storage to cache your data on the client.

, . , - , , , , Relay.

ApolloClient ! ( Apollo , ). , ! typename id , Relay . .

, Apollo , (, , ). .

, :

const cache = new InMemoryCache({
  dataIdFromObject: object => object.key || null
});

https://www.apollographql.com/docs/react/advanced/caching.html#normalization

+6

Source: https://habr.com/ru/post/1683019/


All Articles