Skip to content

Commit

Permalink
Add admins mutations
Browse files Browse the repository at this point in the history
  • Loading branch information
juangm committed Dec 10, 2024
1 parent 9dcd3b3 commit a0041b1
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 1 deletion.
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

0 comments on commit a0041b1

Please sign in to comment.