GraphQL Client Vocabulary
5 exercises — master GraphQL client vocabulary: operations and naming, fragments and co-location, variables, over-fetching vs under-fetching, and persisted queries.
0 / 5 completed
GraphQL client vocabulary quick reference
- Operation — a single GraphQL request: query, mutation, or subscription
- Named operation —
query GetUser; appears in logs, traces, and monitoring tools - Fragment — reusable selection set:
fragment UserCard on User { id name } - Variable — typed operation parameter:
$userId: ID!— always use instead of inline literals - Over-fetching — receiving more data than needed; under-fetching — needing extra round-trips
- Persisted query — pre-registered operation sent by hash instead of full text; improves security and performance
1 / 5
What is a GraphQL operation, and why is it important to give operations names in production applications?
# Anonymous (avoid in production)
query { user(id: "123") { name email } }
# Named (recommended)
query GetUserProfile { user(id: "123") { name email } }
An operation is the unit of execution in GraphQL — every client request is an operation.
The three operation types:
• query — read data (safe, cacheable)
• mutation — write data (side effects)
• subscription — receive real-time push events
Named vs anonymous operations:
• Operations appear by name in APM tools (Datadog, New Relic, Apollo Studio)
•
• Per-operation metrics: cost, latency, error rate — only possible with named operations
• Persisted queries (sending only the operation name, not the full query document) require named operations
• Client-side debugging: React DevTools, Apollo Client DevTools, Relay show operations by name
Convention: name queries with a noun phrase (
Key vocabulary:
• Operation — a single GraphQL request (query, mutation, or subscription)
• Operation name — the optional identifier after the operation keyword (
• Anonymous operation — an operation without a name; discouraged in production
The three operation types:
• query — read data (safe, cacheable)
• mutation — write data (side effects)
• subscription — receive real-time push events
Named vs anonymous operations:
# Anonymous — avoid in production
{ user(id: "123") { name } }
# Named — the standard in production codebases
query GetUserProfile($userId: ID!) {
user(id: $userId) { name email avatar }
}
mutation UpdateUserEmail($userId: ID!, $email: String!) {
updateUser(id: $userId, email: $email) { id email }
}
Why naming matters:• Operations appear by name in APM tools (Datadog, New Relic, Apollo Studio)
•
GetUserProfile in your logs immediately tells you which query is slow — anonymous tells you nothing• Per-operation metrics: cost, latency, error rate — only possible with named operations
• Persisted queries (sending only the operation name, not the full query document) require named operations
• Client-side debugging: React DevTools, Apollo Client DevTools, Relay show operations by name
Convention: name queries with a noun phrase (
GetUserProfile) and mutations with a verb phrase (UpdateUserEmail, DeletePost).Key vocabulary:
• Operation — a single GraphQL request (query, mutation, or subscription)
• Operation name — the optional identifier after the operation keyword (
query GetUserProfile)• Anonymous operation — an operation without a name; discouraged in production