I would like to ask why I cannot delete data on graphql using react.js and apollo?... The code doesn't give any errors... I have tried deleting on graphiql and on django-admin(server-side)and it works just fine...
const QUERY_CLIENTS = gql`
query{
allClients{
id
age
name
gender
homeAddress
contactNumber
emailAddress
}
}
`;
const DELETE_CLIENT = gql`
mutation deleteClient($id: Int!){
deleteClient(id:$id){
client{
id
}
}
}
`;
function DisplayClients(){
const {loading, error, data} = useQuery(QUERY_CLIENTS);
const [deleteClient] = useMutation(DELETE_CLIENT);
const removeClient = (id) => {
deleteClient(
{
variables: {
id: id
}
}
);
window.location.reload();
}
if (loading) return <p>loading...</p>;
if(error) return <p>Error: (</p>;
return data.allClients.map(({id, age, name, gender, homeAddress, contactNumber, emailAddress}) => (
<div key={id}>
<p>
{id} {name} {age} {gender} {homeAddress} {contactNumber} {emailAddress}
<button onClick={() => removeClient(id)}>Delete</button>
</p>
</div>
));
}
Thank you :)