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 all APP queries #1030

Merged
merged 4 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
120 changes: 120 additions & 0 deletions packages/client/src/actions/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,19 @@ import type {
AddAppSignersRequest,
AddAppSignersResult,
App,
AppFeed,
AppFeedsRequest,
AppGroupsRequest,
AppRequest,
AppSigner,
AppSignersRequest,
AppUser,
AppUsersRequest,
AppsRequest,
CreateAppRequest,
CreateAppResult,
Group,
Paginated,
RemoveAppFeedsRequest,
RemoveAppFeedsResult,
RemoveAppGroupsRequest,
Expand All @@ -34,7 +44,12 @@ import {
AddAppFeedsMutation,
AddAppGroupsMutation,
AddAppSignersMutation,
AppFeedsQuery,
AppGroupsQuery,
AppQuery,
AppSignersQuery,
AppUsersQuery,
AppsQuery,
CreateAppMutation,
RemoveAppFeedsMutation,
RemoveAppGroupsMutation,
Expand All @@ -49,6 +64,7 @@ import {
} from '@lens-protocol/graphql';
import type { ResultAsync } from '@lens-protocol/types';

import type {} from '@lens-protocol/graphql';
import type { AnyClient, SessionClient } from '../clients';
import type { UnauthenticatedError, UnexpectedError } from '../errors';

Expand All @@ -74,6 +90,110 @@ export function fetchApp(
return client.query(AppQuery, { request });
}

/**
* Fetch Apps.
*
* ```ts
* const result = await fetchApps(anyClient, {
* filter: {
* managedBy: {
* address: evmAddress('0xe2f2a5C287993345a840db3B0845fbc70f5935a5')
* }
* },
* });
* ```
*
* @param client - Any Lens client.
* @param request - The query request.
* @returns The list of Apps or empty if it does not exist.
*/
export function fetchApps(
client: AnyClient,
request: AppsRequest,
): ResultAsync<Paginated<App> | null, UnexpectedError> {
return client.query(AppsQuery, { request });
}

/**
* Fetch Groups linked to an App.
*
* ```ts
* const result = await fetchAppGroups(anyClient, {
* app: evmAddress('0xe2f2a5C287993345a840db3B0845fbc70f5935a5')
* });
* ```
*
* @param client - Any Lens client.
* @param request - The query request.
* @returns The list of groups for an App or empty if it does not exist.
*/
export function fetchAppGroups(
client: AnyClient,
request: AppGroupsRequest,
): ResultAsync<Paginated<Group> | null, UnexpectedError> {
return client.query(AppGroupsQuery, { request });
}

/**
* Fetch Feeds linked to an App.
*
* ```ts
* const result = await fetchAppFeeds(anyClient, {
* app: evmAddress('0xe2f2a5C287993345a840db3B0845fbc70f5935a5')
* });
* ```
*
* @param client - Any Lens client.
* @param request - The query request.
* @returns The list of feeds for an App or empty if it does not exist.
*/
export function fetchAppFeeds(
client: AnyClient,
request: AppFeedsRequest,
): ResultAsync<Paginated<AppFeed> | null, UnexpectedError> {
return client.query(AppFeedsQuery, { request });
}

/**
* Fetch Signers linked to an App.
*
* ```ts
* const result = await fetchAppSigners(anyClient, {
* app: evmAddress('0xe2f2a5C287993345a840db3B0845fbc70f5935a5')
* });
* ```
*
* @param client - Any Lens client.
* @param request - The query request.
* @returns The list of signers for an App or empty if it does not exist.
*/
export function fetchAppSigners(
client: AnyClient,
request: AppSignersRequest,
): ResultAsync<Paginated<AppSigner> | null, UnexpectedError> {
return client.query(AppSignersQuery, { request });
}

/**
* Fetch users using an App.
*
* ```ts
* const result = await fetchAppUsers(anyClient, {
* app: evmAddress('0xe2f2a5C287993345a840db3B0845fbc70f5935a5')
* });
* ```
*
* @param client - Any Lens client.
* @param request - The query request.
* @returns The list of users for an App or empty if it does not exist.
*/
export function fetchAppUsers(
client: AnyClient,
request: AppUsersRequest,
): ResultAsync<Paginated<AppUser> | null, UnexpectedError> {
return client.query(AppUsersQuery, { request });
}

/**
* Create an App
*
Expand Down
122 changes: 122 additions & 0 deletions packages/graphql/src/app.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import type { FragmentOf } from 'gql.tada';
import {
AccountFragment,
AppFragment,
GroupFragment,
PaginatedResultInfoFragment,
SelfFundedTransactionRequest,
SponsoredTransactionRequest,
TransactionWillFail,
Expand All @@ -17,6 +20,125 @@ export const AppQuery = graphql(
);
export type AppRequest = RequestOf<typeof AppQuery>;

export const AppsQuery = graphql(
`query Apps($request: AppsRequest!) {
value: apps(request: $request) {
__typename
items {
...App
}
pageInfo {
...PaginatedResultInfo
}
}
}`,
[AppFragment, PaginatedResultInfoFragment],
);
export type AppsRequest = RequestOf<typeof AppsQuery>;

export const AppGroupsQuery = graphql(
`query AppGroups($request: AppGroupsRequest!) {
value: appGroups(request: $request) {
__typename
items {
...Group
}
pageInfo {
...PaginatedResultInfo
}
}
}`,
[GroupFragment, PaginatedResultInfoFragment],
);
export type AppGroupsRequest = RequestOf<typeof AppGroupsQuery>;

export const AppSignerFragment = graphql(
`fragment AppSigner on AppSigner {
__typename
signer
timestamp
}`,
);
export type AppSigner = FragmentOf<typeof AppSignerFragment>;

export const AppSignersQuery = graphql(
`query AppSigners($request: AppSignersRequest!) {
value: appSigners(request: $request) {
__typename
items {
...AppSigner
}
pageInfo {
...PaginatedResultInfo
}
}
}`,
[AppSignerFragment, PaginatedResultInfoFragment],
);
export type AppSignersRequest = RequestOf<typeof AppSignersQuery>;

export const AppFeedFragment = graphql(
`fragment AppFeed on AppFeed {
__typename
feed
timestamp
}`,
);
export type AppFeed = FragmentOf<typeof AppFeedFragment>;

export const AppFeedsQuery = graphql(
`query AppFeeds($request: AppFeedsRequest!) {
value: appFeeds(request: $request) {
__typename
items {
...AppFeed
}
pageInfo {
...PaginatedResultInfo
}
}
}`,
[AppFeedFragment, PaginatedResultInfoFragment],
);
export type AppFeedsRequest = RequestOf<typeof AppFeedsQuery>;

export const AppUserFragment = graphql(
`fragment AppUser on AppUser {
__typename
account {
...Account
}
lastActiveOn
firstLoginOn
}`,
[AccountFragment],
);
export type AppUser = FragmentOf<typeof AppUserFragment>;

export const AppUsersQuery = graphql(
`query AppUsers($request: AppUsersRequest!) {
value: appUsers(request: $request) {
__typename
items {
...AppUser
}
pageInfo {
...PaginatedResultInfo
}
}
}`,
[AppUserFragment, PaginatedResultInfoFragment],
);
export type AppUsersRequest = RequestOf<typeof AppUsersQuery>;

export const AppServerApiKeyQuery = graphql(
`query AppServerApiKey($request: AppServerApiKeyRequest!) {
value: appServerApiKey(request: $request)
}`,
[AppFragment],
);
export type AppServerApiKeyRequest = RequestOf<typeof AppServerApiKeyQuery>;

const CreateAppResponse = graphql(
`fragment CreateAppResponse on CreateAppResponse {
__typename
Expand Down
Loading