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 query timeline #987

Merged
merged 1 commit into from
Dec 4, 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
4 changes: 2 additions & 2 deletions packages/client/src/actions/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import type {
CreateAccountWithUsernameRequest,
CreateAccountWithUsernameResult,
EnableSignlessResult,
PaginatedAccountsResult,
SearchAccountsRequest,
SetAccountMetadataRequest,
SetAccountMetadataResult,
Expand All @@ -22,6 +21,7 @@ import type { ResultAsync } from '@lens-protocol/types';
import type { RemoveSignlessResult } from '@lens-protocol/graphql';
import type { AnyClient, SessionClient } from '../clients';
import type { UnauthenticatedError, UnexpectedError } from '../errors';
import type { Paginated } from '../types';

/**
* Fetch an Account.
Expand Down Expand Up @@ -61,7 +61,7 @@ export function fetchAccount(
export function searchAccounts(
client: AnyClient,
request: SearchAccountsRequest,
): ResultAsync<PaginatedAccountsResult | null, UnexpectedError> {
): ResultAsync<Paginated<Account> | null, UnexpectedError> {
return client.query(SearchAccountsQuery, { request });
}

Expand Down
52 changes: 52 additions & 0 deletions packages/client/src/actions/timeline.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import type {
Post,
TimelineHighlightsRequest,
TimelineItem,
TimelineRequest,
} from '@lens-protocol/graphql';
import { TimelineHighlightsQuery, TimelineQuery } from '@lens-protocol/graphql';
import type { ResultAsync } from '@lens-protocol/types';

import type { AnyClient } from '../clients';
import type { UnexpectedError } from '../errors';
import type { Paginated } from '../types';

/**
* Fetch timeline from an account.
*
* ```ts
* const result = await fetchTimeline(anyClient, {
* account: evmAddress('0xe2f2a5C287993345a840db3B0845fbc70f5935a5'),
* });
* ```
*
* @param client - Any Lens client.
* @param request - The query request.
* @returns The list of timeline items.
*/
export function fetchTimeline(
client: AnyClient,
request: TimelineRequest,
): ResultAsync<Paginated<TimelineItem> | null, UnexpectedError> {
return client.query(TimelineQuery, { request });
}

/**
* Fetch fetchTimelineHighlights from an account.
*
* ```ts
* const result = await fetchTimelineHighlights(anyClient, {
* account: evmAddress('0xe2f2a5C287993345a840db3B0845fbc70f5935a5'),
* });
* ```
*
* @param client - Any Lens client.
* @param request - The query request.
* @returns The list of highlights post for an account.
*/
export function fetchTimelineHighlights(
client: AnyClient,
request: TimelineHighlightsRequest,
): ResultAsync<Paginated<Post> | null, UnexpectedError> {
return client.query(TimelineHighlightsQuery, { request });
}
20 changes: 6 additions & 14 deletions packages/graphql/src/accounts/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,19 @@ export const AccountQuery = graphql(

export type AccountRequest = RequestOf<typeof AccountQuery>;

const PaginatedAccountsResult = graphql(
`fragment PaginatedAccountsResult on PaginatedAccountsResult {
__typename
items {
export const SearchAccountsQuery = graphql(
`query SearchAccounts($request: AccountSearchRequest!) {
value: searchAccounts(request: $request) {
__typename
items {
...Account
}
pageInfo {
...PaginatedResultInfo
}
}`,
[Account, PaginatedResultInfo],
);
export type PaginatedAccountsResult = FragmentOf<typeof PaginatedAccountsResult>;

export const SearchAccountsQuery = graphql(
`query SearchAccounts($request: AccountSearchRequest!) {
value: searchAccounts(request: $request) {
...PaginatedAccountsResult
}
}`,
[PaginatedAccountsResult],
[Account, PaginatedResultInfo],
);

export type SearchAccountsRequest = RequestOf<typeof SearchAccountsQuery>;
Expand Down
1 change: 1 addition & 0 deletions packages/graphql/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ export * from './graphql';
export * from './health';
export * from './post';
export * from './transactions';
export * from './timeline';
53 changes: 53 additions & 0 deletions packages/graphql/src/timeline.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import type { FragmentOf } from 'gql.tada';
import { PaginatedResultInfo, Post } from './fragments';
import { type RequestOf, graphql } from './graphql';

const TimelineItem = graphql(
`fragment TimelineItem on TimelineItem {
__typename
id
primary {
...Post
}
comments {
...Post
}
reposts {
...Post
}
}`,
[Post],
);
export type TimelineItem = FragmentOf<typeof TimelineItem>;

export const TimelineQuery = graphql(
`query Timeline($request: TimelineRequest!) {
value: timeline(request: $request) {
__typename
items {
...TimelineItem
}
pageInfo {
...PaginatedResultInfo
}
}
}`,
[TimelineItem, PaginatedResultInfo],
);
export type TimelineRequest = RequestOf<typeof TimelineQuery>;

export const TimelineHighlightsQuery = graphql(
`query TimelineHighlights($request: TimelineHighlightsRequest!) {
value: timelineHighlights(request: $request) {
__typename
items {
...Post
}
pageInfo {
...PaginatedResultInfo
}
}
}`,
[Post, PaginatedResultInfo],
);
export type TimelineHighlightsRequest = RequestOf<typeof TimelineHighlightsQuery>;
Loading