From 529be9766ad0035c21bfc4977ee05ead91b477e3 Mon Sep 17 00:00:00 2001 From: Juan Garcia Date: Thu, 28 Nov 2024 16:42:06 +0100 Subject: [PATCH 1/2] Implement post deletion --- packages/client/src/actions/post.ts | 27 ++++++++++++++++++++++++-- packages/graphql/src/post.ts | 30 +++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 2 deletions(-) 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..13e893cc8 100644 --- a/packages/graphql/src/post.ts +++ b/packages/graphql/src/post.ts @@ -198,3 +198,33 @@ export const UndoBookmarkPostMutation = graphql( }`, ); export type UndoBookmarkPostRequest = RequestOf; + +const DeletePostResult = graphql( + `fragment DeletePostResult on DeletePostResult { + ... on DeletePostResponse { + __typename + hash + } + ... on SponsoredTransactionRequest { + ...SponsoredTransactionRequest + } + ... on SelfFundedTransactionRequest { + ...SelfFundedTransactionRequest + } + ... on TransactionWillFail { + ...TransactionWillFail + } + }`, + [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; From cda98805e20f4aa38e117fccf92b165ba3cb7786 Mon Sep 17 00:00:00 2001 From: Juan Garcia Date: Fri, 29 Nov 2024 10:01:28 +0100 Subject: [PATCH 2/2] Add deletePostResponse --- packages/graphql/src/post.ts | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/packages/graphql/src/post.ts b/packages/graphql/src/post.ts index 13e893cc8..36d2ebd0f 100644 --- a/packages/graphql/src/post.ts +++ b/packages/graphql/src/post.ts @@ -199,11 +199,18 @@ 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 { - __typename - hash + ...DeletePostResponse } ... on SponsoredTransactionRequest { ...SponsoredTransactionRequest @@ -215,7 +222,12 @@ const DeletePostResult = graphql( ...TransactionWillFail } }`, - [TransactionWillFail, SelfFundedTransactionRequest, SponsoredTransactionRequest], + [ + DeletePostResponse, + TransactionWillFail, + SelfFundedTransactionRequest, + SponsoredTransactionRequest, + ], ); export type DeletePostResult = FragmentOf;