Skip to content

Instantly share code, notes, and snippets.

@cevr
Last active November 24, 2021 18:35
Show Gist options
  • Save cevr/9ab1fe498ba8383d13fab8c7aaca26c8 to your computer and use it in GitHub Desktop.
Save cevr/9ab1fe498ba8383d13fab8c7aaca26c8 to your computer and use it in GitHub Desktop.
Cache update after mutation with writeFragment
createCaseFromEvent(result, variables, cache) {
const readEvent = () =>
cache.readFragment(
gql`
fragment _ on CaseManagementEvent {
id
cases {
id
status
}
}
`,
{
id: variables.eventId
}
);
console.log(readEvent());
cache.writeFragment(
gql`
fragment _ on CaseManagementEvent {
id
}
`,
{
id: variables.eventId,
cases: [result.createCaseFromEvent as CaseManagementEventCase]
},
{
id: variables.eventId
}
);
console.log(readEvent());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment