When merge function called for TypePolicy object?

Hey there! I can’t find it in the documentation, so I hope for explain.

For example I have:

const client = new ApolloClient({
    link: from([authMiddleware, errorMiddleware, httpLink]),
    cache: new InMemoryCache({
        possibleTypes,
        typePolicies: {
            User: {
                merge: (existing, incoming, { mergeObjects }) => mergeObjects(existing, incoming),
            },
        },
    }),
});

When the merge callback will be called?

Hi bro!

In the docs:

The merge function

If you define a merge function for a field, the cache calls that function whenever the field is about to be written with an incoming value (such as from your GraphQL server). When the write occurs, the field’s new value is set to the merge function’s return value, instead of the original incoming value.

You can read more here: Customizing the behavior of cached fields - Apollo GraphQL Docs