Write data through GraphQL with mutations. Input types, custom scalars, server-side validation, and the error handling patterns that give clients actionable feedback.
Write data through GraphQL with mutations. Input types, custom scalars, server-side validation, and the error handling patterns that give clients actionable feedback.
const typeDefs = `#graphql
type Mutation {
createUser(input: CreateUserInput!): User!
updateUser(id: ID!, input: UpdateUserInput!): User!
deleteUser(id: ID!): Boolean!
createPost(input: CreatePostInput!): Post!
}
input CreateUserInput {
name: String!
email: String!
}
input UpdateUserInput {
name: String
email: String
}
input CreatePostInput {
title: String!
body: String
authorId: ID!
}
`
const resolvers = {
Mutation: {
createUser: (_, { input }) => {
const user = { id: String(users.length + 1), ...input };
users.push(user);
return user;
},
updateUser: (_, { id, input }) => {
const user = users.find(u => u.id === id);
if (!user) throw new Error('User not found');
Object.assign(user, input);
return user;
},
deleteUser: (_, { id }) => {
const idx = users.findIndex(u => u.id === id);
if (idx === -1) return false;
users.splice(idx, 1);
return true;
},
}
};mutation CreateUser {
createUser(input: {
name: "Carol"
email: "[email protected]"
}) {
id
name
email
}
}mutation keyword.input: CreateUserInput!.errors array.The foundations from today carry directly into Day 4. In the next session the focus shifts to Subscriptions and Real-Time Data — building directly on everything covered here.
Before moving on, verify you can answer these without looking:
Live Bootcamp
Learn this in person — 2 days, 5 cities
Thu–Fri sessions in Denver, Los Angeles, New York, Chicago, and Dallas. $1,490 per seat. June–October 2026.
Reserve Your Seat →