mirror of
https://github.com/sergeyyarkov/todo-app.git
synced 2026-10-11 02:19:04 +03:00
caching
This commit is contained in:
parent
f5eaf9e525
commit
248c505a97
@ -6,6 +6,7 @@ import { useParams } from 'react-router-dom'
|
||||
import { Button, Dialog, DialogActions, DialogContent, DialogContentText, DialogTitle } from '@material-ui/core'
|
||||
import { useMutation } from '@apollo/react-hooks'
|
||||
|
||||
import GET_TODOS from '../../../apollo/queries/todos/todos'
|
||||
import GET_CATEGORIES from '../../../apollo/queries/categories/categories'
|
||||
import DELETE_CATEGORY from '../../../apollo/mutations/categories/deleteCategoty'
|
||||
|
||||
@ -21,6 +22,16 @@ const DeleteCategoryDialog = ({ isOpenDialog, handleCloseDialog }) => {
|
||||
query: GET_CATEGORIES,
|
||||
data: { categories: categories.filter(category => category.id !== deleteCategory.id) }
|
||||
})
|
||||
|
||||
try {
|
||||
const { todos } = cache.readQuery({ query: GET_TODOS })
|
||||
cache.writeQuery({
|
||||
query: GET_TODOS,
|
||||
data: { todos: todos.filter(todo => todo.category.id !== deleteCategory.id) }
|
||||
})
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
@ -16,6 +16,8 @@ const categoryResolvers = {
|
||||
},
|
||||
deleteCategory: async (_, { id }) => {
|
||||
const deletedCategory = await Category.findByIdAndRemove(id)
|
||||
await Todo.deleteMany({ categoryId: id })
|
||||
|
||||
return deletedCategory
|
||||
},
|
||||
updateCategory: (_, { id, title }) => Category.findByIdAndUpdate(id, { $set: { title, updatedAt: new Date().toISOString() } }, { new: true })
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user