Module subscription_filters

Source
Expand description

GraphQL subscription filter implementation for AWS AppSync

This module provides types and abstractions for building type-safe GraphQL subscription filters according to the AWS AppSync specification. The filters are used to control which events are delivered to subscribed clients based on the event payloads.

The module enforces AWS AppSync’s filter constraints at compile time, including:

  • Maximum depth of 5 levels for nested field paths
  • Maximum 256 character length for field paths
  • in and notIn operators accept up to 5 values in an array
  • containsAny operator accepts up to 20 values in an array

§Examples

Simple field equality filter:

let filter = FieldPath::new("user.name")?.eq("example");

Complex filter group with AND/OR logic:

// The FilterGroup combines Filter elements with OR logic
// This means the filter will match if ANY of the Filter conditions are true
let group = FilterGroup::from([
    // First filter - combines conditions with AND logic:
    // - user.role must equal "admin" AND
    // - user.age must be greater than 21
    Filter::from([
        FieldPath::new("user.role")?.eq("admin"),
        FieldPath::new("user.age")?.gt(21)
    ]),
    // Second filter - also uses AND logic between its conditions:
    // - user.role must equal "moderator" AND
    // - user.permissions must contain either "moderate" or "review"
    Filter::from([
        FieldPath::new("user.role")?.eq("moderator"),
        FieldPath::new("user.permissions")?.contains_any(["moderate", "review"])
    ])
    // Final logic:
    // (role="admin" AND age>21) OR (role="moderator" AND permissions∩["moderate","review"]≠∅)
]);

Array operators with size limits:

// IN operator (max 5 values)
let roles = FieldPath::new("user.role")?.in_values(["admin", "mod", "user"]);

// ContainsAny operator (max 20 values)
let perms = FieldPath::new("user.permissions")?
    .contains_any(["read", "write", "delete", "admin"]);

Structs§

FieldFilter
A single field filter that combines a field path with an operator and value in the AppSync subscription filter format.
FieldPath
Field path supporting up to 5 levels of nesting
Filter
A single filter limited to 5 field filters
FilterGroup
A filter group limited to 10 filters combined with OR logic
FixedVec
Fixed-size vector for operators with size limits

Traits§

IFSBValueMarker
Private marker trait for types that can be used in equality operations
IFSValueMarker
Private marker trait for types that can be used in filter values