4.4 Deleting Tasks

Lastly, we want to allow our users to be able to delete tasks.

Step 1: Write Mutation

Let's write a mutation to delete our task.

src/components/TaskDeleteButton/DeleteTaskMutation.graphq l.ts
import gql from 'graphql-tag';

export const DeleteTaskMutation = gql`
	mutation DeleteTaskMutation($id: UUID!) {
		deleteFromtasksCollection(filter: { id: { eq: $id } }) {
			records {
				id
			}
		}
	}
`;

Step 2: Generate Typings

We will now generate typescript interfaces for our GraphQL API. Execute the following command:

yarn graphql-codegen

This will update the file src/graphql-types.ts.

Step 3: Create Delete Button

Now lets an IconButton to delete the task.

Step 4: Add Button to EditTaskScreen

Modify the EditTaskScreen to add the headerRight option:

This should be the result:

Web
iOS

Last updated

Was this helpful?