0
0
GraphQLquery~20 mins

Subscription filtering in GraphQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Subscription Filtering Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
Filter subscription events by user ID

Given a GraphQL subscription that listens for new messages, which option correctly filters messages to only those sent by user with ID 42?

GraphQL
subscription OnNewMessage($userId: ID!) {
  newMessage(filter: { senderId: $userId }) {
    id
    content
    senderId
  }
}
A
subscription OnNewMessage {
  newMessage(filter: { senderId: 42 }) {
    id
    content
    senderId
  }
}
B
subscription OnNewMessage($userId: ID!) {
  newMessage(filter: { id: $userId }) {
    id
    content
    senderId
  }
}
C
subscription OnNewMessage($userId: ID!) {
  newMessage(filter: { senderId: $userId }) {
    id
    content
    senderId
  }
}
D
subscription OnNewMessage($userId: ID!) {
  newMessage(filter: { sender: $userId }) {
    id
    content
    senderId
  }
}
Attempts:
2 left
💡 Hint

Check the filter field name matches the message sender's ID field.

🧠 Conceptual
intermediate
1:30remaining
Understanding subscription filter behavior

What happens if a subscription filter does not match any events?

AThe subscription immediately closes with an error.
BThe subscription stays open but no events are sent until a matching event occurs.
CThe subscription sends all events regardless of the filter.
DThe subscription sends a single empty event and then closes.
Attempts:
2 left
💡 Hint

Think about how subscriptions work over time.

📝 Syntax
advanced
1:30remaining
Identify the syntax error in subscription filter

Which option contains a syntax error in the subscription filter?

GraphQL
subscription OnOrderUpdate($status: String!) {
  orderUpdated(filter: { status: $status }) {
    id
    status
  }
}
A
ubscription OnOrderUpdate($status: String!) {
  orderUpdated(filter: { status: $status }) {
    id
    status
  }
}
B
subscription OnOrderUpdate($status: String!) {
  orderUpdated(filter: { status: $status }) {
    id
    status
  }
}
C
}
}  
sutats    
di    
{ )} sutats$ :sutats { :retlif(detadpUredro  
{ )!gnirtS :sutats$(etadpUredrOnO noitpircsbus
D
subscription OnOrderUpdate($status: String!) {
  orderUpdated(filter: { status $status }) {
    id
    status
  }
}
Attempts:
2 left
💡 Hint

Look carefully at the colon usage in the filter object.

optimization
advanced
2:30remaining
Optimize subscription filter for multiple conditions

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?

Afilter: { OR: [{ authorId: 10 }, { tags_contains: "urgent" }] }
Bfilter: { authorId: 10, tags_contains: "urgent" }
Cfilter: { AND: [{ authorId: 10 }, { tags_contains: "urgent" }] }
Dfilter: { authorId: 10 OR tags_contains: "urgent" }
Attempts:
2 left
💡 Hint

Think about how to combine conditions to match either one or the other.

🔧 Debug
expert
3:00remaining
Debug why subscription filter does not receive expected events

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?

AThe subscription server does not support the 'price_gt' filter operator.
BThe filter should use 'price > 100' syntax instead of 'price_gt'.
CThe subscription query is missing the variable declaration for price.
DThe filter field name 'price_gt' is incorrect; it should be 'priceGreaterThan'.
Attempts:
2 left
💡 Hint

Check the filter operators supported by the GraphQL server.