Yes
The way it currently works (version 0.5 of apollo-client), with the function dataIdFromObjectthat the constructor takes ApolloClient.
If all nodes received a field id, and they are unique in all nodes (for example, in Graphcool we generate unique identifiers with this library ):
import ApolloClient from 'apollo-client';
const client = new ApolloClient({
dataIdFromObject: o => o.id
});
You must include a field idin every query that you want to normalize.
If your identifiers are unique to each type only, you can combine them with __typenameto create unique identifiers:
const client = new ApolloClient({
dataIdFromObject: (result) => {
if (result.id && result.__typename) {
return result.__typename + result.id;
}
return null;
},
});
The code is taken from the official Apollo documentation .
source
share