0
0
GraphQLquery~10 mins

Subscription syntax in GraphQL - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
AnewMessages
Bquery
Cmutation
DsubscriptionMessage
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'query' or 'mutation' instead of a subscription name.
Omitting the subscription name.
2fill in blank
medium

Complete 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'
AuserId
Bstatus
Cid
D$userId
Attempts:
3 left
💡 Hint
Common Mistakes
Using the variable name without the $ prefix.
Using a different variable name than declared.
3fill in blank
hard

Fix 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'
Aquery
Bmutation
Csubscription
Dnotify
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'query' or 'mutation' instead of 'subscription'.
Omitting the operation type.
4fill in blank
hard

Fill 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'
AonCommentAdded
B$postId
CpostId
DcommentAdded
Attempts:
3 left
💡 Hint
Common Mistakes
Using the variable name without $ inside the subscription.
Using the wrong subscription name.
5fill in blank
hard

Fill 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'
AonOrderStatusChanged
B$orderId
CupdatedAt
DorderStatusChanged
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting the $ prefix for variables.
Forgetting to include the 'updatedAt' field.