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

Add admins mutations #1007

Merged
merged 1 commit into from
Dec 10, 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
53 changes: 53 additions & 0 deletions packages/client/src/actions/admins.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import type {
AddAdminsRequest,
AddAdminsResult,
RemoveAdminsRequest,
RemoveAdminsResult,
} from '@lens-protocol/graphql';
import { AddAdminsMutation, RemoveAdminsMutation } from '@lens-protocol/graphql';
import type { ResultAsync } from '@lens-protocol/types';

import type { SessionClient } from '../clients';
import type { UnauthenticatedError, UnexpectedError } from '../errors';

/**
* Add Admins
*
* ```ts
* const result = await addAdmins(sessionClient{
* admins: [evmAddress('0xe2f2a5C287993345a840db3B0845fbc70f5935a5')],
* address: evmAddress('0xe2f2a5C287993345a840db3B0845fbc70f5935a5'),
* });
* ```
*
* @param client - The session client logged as a builder.
* @param request - The mutation request.
* @returns Tiered transaction result.
*/
export function addAdmins(
client: SessionClient,
request: AddAdminsRequest,
): ResultAsync<AddAdminsResult, UnexpectedError | UnauthenticatedError> {
return client.mutation(AddAdminsMutation, { request });
}

/**
* Remove admins
*
* ```ts
* const result = await removeAdmins(sessionClient{
* admins: [evmAddress('0xe2f2a5C287993345a840db3B0845fbc70f5935a5')],
* address: evmAddress('0xe2f2a5C287993345a840db3B0845fbc70f5935a5'),
* });
* ```
*
* @param client - The session client for the authenticated Account.
* @param request - The mutation request.
* @returns Tiered transaction result.
*/
export function removeAdmins(
client: SessionClient,
request: RemoveAdminsRequest,
): ResultAsync<RemoveAdminsResult, UnexpectedError | UnauthenticatedError> {
return client.mutation(RemoveAdminsMutation, { request });
}
3 changes: 2 additions & 1 deletion packages/client/src/actions/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
export * from './account';
export * from './admins';
export * from './app';
export * from './authentication';
export * from './follow';
export * from './post';
export * from './posts';
export * from './transactions';
export * from './timeline';
export * from './transactions';
59 changes: 59 additions & 0 deletions packages/graphql/src/admins.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import type { FragmentOf } from 'gql.tada';
import {
SelfFundedTransactionRequest,
SponsoredTransactionRequest,
TransactionWillFail,
} from './fragments';
import { type RequestOf, graphql } from './graphql';

const AddAdminsResult = graphql(
`fragment AddAdminsResult on AddAdminsResult {
...on SponsoredTransactionRequest {
...SponsoredTransactionRequest
}
...on SelfFundedTransactionRequest {
...SelfFundedTransactionRequest
}
...on TransactionWillFail {
...TransactionWillFail
}
}`,
[SponsoredTransactionRequest, SelfFundedTransactionRequest, TransactionWillFail],
);
export type AddAdminsResult = FragmentOf<typeof AddAdminsResult>;

export const AddAdminsMutation = graphql(
`mutation AddAdmins($request: AddAdminsRequest!) {
value: addAdmins(request: $request) {
...AddAdminsResult
}
}`,
[AddAdminsResult],
);
export type AddAdminsRequest = RequestOf<typeof AddAdminsMutation>;

const RemoveAdminsResult = graphql(
`fragment RemoveAdminsResult on RemoveAdminsResult {
...on SponsoredTransactionRequest {
...SponsoredTransactionRequest
}
...on SelfFundedTransactionRequest {
...SelfFundedTransactionRequest
}
...on TransactionWillFail {
...TransactionWillFail
}
}`,
[SponsoredTransactionRequest, SelfFundedTransactionRequest, TransactionWillFail],
);
export type RemoveAdminsResult = FragmentOf<typeof RemoveAdminsResult>;

export const RemoveAdminsMutation = graphql(
`mutation RemoveAdmins($request: RemoveAdminsRequest!) {
value: removeAdmins(request: $request) {
...RemoveAdminsResult
}
}`,
[RemoveAdminsResult],
);
export type RemoveAdminsRequest = RequestOf<typeof RemoveAdminsMutation>;
1 change: 1 addition & 0 deletions packages/graphql/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './accounts';
export * from './admins';
export * from './app';
export * from './authentication';
export * from './enums';
Expand Down
Loading