this string has no description
quickslice-subscription-filtering
145 lines 3.7 kB view raw
1# Filtering Subscriptions by Publication Name in QuickSlice 2 3## Goal 4 5Query subscriptions for a user (e.g., `zeu.dev`) and filter by the resolved publication's name (e.g., publications containing "banana"). 6 7## Limitation 8 9**Direct filtering is not supported.** The `publicationResolved` field on `SiteStandardGraphSubscription` doesn't accept `where` arguments, so you cannot filter subscriptions based on attributes of the resolved publication in a single query. 10 11This query shape is **not possible**: 12 13```graphql 14# ❌ Does not work 15query { 16 siteStandardGraphSubscription( 17 where: { 18 actorHandle: { eq: "zeu.dev" }, 19 publicationResolved: { name: { contains: "banana" } } # Not supported 20 } 21 ) { 22 edges { 23 node { 24 publicationResolved { ... } 25 } 26 } 27 } 28} 29``` 30 31## Workaround: Reverse the Query Direction 32 33Instead of starting from subscriptions, start from publications and traverse to subscriptions: 34 35```graphql 36query GetSubscribedPublicationsByName($did: String!, $nameFilter: String!) { 37 siteStandardPublication(first: 50, where: { name: { contains: $nameFilter }}) { 38 edges { 39 node { 40 uri 41 name 42 description 43 siteStandardGraphSubscriptionViaPublication( 44 first: 1, 45 where: { did: { eq: $did }} 46 ) { 47 edges { 48 node { 49 uri 50 actorHandle 51 } 52 } 53 } 54 } 55 } 56 } 57} 58``` 59 60Variables: 61```json 62{ 63 "did": "did:plc:gotnvwkr56ibs33l4hwgfoet", 64 "nameFilter": "banana" 65} 66``` 67 68### Client-Side Filtering Required 69 70This query returns all publications matching the name filter. To get only those the user is subscribed to, filter results where `siteStandardGraphSubscriptionViaPublication.edges` is non-empty: 71 72```typescript 73const subscribedPublications = result.siteStandardPublication.edges 74 .filter(edge => edge.node.siteStandardGraphSubscriptionViaPublication.edges.length > 0) 75 .map(edge => edge.node); 76``` 77 78## Gotcha: Use `did` Instead of `actorHandle` on Nested Connections 79 80When filtering nested connections (like `siteStandardGraphSubscriptionViaPublication`), filtering by `actorHandle` silently fails and returns empty results. Use `did` instead: 81 82```graphql 83# ❌ Does not work - returns empty 84siteStandardGraphSubscriptionViaPublication( 85 where: { actorHandle: { eq: "zeu.dev" }} 86) 87 88# ✅ Works correctly 89siteStandardGraphSubscriptionViaPublication( 90 where: { did: { eq: "did:plc:gotnvwkr56ibs33l4hwgfoet" }} 91) 92``` 93 94This is likely because `actorHandle` is a resolved/computed field rather than an indexed database column. 95 96## Alternative: Client-Side Filtering 97 98If you need the original query shape (subscriptions → publications), fetch all subscriptions with resolved publications and filter client-side: 99 100```graphql 101query GetAllSubscriptionsForUser { 102 siteStandardGraphSubscription( 103 first: 100, 104 where: { actorHandle: { eq: "zeu.dev" }} 105 ) { 106 edges { 107 node { 108 uri 109 publicationResolved { 110 ... on SiteStandardPublication { 111 uri 112 name 113 description 114 } 115 } 116 } 117 } 118 } 119} 120``` 121 122Then filter in code: 123 124```typescript 125const filtered = result.siteStandardGraphSubscription.edges 126 .filter(edge => 127 edge.node.publicationResolved?.name?.includes("banana") 128 ); 129``` 130 131## Feature Request 132 133To support the original query pattern natively, QuickSlice would need to add ref field filtering support: 134 135```graphql 136# Hypothetical future syntax 137siteStandardGraphSubscription( 138 where: { 139 actorHandle: { eq: "zeu.dev" }, 140 publication: { 141 ref: { name: { contains: "banana" } } # Filter on resolved ref fields 142 } 143 } 144) 145```