-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement notifications query (#1000)
- Loading branch information
Showing
5 changed files
with
173 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>; |