Skip to content

Commit

Permalink
Merge pull request #1028 from lens-protocol/T-23292/js-action-impleme…
Browse files Browse the repository at this point in the history
…nt-feed-graph-namespace-queries
  • Loading branch information
juangm authored Dec 16, 2024
2 parents 5790bd7 + 4a68f6f commit c650381
Show file tree
Hide file tree
Showing 13 changed files with 386 additions and 48 deletions.
27 changes: 25 additions & 2 deletions packages/client/src/actions/admins.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import type {
AddAdminsRequest,
AddAdminsResult,
Admin,
AdminsForRequest,
RemoveAdminsRequest,
RemoveAdminsResult,
} from '@lens-protocol/graphql';
import { AddAdminsMutation, RemoveAdminsMutation } from '@lens-protocol/graphql';
import { AddAdminsMutation, AdminsForQuery, RemoveAdminsMutation } from '@lens-protocol/graphql';
import type { ResultAsync } from '@lens-protocol/types';

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

/**
Expand Down Expand Up @@ -51,3 +54,23 @@ export function removeAdmins(
): ResultAsync<RemoveAdminsResult, UnexpectedError | UnauthenticatedError> {
return client.mutation(RemoveAdminsMutation, { request });
}

/**
* Fetch admins for.
*
* ```ts
* const result = await fetchAdminsFor(anyClient, {
* address: evmAddress('0xe2f2a5C287993345a840db3B0845fbc70f5935a5'),
* });
* ```
*
* @param client - Any Lens client.
* @param request - The query request.
* @returns The list of admins or empty if it does not exist.
*/
export function fetchAdminsFor(
client: AnyClient,
request: AdminsForRequest,
): ResultAsync<Paginated<Admin> | null, UnexpectedError> {
return client.query(AdminsForQuery, { request });
}
57 changes: 54 additions & 3 deletions packages/client/src/actions/feed.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import type { CreateFeedRequest, CreateFeedResult } from '@lens-protocol/graphql';
import { CreateFeedMutation } from '@lens-protocol/graphql';
import type {
CreateFeedRequest,
CreateFeedResult,
Feed,
FeedRequest,
FeedsRequest,
Paginated,
} from '@lens-protocol/graphql';
import { CreateFeedMutation, FeedQuery, FeedsQuery } from '@lens-protocol/graphql';
import type { ResultAsync } from '@lens-protocol/types';

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

/**
Expand All @@ -22,3 +29,47 @@ export function createFeed(
): ResultAsync<CreateFeedResult, UnexpectedError | UnauthenticatedError> {
return client.mutation(CreateFeedMutation, { request });
}

/**
* Fetch a Feed.
*
* ```ts
* const result = await fetchFeed(anyClient, {
* feed: evmAddress('0xe2f2a5C287993345a840db3B0845fbc70f5935a5'),
* });
* ```
*
* @param client - Any Lens client.
* @param request - The Feed query request.
* @returns The Feed or `null` if it does not exist.
*/
export function fetchFeed(
client: AnyClient,
request: FeedRequest,
): ResultAsync<Feed | null, UnexpectedError> {
return client.query(FeedQuery, { request });
}

/**
* Fetch Feeds.
*
* ```ts
* const result = await fetchFeeds(anyClient, {
* filter: {
* managedBy: {
* address: evmAddress('0xe2f2a5C287993345a840db3B0845fbc70f5935a5')
* }
* },
* });
* ```
*
* @param client - Any Lens client.
* @param request - The Feeds query request.
* @returns The list of Feeds or empty list if none exist.
*/
export function fetchFeeds(
client: AnyClient,
request: FeedsRequest,
): ResultAsync<Paginated<Feed> | null, UnexpectedError> {
return client.query(FeedsQuery, { request });
}
57 changes: 54 additions & 3 deletions packages/client/src/actions/graph.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import type { CreateGraphRequest, CreateGraphResult } from '@lens-protocol/graphql';
import { CreateGraphMutation } from '@lens-protocol/graphql';
import type {
CreateGraphRequest,
CreateGraphResult,
Graph,
GraphRequest,
GraphsRequest,
Paginated,
} from '@lens-protocol/graphql';
import { CreateGraphMutation, GraphQuery, GraphsQuery } from '@lens-protocol/graphql';
import type { ResultAsync } from '@lens-protocol/types';

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

/**
Expand All @@ -22,3 +29,47 @@ export function createGraph(
): ResultAsync<CreateGraphResult, UnexpectedError | UnauthenticatedError> {
return client.mutation(CreateGraphMutation, { request });
}

/**
* Fetch a Graph.
*
* ```ts
* const result = await fetchGraph(anyClient, {
* graph: evmAddress('0xe2f2a5C287993345a840db3B0845fbc70f5935a5'),
* });
* ```
*
* @param client - Any Lens client.
* @param request - The Graph query request.
* @returns The Graph or `null` if it does not exist.
*/
export function fetchGraph(
client: AnyClient,
request: GraphRequest,
): ResultAsync<Graph | null, UnexpectedError> {
return client.query(GraphQuery, { request });
}

/**
* Fetch Graphs.
*
* ```ts
* const result = await fetchGraphs(anyClient, {
* filter: {
* managedBy: {
* address: evmAddress('0xe2f2a5C287993345a840db3B0845fbc70f5935a5')
* }
* },
* });
* ```
*
* @param client - Any Lens client.
* @param request - The Graphs query request.
* @returns The list of Graphs or empty list if none exist.
*/
export function fetchGraphs(
client: AnyClient,
request: GraphsRequest,
): ResultAsync<Paginated<Graph> | null, UnexpectedError> {
return client.query(GraphsQuery, { request });
}
56 changes: 54 additions & 2 deletions packages/client/src/actions/namespace.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
import type {
CreateUsernameNamespaceRequest,
CreateUsernameNamespaceResult,
NamespacesRequest,
Paginated,
UsernameNamespace,
UsernameNamespaceRequest,
} from '@lens-protocol/graphql';
import {
CreateUsernameNamespaceMutation,
NamespacesQuery,
UsernameNamespaceQuery,
} from '@lens-protocol/graphql';
import { CreateUsernameNamespaceMutation } from '@lens-protocol/graphql';
import type { ResultAsync } from '@lens-protocol/types';

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

/**
Expand All @@ -28,3 +36,47 @@ export function createUsernameNamespace(
): ResultAsync<CreateUsernameNamespaceResult, UnexpectedError | UnauthenticatedError> {
return client.mutation(CreateUsernameNamespaceMutation, { request });
}

/**
* Fetch a UsernameNamespace.
*
* ```ts
* const result = await fetchUsernameNamespace(anyClient, {
* namespace: evmAddress('0xe2f2a5C287993345a840db3B0845fbc70f5935a5'),
* });
* ```
*
* @param client - Any Lens client.
* @param request - The query request.
* @returns The UsernameNamespace or `null` if it does not exist.
*/
export function fetchUsernameNamespace(
client: AnyClient,
request: UsernameNamespaceRequest,
): ResultAsync<UsernameNamespace | null, UnexpectedError> {
return client.query(UsernameNamespaceQuery, { request });
}

/**
* Fetch Namespaces.
*
* ```ts
* const result = await fetchNamespaces(anyClient, {
* filter: {
* managedBy: {
* address: evmAddress('0xe2f2a5C287993345a840db3B0845fbc70f5935a5')
* }
* },
* });
* ```
*
* @param client - Any Lens client.
* @param request - The query request.
* @returns The list of Namespaces or empty list if none exist.
*/
export function fetchNamespaces(
client: AnyClient,
request: NamespacesRequest,
): ResultAsync<Paginated<UsernameNamespace> | null, UnexpectedError> {
return client.query(NamespacesQuery, { request });
}
26 changes: 26 additions & 0 deletions packages/graphql/src/admins.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { FragmentOf } from 'gql.tada';
import {
PaginatedResultInfoFragment,
SelfFundedTransactionRequest,
SponsoredTransactionRequest,
TransactionWillFail,
Expand Down Expand Up @@ -57,3 +58,28 @@ export const RemoveAdminsMutation = graphql(
[RemoveAdminsResult],
);
export type RemoveAdminsRequest = RequestOf<typeof RemoveAdminsMutation>;

export const AdminFragment = graphql(
`fragment Admin on Admin {
__typename
address
addedAt
}`,
);
export type Admin = FragmentOf<typeof AdminFragment>;

export const AdminsForQuery = graphql(
`query AdminsFor($request: AdminsForRequest!) {
value: adminsFor(request: $request) {
__typename
items {
...Admin
}
pageInfo {
...PaginatedResultInfo
}
}
}`,
[AdminFragment, PaginatedResultInfoFragment],
);
export type AdminsForRequest = RequestOf<typeof AdminsForQuery>;
33 changes: 32 additions & 1 deletion packages/graphql/src/feed.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import type { FragmentOf } from 'gql.tada';
import { SelfFundedTransactionRequest, TransactionWillFail } from './fragments';
import {
FeedFragment,
PaginatedResultInfoFragment,
SelfFundedTransactionRequest,
TransactionWillFail,
} from './fragments';
import { type RequestOf, graphql } from './graphql';

const CreateFeedResponse = graphql(
Expand Down Expand Up @@ -35,3 +40,29 @@ export const CreateFeedMutation = graphql(
[CreateFeedResult],
);
export type CreateFeedRequest = RequestOf<typeof CreateFeedMutation>;

export const FeedQuery = graphql(
`query Feed($request: FeedRequest!) {
value: feed(request: $request) {
...Feed
}
}`,
[FeedFragment],
);
export type FeedRequest = RequestOf<typeof FeedQuery>;

export const FeedsQuery = graphql(
`query Feeds($request: FeedsRequest!) {
value: feeds(request: $request) {
__typename
items {
...Feed
}
pageInfo {
...PaginatedResultInfo
}
}
}`,
[FeedFragment, PaginatedResultInfoFragment],
);
export type FeedsRequest = RequestOf<typeof FeedsQuery>;
1 change: 0 additions & 1 deletion packages/graphql/src/fragments/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@ export * from './SponsoredTransactionRequest';
export * from './SelfFundedTransactionRequest';
export * from './TransactionWillFail';
export * from './username';
export * from './namespace';
export * from './media';
export * from './metadata';
27 changes: 0 additions & 27 deletions packages/graphql/src/fragments/namespace.ts

This file was deleted.

6 changes: 3 additions & 3 deletions packages/graphql/src/fragments/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
TransactionMetadataFragment,
VideoMetadataFragment,
} from './metadata';
import { AppFragment, Feed } from './primitives';
import { AppFragment, FeedFragment } from './primitives';

export const RecipientDataOutputFragment = graphql(
`fragment RecipientDataOutput on RecipientDataOutput {
Expand Down Expand Up @@ -207,7 +207,7 @@ export const ReferencedPostFragment = graphql(
[
AccountFragment,
AppFragment,
Feed,
FeedFragment,
PostMetadataFragment,
PostActionFragment,
LoggedInPostOperationsFragment,
Expand Down Expand Up @@ -264,7 +264,7 @@ export const PostFragment = graphql(
[
AccountFragment,
AppFragment,
Feed,
FeedFragment,
PostMetadataFragment,
PostActionFragment,
NestedPostFragment,
Expand Down
Loading

0 comments on commit c650381

Please sign in to comment.