Skip to content

Instantly share code, notes, and snippets.

@seandearnaley
Last active March 5, 2020 02:17
Show Gist options
  • Save seandearnaley/40c07b6a76028c83abd9a43d90f2e6ad to your computer and use it in GitHub Desktop.
Save seandearnaley/40c07b6a76028c83abd9a43d90f2e6ad to your computer and use it in GitHub Desktop.
Type & Field Policy API example
export const cache = new InMemoryCache({
...possibleTypes,
typePolicies: {
Query: {
fields: {
card(existingData, { args, toReference }) {
return (
existingData || toReference({ __typename: 'Card', id: args?.id })
);
},
category(existingData, { args, toReference }) {
return (
existingData ||
toReference({ __typename: 'Category', id: args?.id })
);
},
},
},
Card: {
fields: {
categories: {
keyArgs: [],
},
},
},
Category: {
fields: {
cards: {
keyArgs: [],
merge(existing, incoming, { args }) {
return incoming; // this example is just returning the incoming
},
},
},
},
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment