diff --git a/packages/client/src/actions/post.ts b/packages/client/src/actions/post.ts index 3044d7efb..84fcaab30 100644 --- a/packages/client/src/actions/post.ts +++ b/packages/client/src/actions/post.ts @@ -4,23 +4,26 @@ import type { BookmarkPostRequest, CreatePostRequest, CreateRepostRequest, + DeletePostRequest, + DeletePostResult, EditPostRequest, + PostResult, UndoBookmarkPostRequest, UndoReactionRequest, UndoReactionResult, } from '@lens-protocol/graphql'; - import { AddReactionMutation, BookmarkPostMutation, + DeletePostMutation, EditPostMutation, PostMutation, - type PostResult, RepostMutation, UndoBookmarkPostMutation, UndoReactionMutation, } from '@lens-protocol/graphql'; import type { ResultAsync } from '@lens-protocol/types'; + import type { SessionClient } from '../clients'; import type { UnauthenticatedError, UnexpectedError } from '../errors'; @@ -85,6 +88,26 @@ export function editPost( return client.mutation(EditPostMutation, { request }); } +/** + * Delete a Post. + * + * ```ts + * const result = await deletePost(sessionClient, { + * post: post.id, + * }); + * ``` + * + * @param client - The session client. + * @param request - The mutation request. + * @returns Tiered transaction result. + */ +export function deletePost( + client: SessionClient, + request: DeletePostRequest, +): ResultAsync { + return client.mutation(DeletePostMutation, { request }); +} + /** * React to a post. * diff --git a/packages/graphql/src/post.ts b/packages/graphql/src/post.ts index 07e212bcb..36d2ebd0f 100644 --- a/packages/graphql/src/post.ts +++ b/packages/graphql/src/post.ts @@ -198,3 +198,45 @@ export const UndoBookmarkPostMutation = graphql( }`, ); export type UndoBookmarkPostRequest = RequestOf; + +const DeletePostResponse = graphql( + `fragment DeletePostResponse on DeletePostResponse { + __typename + hash + }`, +); +export type DeletePostResponse = FragmentOf; + +const DeletePostResult = graphql( + `fragment DeletePostResult on DeletePostResult { + ... on DeletePostResponse { + ...DeletePostResponse + } + ... on SponsoredTransactionRequest { + ...SponsoredTransactionRequest + } + ... on SelfFundedTransactionRequest { + ...SelfFundedTransactionRequest + } + ... on TransactionWillFail { + ...TransactionWillFail + } + }`, + [ + DeletePostResponse, + TransactionWillFail, + SelfFundedTransactionRequest, + SponsoredTransactionRequest, + ], +); +export type DeletePostResult = FragmentOf; + +export const DeletePostMutation = graphql( + `mutation DeletePost($request: DeletePostRequest!) { + value: deletePost(request: $request) { + ...DeletePostResult + } + }`, + [DeletePostResult], +); +export type DeletePostRequest = RequestOf;