diff --git a/packages/client/src/actions/health.ts b/packages/client/src/actions/health.ts index da90d7344..bf59d1e69 100644 --- a/packages/client/src/actions/health.ts +++ b/packages/client/src/actions/health.ts @@ -4,8 +4,7 @@ import type { AnyClient } from '../clients'; import type { UnexpectedError } from '../errors'; /** - * Health checks. - * + * Health check query. * * ```ts * const result = await health(anyClient); diff --git a/packages/client/src/actions/index.ts b/packages/client/src/actions/index.ts index f9bbb6bfe..d3c97fe25 100644 --- a/packages/client/src/actions/index.ts +++ b/packages/client/src/actions/index.ts @@ -5,3 +5,4 @@ export * from './follow'; export * from './post'; export * from './posts'; export * from './transactions'; +export * from './timeline'; diff --git a/packages/client/src/actions/notifications.ts b/packages/client/src/actions/notifications.ts new file mode 100644 index 000000000..4ec4c0822 --- /dev/null +++ b/packages/client/src/actions/notifications.ts @@ -0,0 +1,25 @@ +import type { Notification, NotificationsRequest } from '@lens-protocol/graphql'; +import { NotificationsQuery } from '@lens-protocol/graphql'; +import type { ResultAsync } from '@lens-protocol/types'; + +import type { SessionClient } from '../clients'; +import type { UnexpectedError } from '../errors'; +import type { Paginated } from '../types'; + +/** + * Fetch notifications for the authenticated Account. + * + * ```ts + * const result = await fetchNotifications(sessionClient); + * ``` + * + * @param client - The session client for the authenticated Account. + * @param request - The query request. + * @returns Paginated notifications. + */ +export function fetchNotifications( + client: SessionClient, + request: NotificationsRequest, +): ResultAsync, UnexpectedError> { + return client.query(NotificationsQuery, { request }); +} diff --git a/packages/graphql/src/index.ts b/packages/graphql/src/index.ts index 2bddf8312..a4190f76b 100644 --- a/packages/graphql/src/index.ts +++ b/packages/graphql/src/index.ts @@ -2,10 +2,11 @@ export * from './accounts'; export * from './app'; export * from './authentication'; export * from './enums'; -export * from './fragments'; export * from './follow'; +export * from './fragments'; export * from './graphql'; export * from './health'; +export * from './notifications'; export * from './post'; -export * from './transactions'; export * from './timeline'; +export * from './transactions'; diff --git a/packages/graphql/src/notifications.ts b/packages/graphql/src/notifications.ts new file mode 100644 index 000000000..75a81d5c0 --- /dev/null +++ b/packages/graphql/src/notifications.ts @@ -0,0 +1,143 @@ +import type { FragmentOf } from 'gql.tada'; +import { Account, PaginatedResultInfo, Post } from './fragments'; +import { type RequestOf, graphql } from './graphql'; + +const FollowNotification = graphql( + `fragment FollowNotification on FollowNotification { + __typename + id + followers { + account { + ...Account + } + followedAt + } + }`, + [Account], +); +export type FollowNotification = FragmentOf; + +const ReactionNotification = graphql( + `fragment ReactionNotification on ReactionNotification { + __typename + id + reactions { + account { + ...Account + } + reactions { + reactedAt + reaction + } + } + post { + ...Post + } + }`, + [Account, Post], +); +export type ReactionNotification = FragmentOf; + +const CommentNotification = graphql( + `fragment CommentNotification on CommentNotification { + __typename + id + comment { + ...Post + } + }`, + [Post], +); +export type CommentNotification = FragmentOf; + +const RepostNotification = graphql( + `fragment RepostNotification on RepostNotification { + __typename + id + reposts { + repostId + account { + ...Account + } + repostedAt + } + post { + ...Post + } + }`, + [Account], +); +export type RepostNotification = FragmentOf; + +const QuoteNotification = graphql( + `fragment QuoteNotification on QuoteNotification { + __typename + id + quote { + ...Post + } + }`, + [Post], +); +export type QuoteNotification = FragmentOf; + +const MentionNotification = graphql( + `fragment MentionNotification on MentionNotification { + __typename + id + post { + ...Post + } + }`, + [Post], +); +export type MentionNotification = FragmentOf; + +const Notification = graphql( + `fragment Notification on Notification { + __typename + ... on FollowNotification { + ...FollowNotification + } + ... on ReactionNotification { + ...ReactionNotification + } + ... on CommentNotification { + ...CommentNotification + } + ... on RepostNotification { + ...RepostNotification + } + ... on QuoteNotification { + ...QuoteNotification + } + ... on MentionNotification { + ...MentionNotification + } + }`, + [ + FollowNotification, + ReactionNotification, + CommentNotification, + RepostNotification, + QuoteNotification, + MentionNotification, + ], +); +export type Notification = FragmentOf; + +export const NotificationsQuery = graphql( + `query Notifications($request: NotificationRequest!) { + value: notifications(request: $request) { + __typename + items { + ...Notification + } + pageInfo { + ...PaginatedResultInfo + } + } + }`, + [Notification, PaginatedResultInfo], +); +export type NotificationsRequest = RequestOf;