Skip to content

Commit

Permalink
Merge pull request #1037 from lens-protocol/feat/fetchPosts
Browse files Browse the repository at this point in the history
feat: fetchPosts paginated action
  • Loading branch information
cesarenaldi authored Dec 18, 2024
2 parents ad7889b + 5da8eff commit 8c5296a
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
29 changes: 28 additions & 1 deletion packages/client/src/actions/posts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type {
PostReactionsRequest,
PostReferencesRequest,
PostRequest,
PostsRequest,
} from '@lens-protocol/graphql';
import {
PostActionsQuery,
Expand All @@ -19,6 +20,7 @@ import {
PostReactionsQuery,
PostReferencesQuery,
PostTagsQuery,
PostsQuery,
WhoActedOnPostQuery,
WhoReferencedPostQuery,
} from '@lens-protocol/graphql';
Expand All @@ -43,7 +45,7 @@ import type { UnauthenticatedError, UnexpectedError } from '../errors';
*
* ```ts
* const result = await fetchPost(anyClient, {
* post: postId('0x01')
* post: postId('42')
* });
* ```
*
Expand All @@ -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<Paginated<AnyPost>, UnexpectedError> {
return client.query(PostsQuery, { request });
}

/**
* Fetch available actions for POST.
*
Expand Down
15 changes: 15 additions & 0 deletions packages/graphql/src/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,21 @@ export const PostQuery = graphql(
);
export type PostRequest = RequestOf<typeof PostQuery>;

export const PostsQuery = graphql(
`query Posts($request: PostsRequest!) {
value: posts(request: $request) {
items {
...AnyPost
}
pageInfo {
...PaginatedResultInfo
}
}
}`,
[AnyPostFragment, PaginatedResultInfoFragment],
);
export type PostsRequest = RequestOf<typeof PostsQuery>;

export const PostActionsQuery = graphql(
`query PostActions($request: PostActionsRequest!) {
value: postActions(request: $request) {
Expand Down

0 comments on commit 8c5296a

Please sign in to comment.