Consider this GraphQL subscription that listens for new messages:
subscription {
newMessage {
id
content
sender
}
}If a new message with id: 101, content: "Hello!", and sender: "Alice" is sent, what will the subscription receive?
subscription {
newMessage {
id
content
sender
}
}Check the exact field names in the subscription response.
The subscription listens to newMessage field, so the response wraps the message data inside newMessage. The id is a number, not a string.
Identify the valid GraphQL subscription syntax from the options below:
Subscriptions can have operation names and must have a single root field.
Option B uses a valid operation name NewMessages and a single root field newMessage. Option B incorrectly uses arguments in subscription root field which is allowed but depends on schema; Option B uses lowercase operation name which is invalid; Option B has multiple root fields which is invalid.
You want to subscribe to user status updates but only need the userId and status fields. Which subscription query is optimized?
Request only the fields you need to reduce data transfer.
Option C requests only userId and status, which is optimal. Option C requests extra unnecessary fields. Option C uses invalid syntax. Option C misses the status field.
Given this subscription:
subscription {
newMessage {
id
content
sender
}
userStatus {
userId
status
}
}Why does it cause an error?
Check the number of root fields in the subscription.
GraphQL subscriptions require exactly one root field. Having both newMessage and userStatus as root fields causes a syntax error.
Choose the best explanation of how subscriptions differ from queries in GraphQL.
Think about how data is delivered over time.
Subscriptions keep a live connection to get real-time updates. Queries run once and return data immediately.