diff --git a/packages/client/src/actions/posts.ts b/packages/client/src/actions/posts.ts index 0537da52e..7f854fb27 100644 --- a/packages/client/src/actions/posts.ts +++ b/packages/client/src/actions/posts.ts @@ -9,6 +9,7 @@ import type { PostReactionsRequest, PostReferencesRequest, PostRequest, + PostsRequest, } from '@lens-protocol/graphql'; import { PostActionsQuery, @@ -19,6 +20,7 @@ import { PostReactionsQuery, PostReferencesQuery, PostTagsQuery, + PostsQuery, WhoActedOnPostQuery, WhoReferencedPostQuery, } from '@lens-protocol/graphql'; @@ -43,7 +45,7 @@ import type { UnauthenticatedError, UnexpectedError } from '../errors'; * * ```ts * const result = await fetchPost(anyClient, { - * post: postId('0x01') + * post: postId('42') * }); * ``` * @@ -58,6 +60,31 @@ export function fetchPost( return client.query(PostQuery, { request }); } +/** + * Fetch paginated Posts. + * + * Using a {@link SessionClient} will yield {@link Post#operations} + * and {@link Account#operations} specific to the authenticated Account. + * + * ```ts + * const result = await fetchPosts(anyClient, { + * filter: { + * authors: [evmAddress('0xe2f2a5C287993345a840db3B0845fbc70f5935a5')], + * } + * }); + * ``` + * + * @param client - Any Lens client. + * @param request - The query request. + * @returns The paginated list of Posts. + */ +export function fetchPosts( + client: AnyClient, + request: PostsRequest, +): ResultAsync, UnexpectedError> { + return client.query(PostsQuery, { request }); +} + /** * Fetch available actions for POST. * diff --git a/packages/graphql/src/post.ts b/packages/graphql/src/post.ts index 7953713fe..fced0f8a4 100644 --- a/packages/graphql/src/post.ts +++ b/packages/graphql/src/post.ts @@ -84,6 +84,21 @@ export const PostQuery = graphql( ); export type PostRequest = RequestOf; +export const PostsQuery = graphql( + `query Posts($request: PostsRequest!) { + value: posts(request: $request) { + items { + ...AnyPost + } + pageInfo { + ...PaginatedResultInfo + } + } + }`, + [AnyPostFragment, PaginatedResultInfoFragment], +); +export type PostsRequest = RequestOf; + export const PostActionsQuery = graphql( `query PostActions($request: PostActionsRequest!) { value: postActions(request: $request) {