As someone who is new to Typescript and GraphQL, I recently implemented CRUD functionalities in a To-Do list. However, I am facing a challenge when it comes to including messages within GraphQL responses. Specifically, when I delete a User, I would like the response to include deleted: true
.
So far, I have successfully created all the necessary logic to delete a User.
Here is my Delete User mutation:
import { getRepository } from 'typeorm';
import { Entities } from '../../../entities/entities';
export const deleteUserMutation = {
async deleteUser(_, { id }): Promise<typeof user> {
const repository = getRepository(Entities.user);
const user = await repository.findOne({ id });
await repository.delete({ id });
return {
...user,
};
},
};
User Mutation schema snippet:
export const UserMutation = `
extend type Mutation {
createUser (
user: NewUserPatch!
): User
updateUser (
id: String!
patch: UserPatch!
): User
deleteUser (
id: String!
): User
}
`;
If there are additional details you'd like me to provide, please let me know so I can include them.
To summarize my issue, I need the response message to indicate that the deletion was successful:
{
"data": {
"deleteUser": {
"deleted": true
}
}
}