export interface Notification { user: { name: string; avatar: { large: string; }; }; thread: { title: string; }; context: string; id: number; createdAt: number; type: | 'FOLLOWING' | 'ACTIVITY_MESSAGE' | 'ACTIVITY_MENTION' | 'ACTIVITY_REPLY' | 'ACTIVITY_REPLY_SUBSCRIBED' | 'ACTIVITY_LIKE' | 'ACTIVITY_REPLY_LIKE' | 'THREAD_COMMENT_MENTION' | 'THREAD_COMMENT_REPLY' | 'THREAD_SUBSCRIBED' | 'THREAD_COMMENT_LIKE' | 'THREAD_LIKE'; } export const notifications = async (accessToken: string): Promise => { const activityNotification = (type: string) => `... on ${type} { id user { name avatar { large } } context createdAt type }`; const threadNotification = (type: string) => `... on ${type} { id user { name avatar { large } } context createdAt type thread { title } }`; return ( await ( await fetch('https://graphql.anilist.co', { method: 'POST', headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${accessToken}`, Accept: 'application/json' }, body: JSON.stringify({ query: `{ Page(page: 1, perPage: 50) { notifications { ${activityNotification('FollowingNotification')} ${activityNotification('ActivityMessageNotification')} ${activityNotification('ActivityMentionNotification')} ${activityNotification('ActivityReplyNotification')} ${activityNotification('ActivityReplySubscribedNotification')} ${activityNotification('ActivityLikeNotification')} ${activityNotification('ActivityReplyLikeNotification')} ${threadNotification('ThreadCommentMentionNotification')} ${threadNotification('ThreadCommentReplyNotification')} ${threadNotification('ThreadCommentSubscribedNotification')} ${threadNotification('ThreadCommentLikeNotification')} ${threadNotification('ThreadLikeNotification')} } } }` }) }) ).json() )['data']['Page']['notifications']; };