Last active
March 23, 2021 16:38
-
-
Save lydemann/defcbb2c33c14e9a69b1ac5ca15d26f3 to your computer and use it in GitHub Desktop.
course-facade.service.ts
This file contains 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
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