Adding mutations
In the previous section, we learned how to create a GraphQL API using HotChocolate. We added a query root type to query data. In this section, we will discuss how to modify data using mutations.
Mutations are used to modify data in GraphQL. A mutation consists of three parts:
- Input: The input is the data that will be used to modify the data. It is named with the
Input
suffix following the convention, such asAddTeacherInput
. - Payload: The payload is the data that will be returned after the mutation is executed. It is named with the
Payload
suffix following the convention, such asAddTeacherPayload
. - Mutation: The mutation is the operation that will be executed. It is named as verb + noun following the convention, such as
AddTeacherAsync
.
Let us add a mutation to create a new teacher. We will use the following steps:
- Create an
AddTeacherInput
class in theGraphQL/Mutations
folder, as shown here:public record AddTeacherInput( ...