-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
199 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters