i am trying to learn and apply graphql apollo in react projects. i created express server. I learned how to do queries and some mutations but i got stuck in creating the delete mutation. i have a mock json data. i fetch the data from there and created a mutation to delete the item. in the network tab i can see the right id in the variable section but when i refresh the user is still there. i am sharing all the thing related to deleting. i search all around but no luck. any help would be very much appreciated.
deleteUser Resolver:
deleteUser: {
type:UserType,
args: {
id: { type: GraphQLInt },
},
resolve(parent, args) {
userData.filter((user) => user.id !== args.id);
return args;
},
},
},
delete mutation:
export const DELETE_USER = gql`
mutation deleteUser($id: Int) {
deleteUser(id: $id) {
id
}
}
`;
delete function:
const handleDeleteUser = (id) => {
deleteUser({
variables: { id },
});
const newUsers = users.filter((item) => item.id !== id);
setUsers(newUsers);
};
Read more here: https://stackoverflow.com/questions/66276963/how-to-create-resolver-in-schema-for-delete-mutation-in-graphql-apollo
Content Attribution
This content was originally published by emira at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.