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 group mutations #1006

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
71 changes: 71 additions & 0 deletions packages/client/src/actions/group.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import type {
CreateGroupRequest,
CreateGroupResult,
JoinGroupRequest,
JoinGroupResult,
LeaveGroupRequest,
LeaveGroupResult,
} from '@lens-protocol/graphql';
import { CreateGroupMutation, JoinGroupMutation, LeaveGroupMutation } from '@lens-protocol/graphql';
import type { ResultAsync } from '@lens-protocol/types';

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

/**
* Create a Group
*
* ```ts
* const result = await createGroup(sessionClient);
* ```
*
* @param client - The session client logged as a builder.
* @param request - The mutation request.
* @returns Tiered transaction result.
*/
export function createGroup(
client: SessionClient,
request: CreateGroupRequest,
): ResultAsync<CreateGroupResult, UnexpectedError | UnauthenticatedError> {
return client.mutation(CreateGroupMutation, { request });
}

/**
* Join a Group
*
* ```ts
* const result = await joinGroup(sessionClient, {
* group: evmAddress('0xe2f2a5C287993345a840db3B0845fbc70f5935a5'),
* });
* ```
*
* @param client - The session client for the authenticated Account.
* @param request - The mutation request.
* @returns Tiered transaction result.
*/
export function joinGroup(
client: SessionClient,
request: JoinGroupRequest,
): ResultAsync<JoinGroupResult, UnexpectedError | UnauthenticatedError> {
return client.mutation(JoinGroupMutation, { request });
}

/**
* Leave a Group
*
* ```ts
* const result = await leaveGroup(sessionClient, {
* group: evmAddress('0xe2f2a5C287993345a840db3B0845fbc70f5935a5'),
* });
* ```
*
* @param client - The session client for the authenticated Account.
* @param request - The mutation request.
* @returns Tiered transaction result.
*/
export function leaveGroup(
client: SessionClient,
request: LeaveGroupRequest,
): ResultAsync<LeaveGroupResult, UnexpectedError | UnauthenticatedError> {
return client.mutation(LeaveGroupMutation, { request });
}
3 changes: 2 additions & 1 deletion packages/client/src/actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ export * from './account';
export * from './app';
export * from './authentication';
export * from './follow';
export * from './group';
export * from './post';
export * from './posts';
export * from './transactions';
export * from './timeline';
export * from './transactions';
125 changes: 125 additions & 0 deletions packages/graphql/src/group.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
import type { FragmentOf } from 'gql.tada';
import {
SelfFundedTransactionRequest,
SponsoredTransactionRequest,
TransactionWillFail,
} from './fragments';
import { type RequestOf, graphql } from './graphql';

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

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

export const CreateGroupMutation = graphql(
`mutation CreateGroup($request: CreateGroupRequest!) {
value: createGroup(request: $request) {
...CreateGroupResult
}
}`,
[CreateGroupResult],
);
export type CreateGroupRequest = RequestOf<typeof CreateGroupMutation>;

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

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

export const JoinGroupMutation = graphql(
`mutation JoinGroup($request: JoinGroupRequest!) {
value: joinGroup(request: $request) {
...JoinGroupResult
}
}`,
[JoinGroupResult],
);
export type JoinGroupRequest = RequestOf<typeof JoinGroupMutation>;

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

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

export const LeaveGroupMutation = graphql(
`mutation LeaveGroup($request: LeaveGroupRequest!) {
value: leaveGroup(request: $request) {
...LeaveGroupResult
}
}`,
[LeaveGroupResult],
);
export type LeaveGroupRequest = RequestOf<typeof LeaveGroupMutation>;
1 change: 1 addition & 0 deletions packages/graphql/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export * from './enums';
export * from './follow';
export * from './fragments';
export * from './graphql';
export * from './group';
export * from './health';
export * from './notifications';
export * from './post';
Expand Down
Loading