[SDK] Migrate profile and graph read queries to the appview client (#11356)

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Samuel Newman
2026-08-13 22:26:15 +03:00
committed by GitHub
parent 855457c9fa
commit 0912119c77
14 changed files with 180 additions and 148 deletions
+18 -11
View File
@@ -1,4 +1,5 @@
import {type AppBskyActorDefs, type AppBskyGraphGetFollows} from '@atproto/api'
import {type AppBskyActorDefs} from '@atproto/api'
import {type DidString} from '@atproto/syntax'
import {
type InfiniteData,
type QueryClient,
@@ -7,8 +8,9 @@ import {
} from '@tanstack/react-query'
import {STALE} from '#/state/queries'
import {useAgent} from '#/state/session'
import {useAppviewClient} from '#/state/session'
import {useAnalytics} from '#/analytics'
import {app} from '#/lexicons'
const DEFAULT_SORT = 'latest'
const PAGE_SIZE = 30
@@ -34,27 +36,32 @@ export function useProfileFollowsQuery(
) {
const ax = useAnalytics()
const isSortEnabled = ax.features.enabled(ax.features.FollowSortEnable)
const agent = useAgent()
const client = useAppviewClient()
const sortParam = isSortEnabled ? sort || DEFAULT_SORT : undefined
return useInfiniteQuery<
AppBskyGraphGetFollows.OutputSchema,
app.bsky.graph.getFollows.$OutputBody,
Error,
InfiniteData<AppBskyGraphGetFollows.OutputSchema>,
InfiniteData<app.bsky.graph.getFollows.$OutputBody>,
QueryKey,
RQPageParam
>({
staleTime: STALE.MINUTES.ONE,
queryKey: RQKEY(did || '', sortParam),
async queryFn({pageParam}: {pageParam: RQPageParam}) {
const res = await agent.app.bsky.graph.getFollows({
actor: did || '',
/*
* The vendored lexicon does not declare `sort`, so it is spread in only
* when set and the whole params object is asserted. lex forwards
* undeclared params verbatim but rejects an undeclared key whose value
* is `undefined`, hence the conditional spread.
*/
return await client.call(app.bsky.graph.getFollows, {
actor: (did || '') as DidString,
limit: limit || PAGE_SIZE,
cursor: pageParam,
sort: sortParam,
})
return res.data
...(sortParam ? {sort: sortParam} : {}),
} as app.bsky.graph.getFollows.$Params)
},
initialPageParam: undefined,
getNextPageParam: lastPage => lastPage.cursor,
@@ -67,7 +74,7 @@ export function* findAllProfilesInQueryData(
did: string,
): Generator<AppBskyActorDefs.ProfileView, void> {
const queryDatas = queryClient.getQueriesData<
InfiniteData<AppBskyGraphGetFollows.OutputSchema>
InfiniteData<app.bsky.graph.getFollows.$OutputBody>
>({
queryKey: [RQKEY_ROOT],
})