Consider a GraphQL subscription over WebSocket that listens for new messages in a chat room. The subscription query is:
subscription { newMessage { id content sender } }When a new message with id: 101, content: "Hello!", and sender: "Alice" arrives, what is the expected JSON output sent over the WebSocket?
GraphQL responses wrap the result inside a data field matching the subscription field name.
The correct output wraps the subscription field newMessage inside the data key. The id is a number, not a string, matching the schema.
Which of the following WebSocket messages is not a valid GraphQL subscription start message according to the Apollo protocol?
The id field must be a string, not a number.
Option C uses a numeric id which violates the Apollo WebSocket protocol requiring id to be a string.
You want to reduce the size of WebSocket messages for a GraphQL subscription that sends frequent updates. Which approach will most effectively reduce message size without losing data?
Think about sending less data per message rather than just compressing or batching.
Sending only changed fields reduces the payload size directly. Shorter field names require schema changes and may break clients. Compression and batching help but do not reduce individual message size as effectively.
A client tries to start a GraphQL subscription over WebSocket but immediately receives a Connection error and the subscription does not start. The server logs show no errors. Which is the most likely cause?
Check the required handshake messages in the WebSocket protocol.
The Apollo WebSocket protocol requires the client to send a connection_init message before starting subscriptions. Missing this causes connection errors without server logs.
Why is WebSocket transport preferred over HTTP polling for real-time GraphQL subscriptions?
Consider connection persistence and efficiency for real-time data.
WebSocket keeps a single open connection, so updates can be pushed instantly without repeated HTTP requests, reducing latency and overhead. Other options are incorrect or unrelated.