Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to start a GraphQL subscription named newMessages.
GraphQL
subscription [1] {
messageAdded {
id
content
}
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'query' or 'mutation' instead of a subscription name.
Omitting the subscription name.
✗ Incorrect
The subscription operation must be named correctly to start listening for new messages. Here, 'newMessages' is the correct subscription name.
2fill in blank
mediumComplete the code to subscribe to userStatusChanged with a variable $userId.
GraphQL
subscription onUserStatusChanged($userId: ID!) {
userStatusChanged(userId: [1]) {
id
status
}
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the variable name without the $ prefix.
Using a different variable name than declared.
✗ Incorrect
Variables in GraphQL are referenced with a $ prefix. Here, $userId is the correct variable to pass.
3fill in blank
hardFix the error in the subscription by correctly specifying the operation type.
GraphQL
[1] onNewNotification {
notificationAdded {
id
message
}
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'query' or 'mutation' instead of 'subscription'.
Omitting the operation type.
✗ Incorrect
The operation type for subscriptions must be 'subscription' to listen for real-time events.
4fill in blank
hardFill both blanks to subscribe to commentAdded with a variable $postId and request id and text fields.
GraphQL
subscription [1]($postId: ID!) { commentAdded(postId: [2]) { id text } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the variable name without $ inside the subscription.
Using the wrong subscription name.
✗ Incorrect
The subscription name is 'onCommentAdded' and the variable must be referenced with '$postId' inside the subscription.
5fill in blank
hardFill all three blanks to subscribe to orderStatusChanged with variable $orderId, requesting id, status, and updatedAt fields.
GraphQL
subscription [1]($orderId: ID!) { orderStatusChanged(orderId: [2]) { id status [3] } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting the $ prefix for variables.
Forgetting to include the 'updatedAt' field.
✗ Incorrect
The subscription name is 'onOrderStatusChanged', the variable is referenced as '$orderId', and the field 'updatedAt' is requested.