Given a GraphQL subscription that listens for new messages, which option correctly filters messages to only those sent by user with ID 42?
subscription OnNewMessage($userId: ID!) {
newMessage(filter: { senderId: $userId }) {
id
content
senderId
}
}Check the filter field name matches the message sender's ID field.
Option C correctly uses a variable $userId and filters on senderId, which matches the message sender's ID field. Option C hardcodes the ID and does not use the variable. Option C filters on the wrong field 'id' instead of 'senderId'. Option C uses 'sender' which is not the correct field name.
What happens if a subscription filter does not match any events?
Think about how subscriptions work over time.
Subscriptions stay open waiting for events. If no event matches the filter, no data is sent but the connection remains active.
Which option contains a syntax error in the subscription filter?
subscription OnOrderUpdate($status: String!) {
orderUpdated(filter: { status: $status }) {
id
status
}
}Look carefully at the colon usage in the filter object.
Option D is missing the colon between 'status' and '$status', causing a syntax error. The others are correct.
You want to subscribe to new comments that are either from user ID 10 or have the tag 'urgent'. Which filter is the most efficient and correct?
Think about how to combine conditions to match either one or the other.
Option A uses the OR operator to match comments from user 10 or with tag 'urgent'. Option A and C require both conditions to be true, which is not the requirement. Option A is invalid syntax.
A subscription is set up to receive updates for products with price greater than 100. The filter is written as filter: { price_gt: 100 }. However, no events are received even when products with price 150 are updated. What is the most likely cause?
Check the filter operators supported by the GraphQL server.
Many GraphQL servers support specific filter operators like 'price_gt'. If the server does not support 'price_gt', the filter silently fails and no events are sent. The other options are incorrect because 'price > 100' is not valid GraphQL filter syntax, variable declaration is unrelated, and 'priceGreaterThan' is not a standard operator.