They are the three operation types, each mapped to a root type in the schema:
They are the three operation types, each mapped to a root type in the schema:
query GetPost { # read
post(id: "1") { title }
}
mutation AddComment { # write; returns the created object so the client updates its cache
addComment(postId: "1", text: "Nice!") {
id
text
}
}
subscription OnComment { # live: fires every time a comment is added
commentAdded(postId: "1") {
id
text
}
}
Mutations take arguments (often an input object) and should return the affected data so the client can refresh without a second request. The sequential rule matters: two mutations in one document — deposit then withdraw — always run in that order, whereas two query fields might resolve concurrently.
Interviewers check that you know queries are parallel and side-effect-free while mutations are sequential, and that a subscription needs a stateful transport (WebSocket/SSE). Returning updated data from a mutation is the practical detail that separates people who have shipped GraphQL from those who have only read about it.
A library of IT interview questions with detailed answers — from Junior to Senior.
Donate