Skip to content

Instantly share code, notes, and snippets.

@lydemann
Last active March 23, 2021 16:38
Show Gist options
  • Save lydemann/defcbb2c33c14e9a69b1ac5ca15d26f3 to your computer and use it in GitHub Desktop.
Save lydemann/defcbb2c33c14e9a69b1ac5ca15d26f3 to your computer and use it in GitHub Desktop.
course-facade.service.ts
editCourseSubmitted(editedCourse: Course) {
return this.apollo.mutate<Course>({
mutation: EDIT_COURSE_MUTATION,
variables: {
id: editedCourse.id,
name: editedCourse.name,
description: editedCourse.description,
} as Course,
});
}
createCourseSubmitted(course: Course) {
const getCoursesQuery = this.courseResourcesService.GET_COURSES_QUERY;
return this.apollo.mutate<{ createCourse: Course }>({
mutation: CREATE_COURSE_MUTATION,
variables: {
name: course.name,
description: course.description,
} as Course,
update(cache, { data }) {
createInCache<GetCoursesResponseDTO>(
data?.createCourse,
getCoursesQuery,
cache,
'course'
);
},
});
}
deleteCourseSubmitted(courseId: string) {
const getCoursesQuery = this.courseResourcesService.GET_COURSES_QUERY;
return this.apollo.mutate<{ deleteCourse: Course }>({
mutation: DELETE_COURSE_MUTATION,
variables: {
id: courseId,
} as Course,
update(cache, { data }) {
removeFromCache<GetCoursesResponseDTO>(
data.deleteCourse,
getCoursesQuery,
cache,
'course'
);
},
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment