Apollo duplicates the first result on each node in an array of edges

I am working on a reaction application with a reaction-apollo calling data via graphql, when I check the response to a tab on the browser network, it shows all the elements of the array are different but what I get, or console.log()in my application, then all the elements of the array are the same, like the first element. I do not know how to fix, please help

+4
source share
2 answers

Put it in your App.js

cache: new InMemoryCache({
    dataIdFromObject: o => {o.id ? `${o.__typename}-${o.id}`: `${o.__typename}-${o.cursor}`},
  })
+2
source

, "" Apollo. AKA, . , Symbol(id).

Apollo, , Symbol(id), Apollo. , Symbol(id), . ?

Apollo .

export function defaultDataIdFromObject(result: any): string | null {
  if (result.__typename) {
    if (result.id !== undefined) {
      return `${result.__typename}:${result.id}`;
    }
    if (result._id !== undefined) {
      return `${result.__typename}:${result._id}`;
    }
  }
  return null;
}

. _id = null, - . null, docs

InMemoryCache , ROOT_QUERY.allPeople.0 , allPeople.

, , defaultDataIdFromObject.

, dataIdFromObject, InMemoryCache ApolloClient. , _id __typename.

const client = new ApolloClient({
  link: authLink.concat(httpLink),
  cache: new InMemoryCache({
    dataIdFromObject: o => (o._id ? `${o.__typename}:${o._id}`: null),
  })
});
0

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


All Articles