From the course: Building a Server with TypeScript and GraphQL
Unlock this course with a free trial
Join today to access over 25,300 courses taught by industry experts.
Mutating data with GraphQL
From the course: Building a Server with TypeScript and GraphQL
Mutating data with GraphQL
- [Instructor] Let's dive into how to mutate data on the server side using GraphQL mutations. GraphQL mutations allow you to modify data on the server side. You can use mutations to create, update, and delete data. Similarly, to writing queries, in mutations, you must specify what specific fields you want to modify, and mutations are written in the schema. Let's dive into some examples. To create data using GraphQL, we can define a mutation that specifies the fields we want to create. In this example, we are creating a new album with the title Renaissance and artist Beyonce. The server will return the created albums ID, title, and artist. To update data using GraphQL, we can define a mutation that specifies the fields we want to update. In this example, we are updating the user with ID 123 and changing their release year to 2022. The server will return the updated albums ID, title, artist, and release year. Here's an example of deleting data using a mutation. In this example, we are…