Skip to content

Commit

Permalink
Merge pull request #1021 from lens-protocol/T-23289/js-actions-create…
Browse files Browse the repository at this point in the history
…-all-post-queries
  • Loading branch information
juangm authored Dec 16, 2024
2 parents d36d021 + 2a379fb commit 81626b0
Show file tree
Hide file tree
Showing 4 changed files with 239 additions and 3 deletions.
117 changes: 117 additions & 0 deletions packages/client/src/actions/posts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,25 @@ import type {
import {
PostActionsQuery,
PostBookmarksQuery,
PostEditsQuery,
PostQuery,
PostReactionStatusQuery,
PostReactionsQuery,
PostReferencesQuery,
PostTagsQuery,
WhoActedOnPostQuery,
WhoReferencedPostQuery,
} from '@lens-protocol/graphql';
import type { ResultAsync } from '@lens-protocol/types';

import type { PostTagsRequest } from '@lens-protocol/graphql';
import type { PostReactionStatusRequest } from '@lens-protocol/graphql';
import type { PostReactionStatus } from '@lens-protocol/graphql';
import type { WhoReferencedPostRequest } from '@lens-protocol/graphql';
import type { Account } from '@lens-protocol/graphql';
import type { WhoActedOnPostQueryRequest } from '@lens-protocol/graphql';
import type { PostEditsRequest } from '@lens-protocol/graphql';
import type { PostEdit } from '@lens-protocol/graphql';
import type { AnyClient, SessionClient } from '../clients';
import type { UnauthenticatedError, UnexpectedError } from '../errors';

Expand Down Expand Up @@ -120,3 +133,107 @@ export function fetchPostReferences(
): ResultAsync<Paginated<AnyPost>, UnexpectedError | UnauthenticatedError> {
return client.query(PostReferencesQuery, { request });
}

/**
* Fetch post tags.
*
* ```ts
* const result = await fetchPostTags(anyClient, {
* forFeeds: [evmAddress('0xe2f2a5C287993345a840db3B0845fbc70f5935a5')],
* });
* ```
*
* @param client - Any Lens client.
* @param request - The query request.
* @returns The list of post tags.
*/
export function fetchPostTags(
client: AnyClient,
request: PostTagsRequest,
): ResultAsync<Paginated<string>, UnexpectedError> {
return client.query(PostTagsQuery, { request });
}

/**
* Fetch post reaction status.
*
* ```ts
* const result = await fetchPostReactionStatus(anyClient, {
* pairs: [{
* account: evmAddress('0xe2f2a5C287993345a840db3B0845fbc70f5935a5')],
* post: postId('42'),
* }],
* });
* ```
*
* @param client - Any Lens client.
* @param request - The query request.
* @returns The list of post reaction status.
*/
export function fetchPostReactionStatus(
client: AnyClient,
request: PostReactionStatusRequest,
): ResultAsync<PostReactionStatus[], UnexpectedError> {
return client.query(PostReactionStatusQuery, { request });
}

/**
* Fetch who referenced post.
*
* ```ts
* const result = await fetchWhoReferencedPost(anyClient, {
* referenceTypes: [PostReferenceType.CommentOn]
* post: postId('42'),
* });
* ```
*
* @param client - Any Lens client.
* @param request - The query request.
* @returns The list of accounts who referenced the post.
*/
export function fetchWhoReferencedPost(
client: AnyClient,
request: WhoReferencedPostRequest,
): ResultAsync<Paginated<Account>, UnexpectedError> {
return client.query(WhoReferencedPostQuery, { request });
}

/**
* Fetch who acted on post.
*
* ```ts
* const result = await fetchWhoActedOnPost(anyClient, {
* post: postId('42'),
* });
* ```
*
* @param client - Any Lens client.
* @param request - The query request.
* @returns The list of accounts who acted on the post.
*/
export function fetchWhoActedOnPost(
client: AnyClient,
request: WhoActedOnPostQueryRequest,
): ResultAsync<Paginated<Account>, UnexpectedError> {
return client.query(WhoActedOnPostQuery, { request });
}

/**
* Fetch post edits.
*
* ```ts
* const result = await fetchPostEdits(anyClient, {
* post: postId('42'),
* });
* ```
*
* @param client - Any Lens client.
* @param request - The query request.
* @returns The list of edits for the post.
*/
export function fetchPostEdits(
client: AnyClient,
request: PostEditsRequest,
): ResultAsync<Paginated<PostEdit>, UnexpectedError> {
return client.query(PostEditsQuery, { request });
}
24 changes: 21 additions & 3 deletions packages/graphql/src/enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,25 @@ export enum PostReactionType {
* Enum for the different content warnings.
*/
export enum ContentWarning {
nsfw = 'NSFW',
sensitive = 'SENSITIVE',
spoiler = 'SPOILER',
Nsfw = 'NSFW',
Sensitive = 'SENSITIVE',
Spoiler = 'SPOILER',
}

/**
* Enum for the different types of references a post can have.
*/
export enum PostReferenceType {
CommentOn = 'COMMENT_ON',
RepostOf = 'REPOST_OF',
QuoteOf = 'QUOTE_OF',
}

/**
* Enum for the different order by options for who referenced on a post.
*/
export enum WhoReferencedPostOrderBy {
MostRecent = 'MOST_RECENT',
Oldest = 'OLDEST',
AccountScore = 'ACCOUNT_SCORE',
}
5 changes: 5 additions & 0 deletions packages/graphql/src/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ import type {
PageSize,
PostActionType,
PostReactionType,
PostReferenceType,
WhoReferencedPostOrderBy,
} from './enums';
import type { introspection } from './graphql-env';

Expand All @@ -60,17 +62,20 @@ export const graphql = initGraphQLTada<{
LegacyRefreshToken: CompactJwt;
PostActionType: PostActionType;
PostReactionType: PostReactionType;
PostReferenceType: PostReferenceType;
PageSize: PageSize;
PostId: PostId;
RefreshToken: RefreshToken;
Signature: Signature;
String: string;
Tag: string;
TxHash: TxHash;
URI: URI;
URL: URL;
UsernameValue: UsernameValue;
UUID: UUID;
Void: Void;
WhoReferencedPostOrderBy: WhoReferencedPostOrderBy;
};
}>();

Expand Down
96 changes: 96 additions & 0 deletions packages/graphql/src/post.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import type { FragmentOf } from 'gql.tada';
import {
AccountFragment,
AccountPostReactionFragment,
ActionInfoFragment,
AnyPostFragment,
PaginatedResultInfoFragment,
PostMetadataFragment,
SelfFundedTransactionRequest,
SponsoredTransactionRequest,
TransactionWillFail,
Expand Down Expand Up @@ -261,3 +263,97 @@ export const ReportPostMutation = graphql(
}`,
);
export type ReportPostRequest = RequestOf<typeof ReportPostMutation>;

export const PostTagsQuery = graphql(
`query PostTags($request: PostTagsRequest!) {
value: postTags(request: $request) {
__typename
items
pageInfo {
...PaginatedResultInfo
}
}
}`,
[PaginatedResultInfoFragment],
);
export type PostTagsRequest = RequestOf<typeof PostTagsQuery>;

export const PostReactionStatusFragment = graphql(
`fragment PostReactionStatus on PostReactionStatus {
__typename
postId
account
result
}`,
);
export type PostReactionStatus = FragmentOf<typeof PostReactionStatusFragment>;

export const PostReactionStatusQuery = graphql(
`query PostReactionStatus($request: PostReactionStatusRequest!) {
value: postReactionStatus(request: $request) {
...PostReactionStatus
}
}`,
[PostReactionStatusFragment],
);
export type PostReactionStatusRequest = RequestOf<typeof PostReactionStatusQuery>;

export const WhoReferencedPostQuery = graphql(
`query WhoReferencedPost($request: WhoReferencedPostRequest!) {
value: whoReferencedPost(request: $request) {
__typename
items {
...Account
}
pageInfo {
...PaginatedResultInfo
}
}
}`,
[PaginatedResultInfoFragment, AccountFragment],
);
export type WhoReferencedPostRequest = RequestOf<typeof WhoReferencedPostQuery>;

export const WhoActedOnPostQuery = graphql(
`query WhoReferencedPost($request: WhoActedOnPostRequest!) {
value: whoActedOnPost(request: $request) {
__typename
items {
...Account
}
pageInfo {
...PaginatedResultInfo
}
}
}`,
[PaginatedResultInfoFragment, AccountFragment],
);
export type WhoActedOnPostQueryRequest = RequestOf<typeof WhoActedOnPostQuery>;

export const PostEditFragment = graphql(
`fragment PostEdit on PostEdit {
__typename
metadata{
...PostMetadata
}
timestamp
}`,
[PostMetadataFragment],
);
export type PostEdit = FragmentOf<typeof PostEditFragment>;

export const PostEditsQuery = graphql(
`query PostEdits($request: PostEditsRequest!) {
value: postEdits(request: $request) {
__typename
items {
...PostEdit
}
pageInfo {
...PaginatedResultInfo
}
}
}`,
[PostEditFragment, PaginatedResultInfoFragment],
);
export type PostEditsRequest = RequestOf<typeof PostEditsQuery>;

0 comments on commit 81626b0

Please sign in to comment.