Skip to content

Instantly share code, notes, and snippets.

@DuncanFaulkner
Created March 22, 2021 20:41
Show Gist options
  • Save DuncanFaulkner/57a6c3120a51bee911e226a88df5dd5e to your computer and use it in GitHub Desktop.
Save DuncanFaulkner/57a6c3120a51bee911e226a88df5dd5e to your computer and use it in GitHub Desktop.
add update
ADD_COURSE,
{
update (cache, { data }) {
const newCourseFromResponse = data?.addCourse.course;
const existingCourses = cache.readQuery<GetAllCourses>({
query: GET_ALL_COURSES,
});
if (existingCourses && newCourseFromResponse) {
cache.writeQuery({
query: GET_ALL_COURSES,
data: {
toCourses: [
...existingCourses?.courses,
newCourseFromResponse,
],
},
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment