Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement post deletion #980

Merged
merged 2 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions packages/client/src/actions/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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<DeletePostResult, UnauthenticatedError | UnexpectedError> {
return client.mutation(DeletePostMutation, { request });
}

/**
* React to a post.
*
Expand Down
42 changes: 42 additions & 0 deletions packages/graphql/src/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,3 +198,45 @@ export const UndoBookmarkPostMutation = graphql(
}`,
);
export type UndoBookmarkPostRequest = RequestOf<typeof UndoBookmarkPostMutation>;

const DeletePostResponse = graphql(
`fragment DeletePostResponse on DeletePostResponse {
__typename
hash
}`,
);
export type DeletePostResponse = FragmentOf<typeof DeletePostResponse>;

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<typeof DeletePostResult>;

export const DeletePostMutation = graphql(
`mutation DeletePost($request: DeletePostRequest!) {
value: deletePost(request: $request) {
...DeletePostResult
}
}`,
[DeletePostResult],
);
export type DeletePostRequest = RequestOf<typeof DeletePostMutation>;