I am learning apollo and graphQL and have a simple application that displays a list of data, with a fetchMore function that adds to the array.
I would like to remove the updateQuery as it is being deprecated and use the new field policy merge function. The current cache setup and updateQuery looks like this:
const cache = new InMemoryCache({
typePolicies: {
client_client: {
fields: {
// add local only value to clients
isEdited: {
read(value = false) {
// when writing the new value return new value or false as default
return value;
},
}
}
}
}
});
const onFetchMore = () => {
fetchMore({
variables: {
offset: page
},
updateQuery: (previousResult, { fetchMoreResult, queryVariables }) => {
return {
...previousResult,
client_client: [
...previousResult.client_client,
...fetchMoreResult.client_client,
],
};
},
});
}
However I cannot seem to get it to work as a merge function within the cache for apollo client v3. I have tried adding the merge in many different places however it always seems to break the application.
Any help on how to do this would be appreciated.