Skip to content

Commit

Permalink
Implement notifications query (#1000)
Browse files Browse the repository at this point in the history
  • Loading branch information
juangm authored Dec 6, 2024
1 parent 07a5331 commit 1049987
Show file tree
Hide file tree
Showing 5 changed files with 173 additions and 4 deletions.
3 changes: 1 addition & 2 deletions packages/client/src/actions/health.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions packages/client/src/actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ export * from './follow';
export * from './post';
export * from './posts';
export * from './transactions';
export * from './timeline';
25 changes: 25 additions & 0 deletions packages/client/src/actions/notifications.ts
Original file line number Diff line number Diff line change
@@ -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<Paginated<Notification>, UnexpectedError> {
return client.query(NotificationsQuery, { request });
}
5 changes: 3 additions & 2 deletions packages/graphql/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
143 changes: 143 additions & 0 deletions packages/graphql/src/notifications.ts
Original file line number Diff line number Diff line change
@@ -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<typeof FollowNotification>;

const ReactionNotification = graphql(
`fragment ReactionNotification on ReactionNotification {
__typename
id
reactions {
account {
...Account
}
reactions {
reactedAt
reaction
}
}
post {
...Post
}
}`,
[Account, Post],
);
export type ReactionNotification = FragmentOf<typeof ReactionNotification>;

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

const RepostNotification = graphql(
`fragment RepostNotification on RepostNotification {
__typename
id
reposts {
repostId
account {
...Account
}
repostedAt
}
post {
...Post
}
}`,
[Account],
);
export type RepostNotification = FragmentOf<typeof RepostNotification>;

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

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

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<typeof Notification>;

export const NotificationsQuery = graphql(
`query Notifications($request: NotificationRequest!) {
value: notifications(request: $request) {
__typename
items {
...Notification
}
pageInfo {
...PaginatedResultInfo
}
}
}`,
[Notification, PaginatedResultInfo],
);
export type NotificationsRequest = RequestOf<typeof NotificationsQuery>;

0 comments on commit 1049987

Please sign in to comment.