From ffe11e4418923b67cda32a6585880711a812607e Mon Sep 17 00:00:00 2001 From: MaPoKen Date: Fri, 10 Nov 2023 13:52:18 +0100 Subject: [PATCH 1/6] Added notification endpoint, resolver functions and types --- src/api/arenaApi.ts | 22 ++++++++++++++++++++++ src/resolvers/arenaResolvers.ts | 10 ++++++++++ src/schema.ts | 14 ++++++++++++++ src/types/schema.d.ts | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 79 insertions(+) diff --git a/src/api/arenaApi.ts b/src/api/arenaApi.ts index 684f2282..5cf3b615 100644 --- a/src/api/arenaApi.ts +++ b/src/api/arenaApi.ts @@ -8,6 +8,7 @@ import { GQLArenaCategory, + GQLArenaNotification, GQLArenaPost, GQLArenaTopic, GQLArenaUser, @@ -67,6 +68,19 @@ const toCategory = (category: any): GQLArenaCategory => { }; }; +const toNotification = (notification: any): GQLArenaNotification => ({ + bodyShort: notification.bodyShort, + datetimeISO: notification.datetimeISO, + datetime: notification.datetime, + from: notification.from, + importance: notification.importance, + path: notification.path, + read: notification.read, + user: toUser(notification.user), + readClass: notification.readClass, + image: notification.image, +}); + export const fetchArenaUser = async ( { username }: GQLQueryArenaUserArgs, context: Context, @@ -127,3 +141,11 @@ export const fetchArenaTopicsByUser = async ( const resolved = await resolveJson(response); return resolved.topics.map(toTopic); }; + +export const fetchArenaNotifications = async ( + context: Context, +): Promise => { + const response = await fetch(`/groups/api/notifications`, context); + const resolved = await resolveJson(response); + return resolved.notifications.map(toNotification); +}; diff --git a/src/resolvers/arenaResolvers.ts b/src/resolvers/arenaResolvers.ts index 9b00a7af..263fdad1 100644 --- a/src/resolvers/arenaResolvers.ts +++ b/src/resolvers/arenaResolvers.ts @@ -13,6 +13,7 @@ import { fetchArenaUser, fetchArenaTopic, fetchArenaTopicsByUser, + fetchArenaNotifications, } from '../api/arenaApi'; import { GQLArenaCategory, @@ -23,6 +24,7 @@ import { GQLQueryArenaTopicArgs, GQLQueryArenaTopicsByUserArgs, GQLQueryResolvers, + GQLArenaNotification, } from '../types/schema'; export const Query: Pick< @@ -33,6 +35,7 @@ export const Query: Pick< | 'arenaTopic' | 'arenaRecentTopics' | 'arenaTopicsByUser' + | 'arenaNotifications' > = { async arenaUser( _: any, @@ -76,4 +79,11 @@ export const Query: Pick< ): Promise { return fetchArenaTopicsByUser(params, context); }, + async arenaNotifications( + _: any, + __: any, + context: ContextWithLoaders, + ): Promise { + return fetchArenaNotifications(context); + }, }; diff --git a/src/schema.ts b/src/schema.ts index e8824b9d..bff70ac1 100644 --- a/src/schema.ts +++ b/src/schema.ts @@ -1200,6 +1200,19 @@ export const typeDefs = gql` breadcrumbs: [ArenaBreadcrumb!]! } + type ArenaNotification { + bodyShort: String! + path: String! + from: Int! + importance: Int! + datetime: Int! + datetimeISO: String! + read: Boolean! + user: ArenaUser! + image: String! + readClass: String! + } + type Query { resource(id: String!, subjectId: String, topicId: String): Resource articleResource(articleId: String, taxonomyId: String): Resource @@ -1332,6 +1345,7 @@ export const typeDefs = gql` arenaTopic(topicId: Int!, page: Int!): ArenaTopic arenaRecentTopics: [ArenaTopic!]! arenaTopicsByUser(userSlug: String!): [ArenaTopic!]! + arenaNotifications: [ArenaNotification!]! } type Mutation { diff --git a/src/types/schema.d.ts b/src/types/schema.d.ts index 2ef0e598..22378162 100644 --- a/src/types/schema.d.ts +++ b/src/types/schema.d.ts @@ -43,6 +43,20 @@ export type GQLArenaCategory = { topics?: Maybe>; }; +export type GQLArenaNotification = { + __typename?: 'ArenaNotification'; + bodyShort: Scalars['String']; + datetime: Scalars['Int']; + datetimeISO: Scalars['String']; + from: Scalars['Int']; + image: Scalars['String']; + importance: Scalars['Int']; + path: Scalars['String']; + read: Scalars['Boolean']; + readClass: Scalars['String']; + user: GQLArenaUser; +}; + export type GQLArenaPost = { __typename?: 'ArenaPost'; content: Scalars['String']; @@ -1063,6 +1077,7 @@ export type GQLQuery = { allFolderResources: Array; arenaCategories: Array; arenaCategory?: Maybe; + arenaNotifications: Array; arenaRecentTopics: Array; arenaTopic?: Maybe; arenaTopicsByUser: Array; @@ -1851,6 +1866,7 @@ export type GQLResolversTypes = { AggregationResult: ResolverTypeWrapper; ArenaBreadcrumb: ResolverTypeWrapper; ArenaCategory: ResolverTypeWrapper; + ArenaNotification: ResolverTypeWrapper; ArenaPost: ResolverTypeWrapper; ArenaTopic: ResolverTypeWrapper; ArenaUser: ResolverTypeWrapper; @@ -1998,6 +2014,7 @@ export type GQLResolversParentTypes = { AggregationResult: GQLAggregationResult; ArenaBreadcrumb: GQLArenaBreadcrumb; ArenaCategory: GQLArenaCategory; + ArenaNotification: GQLArenaNotification; ArenaPost: GQLArenaPost; ArenaTopic: GQLArenaTopic; ArenaUser: GQLArenaUser; @@ -2168,6 +2185,20 @@ export type GQLArenaCategoryResolvers; }; +export type GQLArenaNotificationResolvers = { + bodyShort?: Resolver; + datetime?: Resolver; + datetimeISO?: Resolver; + from?: Resolver; + image?: Resolver; + importance?: Resolver; + path?: Resolver; + read?: Resolver; + readClass?: Resolver; + user?: Resolver; + __isTypeOf?: IsTypeOfResolverFn; +}; + export type GQLArenaPostResolvers = { content?: Resolver; id?: Resolver; @@ -3096,6 +3127,7 @@ export type GQLQueryResolvers, ParentType, ContextType, Partial>; arenaCategories?: Resolver, ParentType, ContextType>; arenaCategory?: Resolver, ParentType, ContextType, RequireFields>; + arenaNotifications?: Resolver, ParentType, ContextType>; arenaRecentTopics?: Resolver, ParentType, ContextType>; arenaTopic?: Resolver, ParentType, ContextType, RequireFields>; arenaTopicsByUser?: Resolver, ParentType, ContextType, RequireFields>; @@ -3516,6 +3548,7 @@ export type GQLResolvers = { AggregationResult?: GQLAggregationResultResolvers; ArenaBreadcrumb?: GQLArenaBreadcrumbResolvers; ArenaCategory?: GQLArenaCategoryResolvers; + ArenaNotification?: GQLArenaNotificationResolvers; ArenaPost?: GQLArenaPostResolvers; ArenaTopic?: GQLArenaTopicResolvers; ArenaUser?: GQLArenaUserResolvers; From 14b9bf6cebd547c28f2eeb031d8a9bee8da9ab75 Mon Sep 17 00:00:00 2001 From: MaPoKen Date: Wed, 22 Nov 2023 19:35:46 +0100 Subject: [PATCH 2/6] Added notification mutation that isn't really a mutation --- src/api/arenaApi.ts | 16 +++++++++++++++- src/resolvers/arenaResolvers.ts | 13 +++++++++++++ src/resolvers/index.ts | 6 +++++- src/schema.ts | 10 ++++++++-- src/types/schema.d.ts | 31 ++++++++++++++++++++++++------- 5 files changed, 65 insertions(+), 11 deletions(-) diff --git a/src/api/arenaApi.ts b/src/api/arenaApi.ts index 8071d9bc..a0292216 100644 --- a/src/api/arenaApi.ts +++ b/src/api/arenaApi.ts @@ -12,6 +12,7 @@ import { GQLArenaPost, GQLArenaTopic, GQLArenaUser, + GQLMutationMarkNotificationAsReadArgs, GQLQueryArenaCategoryArgs, GQLQueryArenaTopicArgs, GQLQueryArenaTopicsByUserArgs, @@ -72,7 +73,6 @@ const toCategory = (category: any): GQLArenaCategory => { const toNotification = (notification: any): GQLArenaNotification => ({ bodyShort: notification.bodyShort, datetimeISO: notification.datetimeISO, - datetime: notification.datetime, from: notification.from, importance: notification.importance, path: notification.path, @@ -80,6 +80,12 @@ const toNotification = (notification: any): GQLArenaNotification => ({ user: toUser(notification.user), readClass: notification.readClass, image: notification.image, + topicTitle: notification.topicTitle, + type: notification.type, + subject: notification.subject, + topicId: notification.tid, + postId: notification.pid, + notificationId: notification.nid, }); export const fetchArenaUser = async ( @@ -150,3 +156,11 @@ export const fetchArenaNotifications = async ( const resolved = await resolveJson(response); return resolved.notifications.map(toNotification); }; + +export const markNotificationRead = async ( + { topicId }: GQLMutationMarkNotificationAsReadArgs, + context: Context, +): Promise => { + await fetch(`/groups/api/topic/${topicId}`, context); + return topicId; +}; diff --git a/src/resolvers/arenaResolvers.ts b/src/resolvers/arenaResolvers.ts index 263fdad1..f101333b 100644 --- a/src/resolvers/arenaResolvers.ts +++ b/src/resolvers/arenaResolvers.ts @@ -25,6 +25,8 @@ import { GQLQueryArenaTopicsByUserArgs, GQLQueryResolvers, GQLArenaNotification, + GQLMutationResolvers, + GQLMutationMarkNotificationAsReadArgs, } from '../types/schema'; export const Query: Pick< @@ -87,3 +89,14 @@ export const Query: Pick< return fetchArenaNotifications(context); }, }; + +export const Mutations: Pick = { + async markNotificationAsRead( + _: any, + params: GQLMutationMarkNotificationAsReadArgs, + context: Context, + ) { + await fetchArenaTopic(params, context); + return params.topicId; + }, +}; diff --git a/src/resolvers/index.ts b/src/resolvers/index.ts index 209efa3c..5d3d4a55 100644 --- a/src/resolvers/index.ts +++ b/src/resolvers/index.ts @@ -69,7 +69,10 @@ import { resolvers as ProgrammeResolvers, } from './programmeResolvers'; -import { Query as ArenaQuery } from './arenaResolvers'; +import { + Query as ArenaQuery, + Mutations as ArenaMutations, +} from './arenaResolvers'; export const resolvers = { Query: { @@ -93,6 +96,7 @@ export const resolvers = { Mutation: { ...FolderMutations, ...TransformArticleMutations, + ...ArenaMutations, }, ...folderResolvers, ...articleResolvers, diff --git a/src/schema.ts b/src/schema.ts index 410345a6..d2370810 100644 --- a/src/schema.ts +++ b/src/schema.ts @@ -1225,12 +1225,17 @@ export const typeDefs = gql` path: String! from: Int! importance: Int! - datetime: Int! datetimeISO: String! read: Boolean! user: ArenaUser! image: String! readClass: String! + postId: Int! + topicId: Int! + notificationId: String! + topicTitle: String! + type: String! + subject: String! } type Query { @@ -1364,7 +1369,7 @@ export const typeDefs = gql` arenaCategories: [ArenaCategory!]! arenaCategory(categoryId: Int!, page: Int!): ArenaCategory arenaUser(username: String!): ArenaUser - arenaTopic(topicId: Int!, page: Int!): ArenaTopic + arenaTopic(topicId: Int!, page: Int): ArenaTopic arenaRecentTopics: [ArenaTopic!]! arenaTopicsByUser(userSlug: String!): [ArenaTopic!]! arenaNotifications: [ArenaNotification!]! @@ -1407,6 +1412,7 @@ export const typeDefs = gql` draftConcept: Boolean absoluteUrl: Boolean ): String! + markNotificationAsRead(topicId: Int!): Int! } `; diff --git a/src/types/schema.d.ts b/src/types/schema.d.ts index 2f26056e..4b5f1a69 100644 --- a/src/types/schema.d.ts +++ b/src/types/schema.d.ts @@ -46,14 +46,19 @@ export type GQLArenaCategory = { export type GQLArenaNotification = { __typename?: 'ArenaNotification'; bodyShort: Scalars['String']; - datetime: Scalars['Int']; datetimeISO: Scalars['String']; from: Scalars['Int']; image: Scalars['String']; importance: Scalars['Int']; + notificationId: Scalars['String']; path: Scalars['String']; + postId: Scalars['Int']; read: Scalars['Boolean']; readClass: Scalars['String']; + subject: Scalars['String']; + topicId: Scalars['Int']; + topicTitle: Scalars['String']; + type: Scalars['String']; user: GQLArenaUser; }; @@ -890,6 +895,7 @@ export type GQLMutation = { deleteFolder: Scalars['String']; deleteFolderResource: Scalars['String']; deletePersonalData: Scalars['Boolean']; + markNotificationAsRead: Scalars['Int']; sortFolders: GQLSortResult; sortResources: GQLSortResult; transformArticleContent: Scalars['String']; @@ -934,6 +940,11 @@ export type GQLMutationDeleteFolderResourceArgs = { }; +export type GQLMutationMarkNotificationAsReadArgs = { + topicId: Scalars['Int']; +}; + + export type GQLMutationSortFoldersArgs = { parentId?: InputMaybe; sortedIds: Array; @@ -1099,8 +1110,8 @@ export type GQLQuery = { allFolderResources: Array; arenaCategories: Array; arenaCategory?: Maybe; - arenaNotifications: Array; arenaEnabledOrgs?: Maybe; + arenaNotifications: Array; arenaRecentTopics: Array; arenaTopic?: Maybe; arenaTopicsByUser: Array; @@ -1159,7 +1170,7 @@ export type GQLQueryArenaCategoryArgs = { export type GQLQueryArenaTopicArgs = { - page: Scalars['Int']; + page?: InputMaybe; topicId: Scalars['Int']; }; @@ -2215,14 +2226,19 @@ export type GQLArenaCategoryResolvers = { bodyShort?: Resolver; - datetime?: Resolver; datetimeISO?: Resolver; from?: Resolver; image?: Resolver; importance?: Resolver; + notificationId?: Resolver; path?: Resolver; + postId?: Resolver; read?: Resolver; readClass?: Resolver; + subject?: Resolver; + topicId?: Resolver; + topicTitle?: Resolver; + type?: Resolver; user?: Resolver; __isTypeOf?: IsTypeOfResolverFn; }; @@ -2252,7 +2268,7 @@ export type GQLArenaTopicResolvers = { displayName?: Resolver; - groupTitleArray?: Resolver>>, ParentType, ContextType>; + groupTitleArray?: Resolver, ParentType, ContextType>; id?: Resolver; profilePicture?: Resolver, ParentType, ContextType>; slug?: Resolver; @@ -3049,6 +3065,7 @@ export type GQLMutationResolvers>; deleteFolderResource?: Resolver>; deletePersonalData?: Resolver; + markNotificationAsRead?: Resolver>; sortFolders?: Resolver>; sortResources?: Resolver>; transformArticleContent?: Resolver>; @@ -3177,10 +3194,10 @@ export type GQLQueryResolvers, ParentType, ContextType, Partial>; arenaCategories?: Resolver, ParentType, ContextType>; arenaCategory?: Resolver, ParentType, ContextType, RequireFields>; - arenaNotifications?: Resolver, ParentType, ContextType>; arenaEnabledOrgs?: Resolver, ParentType, ContextType>; + arenaNotifications?: Resolver, ParentType, ContextType>; arenaRecentTopics?: Resolver, ParentType, ContextType>; - arenaTopic?: Resolver, ParentType, ContextType, RequireFields>; + arenaTopic?: Resolver, ParentType, ContextType, RequireFields>; arenaTopicsByUser?: Resolver, ParentType, ContextType, RequireFields>; arenaUser?: Resolver, ParentType, ContextType, RequireFields>; article?: Resolver, ParentType, ContextType, RequireFields>; From eaf72b9ccf650f31fd6d778fd2d35677177e13f2 Mon Sep 17 00:00:00 2001 From: MaPoKen Date: Thu, 23 Nov 2023 12:15:52 +0100 Subject: [PATCH 3/6] Added csrf token to topic. Update marknotifications to handle array instead of single number --- src/api/arenaApi.ts | 18 ++++++------------ src/resolvers/arenaResolvers.ts | 6 ++++-- src/schema.ts | 2 +- src/types/schema.d.ts | 6 +++--- 4 files changed, 14 insertions(+), 18 deletions(-) diff --git a/src/api/arenaApi.ts b/src/api/arenaApi.ts index 96ba2065..18e80c9f 100644 --- a/src/api/arenaApi.ts +++ b/src/api/arenaApi.ts @@ -146,7 +146,7 @@ export const fetchArenaCategory = async ( `/groups/api/category/${categoryId}?page=${page}`, context, ); - const resolved: any = await resolveJson(response); + const resolved = await resolveJson(response); return toCategory(resolved); }; @@ -154,11 +154,13 @@ export const fetchArenaTopic = async ( { topicId, page }: GQLQueryArenaTopicArgs, context: Context, ): Promise => { + const csrfHeaders = await fetchCsrfTokenForSession(context); const response = await fetch( - `/groups/api/topic/${topicId}?page=${page}`, + `/groups/api/topic/${topicId}?page=${page ?? 1}`, context, + { headers: csrfHeaders }, ); - const resolved: any = await resolveJson(response); + const resolved = await resolveJson(response); return toTopic(resolved); }; @@ -182,19 +184,11 @@ export const fetchArenaTopicsByUser = async ( export const fetchArenaNotifications = async ( context: Context, ): Promise => { - const response = await fetch(`/groups/api/notifications`, context); + const response = await fetch('/groups/api/notifications', context); const resolved = await resolveJson(response); return resolved.notifications.map(toNotification); }; -export const markNotificationRead = async ( - { topicId }: GQLMutationMarkNotificationAsReadArgs, - context: Context, -): Promise => { - await fetch(`/groups/api/topic/${topicId}`, context); - return topicId; -}; - export const newTopic = async ( { title, content, categoryId }: GQLMutationNewArenaTopicArgs, context: Context, diff --git a/src/resolvers/arenaResolvers.ts b/src/resolvers/arenaResolvers.ts index a40385cb..728d9e57 100644 --- a/src/resolvers/arenaResolvers.ts +++ b/src/resolvers/arenaResolvers.ts @@ -117,7 +117,9 @@ export const Mutations: Pick< params: GQLMutationMarkNotificationAsReadArgs, context: Context, ) { - await fetchArenaTopic(params, context); - return params.topicId; + await Promise.all( + params.topicIds.map(topicId => fetchArenaTopic({ topicId }, context)), + ); + return params.topicIds; }, }; diff --git a/src/schema.ts b/src/schema.ts index 62dcd159..ae9708e6 100644 --- a/src/schema.ts +++ b/src/schema.ts @@ -1421,7 +1421,7 @@ export const typeDefs = gql` draftConcept: Boolean absoluteUrl: Boolean ): String! - markNotificationAsRead(topicId: Int!): Int! + markNotificationAsRead(topicIds: [Int!]!): [Int!]! newArenaTopic( categoryId: Int! title: String! diff --git a/src/types/schema.d.ts b/src/types/schema.d.ts index bab5c53d..00522ca4 100644 --- a/src/types/schema.d.ts +++ b/src/types/schema.d.ts @@ -895,7 +895,7 @@ export type GQLMutation = { deleteFolder: Scalars['String']; deleteFolderResource: Scalars['String']; deletePersonalData: Scalars['Boolean']; - markNotificationAsRead: Scalars['Int']; + markNotificationAsRead: Array; newArenaTopic: GQLArenaTopic; replyToTopic: GQLArenaPost; sortFolders: GQLSortResult; @@ -943,7 +943,7 @@ export type GQLMutationDeleteFolderResourceArgs = { export type GQLMutationMarkNotificationAsReadArgs = { - topicId: Scalars['Int']; + topicIds: Array; }; @@ -3090,7 +3090,7 @@ export type GQLMutationResolvers>; deleteFolderResource?: Resolver>; deletePersonalData?: Resolver; - markNotificationAsRead?: Resolver>; + markNotificationAsRead?: Resolver, ParentType, ContextType, RequireFields>; newArenaTopic?: Resolver>; replyToTopic?: Resolver>; sortFolders?: Resolver>; From f625fa379b2f246011a7cf14e073794bd9fb1fe6 Mon Sep 17 00:00:00 2001 From: MaPoKen Date: Thu, 23 Nov 2023 12:56:35 +0100 Subject: [PATCH 4/6] Removed required on notification image --- src/schema.ts | 2 +- src/types/schema.d.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/schema.ts b/src/schema.ts index ae9708e6..f4a2ac56 100644 --- a/src/schema.ts +++ b/src/schema.ts @@ -1234,7 +1234,7 @@ export const typeDefs = gql` datetimeISO: String! read: Boolean! user: ArenaUser! - image: String! + image: String readClass: String! postId: Int! topicId: Int! diff --git a/src/types/schema.d.ts b/src/types/schema.d.ts index 00522ca4..8cf1d7a8 100644 --- a/src/types/schema.d.ts +++ b/src/types/schema.d.ts @@ -48,7 +48,7 @@ export type GQLArenaNotification = { bodyShort: Scalars['String']; datetimeISO: Scalars['String']; from: Scalars['Int']; - image: Scalars['String']; + image?: Maybe; importance: Scalars['Int']; notificationId: Scalars['String']; path: Scalars['String']; @@ -2253,7 +2253,7 @@ export type GQLArenaNotificationResolvers; datetimeISO?: Resolver; from?: Resolver; - image?: Resolver; + image?: Resolver, ParentType, ContextType>; importance?: Resolver; notificationId?: Resolver; path?: Resolver; From d2ef600b5d97d4101916ae42d734616614aa9afd Mon Sep 17 00:00:00 2001 From: MaPoKen Date: Thu, 23 Nov 2023 14:20:39 +0100 Subject: [PATCH 5/6] Update user types --- src/api/arenaApi.ts | 19 ++++++++++++----- src/schema.ts | 20 ++++++++++++++++-- src/types/schema.d.ts | 47 ++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 76 insertions(+), 10 deletions(-) diff --git a/src/api/arenaApi.ts b/src/api/arenaApi.ts index 18e80c9f..03d9fc3a 100644 --- a/src/api/arenaApi.ts +++ b/src/api/arenaApi.ts @@ -12,7 +12,8 @@ import { GQLArenaPost, GQLArenaTopic, GQLArenaUser, - GQLMutationMarkNotificationAsReadArgs, + GQLArenaUserNotification, + GQLBaseUser, GQLMutationNewArenaTopicArgs, GQLMutationReplyToTopicArgs, GQLQueryArenaCategoryArgs, @@ -22,22 +23,30 @@ import { } from '../types/schema'; import { fetch, resolveJson } from '../utils/apiHelpers'; -const toUser = (user: any): GQLArenaUser => ({ +const toBaseUser = (user: any): Omit => ({ id: user.uid, displayName: user.displayname, username: user.username, profilePicture: user.picture, slug: user.userslug, +}); + +const toArenaUser = (user: any): GQLArenaUser => ({ + ...toBaseUser(user), groupTitleArray: user.groupTitleArray, }); +const toArenaNotificationUser = (user: any): GQLArenaUserNotification => ({ + ...toBaseUser(user), +}); + const toArenaPost = (post: any, mainPid?: any): GQLArenaPost => ({ id: post.pid, topicId: post.tid, content: post.content, timestamp: post.timestampISO, isMainPost: post.isMainPost ?? post.pid === mainPid, - user: toUser(post.user), + user: toArenaUser(post.user), }); const toTopic = (topic: any): GQLArenaTopic => { @@ -83,7 +92,7 @@ const toNotification = (notification: any): GQLArenaNotification => ({ importance: notification.importance, path: notification.path, read: notification.read, - user: toUser(notification.user), + user: toArenaNotificationUser(notification.user), readClass: notification.readClass, image: notification.image, topicTitle: notification.topicTitle, @@ -127,7 +136,7 @@ export const fetchArenaUser = async ( context, ); const resolved: any = await resolveJson(response); - return toUser(resolved); + return toArenaUser(resolved); }; export const fetchArenaCategories = async ( diff --git a/src/schema.ts b/src/schema.ts index f4a2ac56..39da6407 100644 --- a/src/schema.ts +++ b/src/schema.ts @@ -1190,7 +1190,15 @@ export const typeDefs = gql` topics: [ArenaTopic!] } - type ArenaUser { + interface BaseUser { + id: Int! + displayName: String! + username: String! + profilePicture: String + slug: String! + } + + type ArenaUser implements BaseUser { id: Int! displayName: String! username: String! @@ -1199,6 +1207,14 @@ export const typeDefs = gql` groupTitleArray: [String!]! } + type ArenaUserNotification implements BaseUser { + id: Int! + displayName: String! + username: String! + profilePicture: String + slug: String! + } + type ArenaPost { id: Int! topicId: Int! @@ -1233,7 +1249,7 @@ export const typeDefs = gql` importance: Int! datetimeISO: String! read: Boolean! - user: ArenaUser! + user: ArenaUserNotification! image: String readClass: String! postId: Int! diff --git a/src/types/schema.d.ts b/src/types/schema.d.ts index 8cf1d7a8..80e80cb1 100644 --- a/src/types/schema.d.ts +++ b/src/types/schema.d.ts @@ -59,7 +59,7 @@ export type GQLArenaNotification = { topicId: Scalars['Int']; topicTitle: Scalars['String']; type: Scalars['String']; - user: GQLArenaUser; + user: GQLArenaUserNotification; }; export type GQLArenaPost = { @@ -85,7 +85,7 @@ export type GQLArenaTopic = { title: Scalars['String']; }; -export type GQLArenaUser = { +export type GQLArenaUser = GQLBaseUser & { __typename?: 'ArenaUser'; displayName: Scalars['String']; groupTitleArray: Array; @@ -95,6 +95,15 @@ export type GQLArenaUser = { username: Scalars['String']; }; +export type GQLArenaUserNotification = GQLBaseUser & { + __typename?: 'ArenaUserNotification'; + displayName: Scalars['String']; + id: Scalars['Int']; + profilePicture?: Maybe; + slug: Scalars['String']; + username: Scalars['String']; +}; + export type GQLArticle = { __typename?: 'Article'; articleType: Scalars['String']; @@ -243,6 +252,14 @@ export type GQLAudioSummary = { url: Scalars['String']; }; +export type GQLBaseUser = { + displayName: Scalars['String']; + id: Scalars['Int']; + profilePicture?: Maybe; + slug: Scalars['String']; + username: Scalars['String']; +}; + export type GQLBreadcrumb = { __typename?: 'Breadcrumb'; id: Scalars['String']; @@ -1928,6 +1945,7 @@ export type GQLResolversTypes = { ArenaPost: ResolverTypeWrapper; ArenaTopic: ResolverTypeWrapper; ArenaUser: ResolverTypeWrapper; + ArenaUserNotification: ResolverTypeWrapper; Article: ResolverTypeWrapper; ArticleFolderResourceMeta: ResolverTypeWrapper; ArticleMetaData: ResolverTypeWrapper; @@ -1939,6 +1957,7 @@ export type GQLResolversTypes = { AudioLicense: ResolverTypeWrapper; AudioSearch: ResolverTypeWrapper; AudioSummary: ResolverTypeWrapper; + BaseUser: GQLResolversTypes['ArenaUser'] | GQLResolversTypes['ArenaUserNotification']; Boolean: ResolverTypeWrapper; Breadcrumb: ResolverTypeWrapper; BrightcoveCustomFields: ResolverTypeWrapper; @@ -2079,6 +2098,7 @@ export type GQLResolversParentTypes = { ArenaPost: GQLArenaPost; ArenaTopic: GQLArenaTopic; ArenaUser: GQLArenaUser; + ArenaUserNotification: GQLArenaUserNotification; Article: GQLArticle; ArticleFolderResourceMeta: GQLArticleFolderResourceMeta; ArticleMetaData: GQLArticleMetaData; @@ -2090,6 +2110,7 @@ export type GQLResolversParentTypes = { AudioLicense: GQLAudioLicense; AudioSearch: GQLAudioSearch; AudioSummary: GQLAudioSummary; + BaseUser: GQLResolversParentTypes['ArenaUser'] | GQLResolversParentTypes['ArenaUserNotification']; Boolean: Scalars['Boolean']; Breadcrumb: GQLBreadcrumb; BrightcoveCustomFields: GQLBrightcoveCustomFields; @@ -2264,7 +2285,7 @@ export type GQLArenaNotificationResolvers; topicTitle?: Resolver; type?: Resolver; - user?: Resolver; + user?: Resolver; __isTypeOf?: IsTypeOfResolverFn; }; @@ -2301,6 +2322,15 @@ export type GQLArenaUserResolvers; }; +export type GQLArenaUserNotificationResolvers = { + displayName?: Resolver; + id?: Resolver; + profilePicture?: Resolver, ParentType, ContextType>; + slug?: Resolver; + username?: Resolver; + __isTypeOf?: IsTypeOfResolverFn; +}; + export type GQLArticleResolvers = { articleType?: Resolver; availability?: Resolver, ParentType, ContextType>; @@ -2444,6 +2474,15 @@ export type GQLAudioSummaryResolvers; }; +export type GQLBaseUserResolvers = { + __resolveType: TypeResolveFn<'ArenaUser' | 'ArenaUserNotification', ParentType, ContextType>; + displayName?: Resolver; + id?: Resolver; + profilePicture?: Resolver, ParentType, ContextType>; + slug?: Resolver; + username?: Resolver; +}; + export type GQLBreadcrumbResolvers = { id?: Resolver; name?: Resolver; @@ -3655,6 +3694,7 @@ export type GQLResolvers = { ArenaPost?: GQLArenaPostResolvers; ArenaTopic?: GQLArenaTopicResolvers; ArenaUser?: GQLArenaUserResolvers; + ArenaUserNotification?: GQLArenaUserNotificationResolvers; Article?: GQLArticleResolvers; ArticleFolderResourceMeta?: GQLArticleFolderResourceMetaResolvers; ArticleMetaData?: GQLArticleMetaDataResolvers; @@ -3666,6 +3706,7 @@ export type GQLResolvers = { AudioLicense?: GQLAudioLicenseResolvers; AudioSearch?: GQLAudioSearchResolvers; AudioSummary?: GQLAudioSummaryResolvers; + BaseUser?: GQLBaseUserResolvers; Breadcrumb?: GQLBreadcrumbResolvers; BrightcoveCustomFields?: GQLBrightcoveCustomFieldsResolvers; BrightcoveElement?: GQLBrightcoveElementResolvers; From 7dd9b0f80c1f7ac8ec66b5712e60501171a52bdb Mon Sep 17 00:00:00 2001 From: MaPoKen Date: Thu, 23 Nov 2023 14:26:00 +0100 Subject: [PATCH 6/6] Update user name --- src/api/arenaApi.ts | 4 ++-- src/schema.ts | 4 ++-- src/types/schema.d.ts | 52 +++++++++++++++++++++---------------------- 3 files changed, 30 insertions(+), 30 deletions(-) diff --git a/src/api/arenaApi.ts b/src/api/arenaApi.ts index 03d9fc3a..be48a2ac 100644 --- a/src/api/arenaApi.ts +++ b/src/api/arenaApi.ts @@ -9,10 +9,10 @@ import { GQLArenaCategory, GQLArenaNotification, + GQLArenaNotificationUser, GQLArenaPost, GQLArenaTopic, GQLArenaUser, - GQLArenaUserNotification, GQLBaseUser, GQLMutationNewArenaTopicArgs, GQLMutationReplyToTopicArgs, @@ -36,7 +36,7 @@ const toArenaUser = (user: any): GQLArenaUser => ({ groupTitleArray: user.groupTitleArray, }); -const toArenaNotificationUser = (user: any): GQLArenaUserNotification => ({ +const toArenaNotificationUser = (user: any): GQLArenaNotificationUser => ({ ...toBaseUser(user), }); diff --git a/src/schema.ts b/src/schema.ts index 39da6407..a5e890b2 100644 --- a/src/schema.ts +++ b/src/schema.ts @@ -1207,7 +1207,7 @@ export const typeDefs = gql` groupTitleArray: [String!]! } - type ArenaUserNotification implements BaseUser { + type ArenaNotificationUser implements BaseUser { id: Int! displayName: String! username: String! @@ -1249,7 +1249,7 @@ export const typeDefs = gql` importance: Int! datetimeISO: String! read: Boolean! - user: ArenaUserNotification! + user: ArenaNotificationUser! image: String readClass: String! postId: Int! diff --git a/src/types/schema.d.ts b/src/types/schema.d.ts index 80e80cb1..e52d6e38 100644 --- a/src/types/schema.d.ts +++ b/src/types/schema.d.ts @@ -59,7 +59,16 @@ export type GQLArenaNotification = { topicId: Scalars['Int']; topicTitle: Scalars['String']; type: Scalars['String']; - user: GQLArenaUserNotification; + user: GQLArenaNotificationUser; +}; + +export type GQLArenaNotificationUser = GQLBaseUser & { + __typename?: 'ArenaNotificationUser'; + displayName: Scalars['String']; + id: Scalars['Int']; + profilePicture?: Maybe; + slug: Scalars['String']; + username: Scalars['String']; }; export type GQLArenaPost = { @@ -95,15 +104,6 @@ export type GQLArenaUser = GQLBaseUser & { username: Scalars['String']; }; -export type GQLArenaUserNotification = GQLBaseUser & { - __typename?: 'ArenaUserNotification'; - displayName: Scalars['String']; - id: Scalars['Int']; - profilePicture?: Maybe; - slug: Scalars['String']; - username: Scalars['String']; -}; - export type GQLArticle = { __typename?: 'Article'; articleType: Scalars['String']; @@ -1942,10 +1942,10 @@ export type GQLResolversTypes = { ArenaBreadcrumb: ResolverTypeWrapper; ArenaCategory: ResolverTypeWrapper; ArenaNotification: ResolverTypeWrapper; + ArenaNotificationUser: ResolverTypeWrapper; ArenaPost: ResolverTypeWrapper; ArenaTopic: ResolverTypeWrapper; ArenaUser: ResolverTypeWrapper; - ArenaUserNotification: ResolverTypeWrapper; Article: ResolverTypeWrapper; ArticleFolderResourceMeta: ResolverTypeWrapper; ArticleMetaData: ResolverTypeWrapper; @@ -1957,7 +1957,7 @@ export type GQLResolversTypes = { AudioLicense: ResolverTypeWrapper; AudioSearch: ResolverTypeWrapper; AudioSummary: ResolverTypeWrapper; - BaseUser: GQLResolversTypes['ArenaUser'] | GQLResolversTypes['ArenaUserNotification']; + BaseUser: GQLResolversTypes['ArenaNotificationUser'] | GQLResolversTypes['ArenaUser']; Boolean: ResolverTypeWrapper; Breadcrumb: ResolverTypeWrapper; BrightcoveCustomFields: ResolverTypeWrapper; @@ -2095,10 +2095,10 @@ export type GQLResolversParentTypes = { ArenaBreadcrumb: GQLArenaBreadcrumb; ArenaCategory: GQLArenaCategory; ArenaNotification: GQLArenaNotification; + ArenaNotificationUser: GQLArenaNotificationUser; ArenaPost: GQLArenaPost; ArenaTopic: GQLArenaTopic; ArenaUser: GQLArenaUser; - ArenaUserNotification: GQLArenaUserNotification; Article: GQLArticle; ArticleFolderResourceMeta: GQLArticleFolderResourceMeta; ArticleMetaData: GQLArticleMetaData; @@ -2110,7 +2110,7 @@ export type GQLResolversParentTypes = { AudioLicense: GQLAudioLicense; AudioSearch: GQLAudioSearch; AudioSummary: GQLAudioSummary; - BaseUser: GQLResolversParentTypes['ArenaUser'] | GQLResolversParentTypes['ArenaUserNotification']; + BaseUser: GQLResolversParentTypes['ArenaNotificationUser'] | GQLResolversParentTypes['ArenaUser']; Boolean: Scalars['Boolean']; Breadcrumb: GQLBreadcrumb; BrightcoveCustomFields: GQLBrightcoveCustomFields; @@ -2285,7 +2285,16 @@ export type GQLArenaNotificationResolvers; topicTitle?: Resolver; type?: Resolver; - user?: Resolver; + user?: Resolver; + __isTypeOf?: IsTypeOfResolverFn; +}; + +export type GQLArenaNotificationUserResolvers = { + displayName?: Resolver; + id?: Resolver; + profilePicture?: Resolver, ParentType, ContextType>; + slug?: Resolver; + username?: Resolver; __isTypeOf?: IsTypeOfResolverFn; }; @@ -2322,15 +2331,6 @@ export type GQLArenaUserResolvers; }; -export type GQLArenaUserNotificationResolvers = { - displayName?: Resolver; - id?: Resolver; - profilePicture?: Resolver, ParentType, ContextType>; - slug?: Resolver; - username?: Resolver; - __isTypeOf?: IsTypeOfResolverFn; -}; - export type GQLArticleResolvers = { articleType?: Resolver; availability?: Resolver, ParentType, ContextType>; @@ -2475,7 +2475,7 @@ export type GQLAudioSummaryResolvers = { - __resolveType: TypeResolveFn<'ArenaUser' | 'ArenaUserNotification', ParentType, ContextType>; + __resolveType: TypeResolveFn<'ArenaNotificationUser' | 'ArenaUser', ParentType, ContextType>; displayName?: Resolver; id?: Resolver; profilePicture?: Resolver, ParentType, ContextType>; @@ -3691,10 +3691,10 @@ export type GQLResolvers = { ArenaBreadcrumb?: GQLArenaBreadcrumbResolvers; ArenaCategory?: GQLArenaCategoryResolvers; ArenaNotification?: GQLArenaNotificationResolvers; + ArenaNotificationUser?: GQLArenaNotificationUserResolvers; ArenaPost?: GQLArenaPostResolvers; ArenaTopic?: GQLArenaTopicResolvers; ArenaUser?: GQLArenaUserResolvers; - ArenaUserNotification?: GQLArenaUserNotificationResolvers; Article?: GQLArticleResolvers; ArticleFolderResourceMeta?: GQLArticleFolderResourceMetaResolvers; ArticleMetaData?: GQLArticleMetaDataResolvers;