GraphQL Vocabulary
5 exercises — Query/Mutation/Subscription, the N+1 problem and DataLoader, non-null ! types, fragments vs inline fragments, and schema-first vs code-first design.
0 / 5 completed
GraphQL vocabulary quick reference
- Query = read · Mutation = write · Subscription = real-time push via WebSocket
- N+1 problem = 1 query + N resolver queries · DataLoader = batches + deduplicates per event loop tick
- String! = non-null · String = nullable · [String!]! = non-null list of non-nulls
- Fragment = named reusable field selection (
...UserCard) · Inline fragment =... on ConcreteTypefor unions/interfaces - Schema-first = write SDL then resolvers · Code-first = write code, SDL auto-generated (Pothos, TypeGraphQL)
1 / 5
A tech lead says: "This endpoint should be a Query, not a Mutation. And if you need live updates, that's a Subscription." When do you use each GraphQL operation type?
GraphQL operation types vocabulary:
Query
Fetches data. No server-side effects. Can be executed in parallel by the server.
• Transport: typically HTTP GET or POST
• Analogous to: REST GET
• Example:
Mutation
Changes server state. Executed serially (mutations in a document are run one at a time).
• Transport: HTTP POST
• Analogous to: REST POST/PUT/PATCH/DELETE
• Example:
• Mutations should return the modified object so clients can update their cache
Subscription
Establishes a persistent connection for real-time push updates.
• Transport: WebSocket (most common), Server-Sent Events, or long polling
• Example:
• Use cases: chat messages, live scores, stock prices, CI/CD pipeline status
• Subscriptions require additional server infrastructure (subscriptions manager, pub/sub broker like Redis)
Vocabulary:
• operation — a named piece of GraphQL work (query / mutation / subscription)
• document — a GraphQL request body containing one or more operations
• operation name — optional name for a query, useful in logging and Apollo DevTools
• variable — parameterized input to an operation, sent separately from the query string
• persisted query — pre-stored query on the server identified by hash, reducing request payload size
Query
Fetches data. No server-side effects. Can be executed in parallel by the server.
• Transport: typically HTTP GET or POST
• Analogous to: REST GET
• Example:
query { user(id: "1") { name, email } }Mutation
Changes server state. Executed serially (mutations in a document are run one at a time).
• Transport: HTTP POST
• Analogous to: REST POST/PUT/PATCH/DELETE
• Example:
mutation { createPost(input: {title: "Hello"}) { id, title } }• Mutations should return the modified object so clients can update their cache
Subscription
Establishes a persistent connection for real-time push updates.
• Transport: WebSocket (most common), Server-Sent Events, or long polling
• Example:
subscription { messageAdded(channelId: "42") { text, author { name } } }• Use cases: chat messages, live scores, stock prices, CI/CD pipeline status
• Subscriptions require additional server infrastructure (subscriptions manager, pub/sub broker like Redis)
Vocabulary:
• operation — a named piece of GraphQL work (query / mutation / subscription)
• document — a GraphQL request body containing one or more operations
• operation name — optional name for a query, useful in logging and Apollo DevTools
• variable — parameterized input to an operation, sent separately from the query string
• persisted query — pre-stored query on the server identified by hash, reducing request payload size