Last active
March 5, 2020 02:17
-
-
Save seandearnaley/40c07b6a76028c83abd9a43d90f2e6ad to your computer and use it in GitHub Desktop.
Type & Field Policy API example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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