0
0
GraphQLquery~20 mins

Subscription lifecycle in GraphQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Subscription Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
What is the output of this subscription query?

Consider a GraphQL subscription that listens for new messages in a chat room. When a new message is sent, the subscription returns the message content and the sender's name.

Given the following subscription query:

subscription NewMessage {
  messageAdded {
    content
    sender {
      name
    }
  }
}

If a new message with content "Hello!" is sent by user "Alice", what will the subscription return?

GraphQL
subscription NewMessage {
  messageAdded {
    content
    sender {
      name
    }
  }
}
A{"messageAdded": {"content": "Hello!", "sender": {"name": "Alice"}}}
B{"data": {"messageAdded": {"content": "Hello!", "sender": {"name": "Alice"}}}}
C{"data": {"newMessage": {"content": "Hello!", "sender": {"name": "Alice"}}}}
D{"data": {"messageAdded": {"content": "Hello!", "sender": "Alice"}}}
Attempts:
2 left
💡 Hint

Remember the subscription response wraps data inside a data field matching the subscription field name.

🧠 Conceptual
intermediate
1:30remaining
Which event triggers a GraphQL subscription update?

In a GraphQL subscription lifecycle, what kind of event causes the server to send updated data to subscribed clients?

AA mutation changes data on the server.
BA client sends a new query request.
CThe server restarts.
DA client disconnects from the subscription.
Attempts:
2 left
💡 Hint

Think about what changes data on the server that clients want to be notified about.

📝 Syntax
advanced
2:00remaining
Identify the syntax error in this subscription definition

Which option contains a syntax error in defining a GraphQL subscription?

subscription OnUserStatusChanged {
  userStatusChanged {
    id
    status
  }
}
A
subscription OnUserStatusChanged {
  userStatusChanged {
    id
    status
  }
}
B
subscription OnUserStatusChanged {
  userStatusChanged {
    id
    status
  }}
C
subscription OnUserStatusChanged {
  userStatusChanged {
    id
    status
  }
D
}  
sutats    
di    
{ degnahCsutatSresu  
{ degnahCsutatSresUnO noitpircsbus
Attempts:
2 left
💡 Hint

Check for matching braces and proper closing of the subscription block.

🔧 Debug
advanced
2:30remaining
Why does this subscription not receive updates?

A client subscribes to newOrder events, but never receives any updates even though new orders are created. Which option explains the most likely cause?

subscription NewOrder {
  newOrder {
    id
    total
  }
}
AThe client is not authorized to subscribe.
BThe client query is missing required variables.
CThe subscription query uses incorrect field names.
DThe server does not publish <code>newOrder</code> events after mutations.
Attempts:
2 left
💡 Hint

Check if the server triggers events to notify subscribers after data changes.

optimization
expert
3:00remaining
How to optimize subscription performance for many clients?

You have thousands of clients subscribed to a stockPriceUpdated subscription. What is the best way to optimize server performance when sending updates?

ABatch updates and send only relevant stock price changes to each client.
BSend every update to all clients regardless of their subscribed stocks.
CDisconnect clients frequently to reduce load.
DUse polling queries instead of subscriptions.
Attempts:
2 left
💡 Hint

Think about sending only necessary data to each client to reduce server work.