Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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