Skip to content

Commit

Permalink
Merge pull request #402 from NDLANO/single-arena-user-instead
Browse files Browse the repository at this point in the history
Single arena user instead
  • Loading branch information
MaPoKen authored Nov 29, 2023
2 parents b84bcdd + 9434384 commit 6f3ac9b
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 128 deletions.
24 changes: 4 additions & 20 deletions src/api/arenaApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@
import {
GQLArenaCategory,
GQLArenaNotification,
GQLArenaNotificationUser,
GQLArenaPost,
GQLArenaTopic,
GQLArenaUser,
GQLBaseUser,
GQLFullArenaUser,
GQLMutationNewArenaTopicArgs,
GQLMutationReplyToTopicArgs,
GQLQueryArenaCategoryArgs,
Expand All @@ -24,29 +21,16 @@ import {
} from '../types/schema';
import { fetch, resolveJson } from '../utils/apiHelpers';

const toBaseUser = (user: any): Omit<GQLBaseUser, '__typename'> => ({
const toArenaUser = (user: any): GQLArenaUser => ({
id: user.uid,
displayName: user.displayname,
username: user.username,
profilePicture: user.picture,
slug: user.userslug,
});

const toFullArenaUser = (user: any): GQLFullArenaUser => ({
...toBaseUser(user),
location: user.location,
groupTitleArray: user.groupTitleArray,
});

const toArenaUser = (user: any): GQLArenaUser => ({
...toBaseUser(user),
groupTitleArray: user.groupTitleArray,
});

const toArenaNotificationUser = (user: any): GQLArenaNotificationUser => ({
...toBaseUser(user),
});

const toArenaPost = (post: any, mainPid?: any): GQLArenaPost => ({
id: post.pid,
topicId: post.tid,
Expand Down Expand Up @@ -99,7 +83,7 @@ const toNotification = (notification: any): GQLArenaNotification => ({
importance: notification.importance,
path: notification.path,
read: notification.read,
user: toArenaNotificationUser(notification.user),
user: toArenaUser(notification.user),
readClass: notification.readClass,
image: notification.image,
topicTitle: notification.topicTitle,
Expand Down Expand Up @@ -137,13 +121,13 @@ export const fetchCsrfTokenForSession = async (
export const fetchArenaUser = async (
{ username }: GQLQueryArenaUserArgs,
context: Context,
): Promise<GQLFullArenaUser> => {
): Promise<GQLArenaUser> => {
const response = await fetch(
`/groups/api/user/username/${username}`,
context,
);
const resolved: any = await resolveJson(response);
return toFullArenaUser(resolved);
return toArenaUser(resolved);
};

export const fetchArenaCategories = async (
Expand Down
14 changes: 8 additions & 6 deletions src/resolvers/arenaResolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {
import {
GQLArenaCategory,
GQLArenaTopic,
GQLFullArenaUser,
GQLQueryArenaCategoryArgs,
GQLQueryArenaUserArgs,
GQLQueryArenaTopicArgs,
Expand All @@ -29,7 +28,10 @@ import {
GQLArenaNotification,
GQLMutationResolvers,
GQLMutationMarkNotificationAsReadArgs,
GQLMutationNewArenaTopicArgs,
GQLArenaPost,
GQLMutationReplyToTopicArgs,
GQLArenaUser,
} from '../types/schema';

export const Query: Pick<
Expand All @@ -46,7 +48,7 @@ export const Query: Pick<
_: any,
params: GQLQueryArenaUserArgs,
context: ContextWithLoaders,
): Promise<GQLFullArenaUser> {
): Promise<GQLArenaUser> {
return fetchArenaUser(params, context);
},
async arenaCategories(
Expand Down Expand Up @@ -99,17 +101,17 @@ export const Mutations: Pick<
> = {
async newArenaTopic(
_: any,
params,
params: GQLMutationNewArenaTopicArgs,
context: ContextWithLoaders,
): Promise<GQLArenaTopic> {
return newTopic(params, context);
return await newTopic(params, context);
},
async replyToTopic(
_: any,
params,
params: GQLMutationReplyToTopicArgs,
context: ContextWithLoaders,
): Promise<GQLArenaPost> {
return replyToTopic(params, context);
return await replyToTopic(params, context);
},
async markNotificationAsRead(
_: any,
Expand Down
33 changes: 4 additions & 29 deletions src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1192,39 +1192,14 @@ export const typeDefs = gql`
topics: [ArenaTopic!]
}
interface BaseUser {
type ArenaUser {
id: Int!
displayName: String!
username: String!
profilePicture: String
slug: String!
}
type FullArenaUser implements BaseUser {
id: Int!
displayName: String!
username: String!
groupTitleArray: [String!]
location: String
profilePicture: String
slug: String!
groupTitleArray: [String!]!
}
type ArenaUser implements BaseUser {
id: Int!
displayName: String!
username: String!
profilePicture: String
slug: String!
groupTitleArray: [String!]!
}
type ArenaNotificationUser implements BaseUser {
id: Int!
displayName: String!
username: String!
profilePicture: String
slug: String!
}
type ArenaPost {
Expand Down Expand Up @@ -1261,7 +1236,7 @@ export const typeDefs = gql`
importance: Int!
datetimeISO: String!
read: Boolean!
user: ArenaNotificationUser!
user: ArenaUser!
image: String
readClass: String!
postId: Int!
Expand Down Expand Up @@ -1402,7 +1377,7 @@ export const typeDefs = gql`
resourceEmbeds(resources: [ResourceEmbedInput!]!): ResourceEmbed!
arenaCategories: [ArenaCategory!]!
arenaCategory(categoryId: Int!, page: Int!): ArenaCategory
arenaUser(username: String!): FullArenaUser
arenaUser(username: String!): ArenaUser
arenaTopic(topicId: Int!, page: Int): ArenaTopic
arenaRecentTopics: [ArenaTopic!]!
arenaTopicsByUser(userSlug: String!): [ArenaTopic!]!
Expand Down
82 changes: 9 additions & 73 deletions src/types/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,7 @@ export type GQLArenaNotification = {
topicId: Scalars['Int'];
topicTitle: Scalars['String'];
type: Scalars['String'];
user: GQLArenaNotificationUser;
};

export type GQLArenaNotificationUser = GQLBaseUser & {
__typename?: 'ArenaNotificationUser';
displayName: Scalars['String'];
id: Scalars['Int'];
profilePicture?: Maybe<Scalars['String']>;
slug: Scalars['String'];
username: Scalars['String'];
user: GQLArenaUser;
};

export type GQLArenaPost = {
Expand All @@ -94,11 +85,12 @@ export type GQLArenaTopic = {
title: Scalars['String'];
};

export type GQLArenaUser = GQLBaseUser & {
export type GQLArenaUser = {
__typename?: 'ArenaUser';
displayName: Scalars['String'];
groupTitleArray: Array<Scalars['String']>;
groupTitleArray?: Maybe<Array<Scalars['String']>>;
id: Scalars['Int'];
location?: Maybe<Scalars['String']>;
profilePicture?: Maybe<Scalars['String']>;
slug: Scalars['String'];
username: Scalars['String'];
Expand Down Expand Up @@ -252,14 +244,6 @@ export type GQLAudioSummary = {
url: Scalars['String'];
};

export type GQLBaseUser = {
displayName: Scalars['String'];
id: Scalars['Int'];
profilePicture?: Maybe<Scalars['String']>;
slug: Scalars['String'];
username: Scalars['String'];
};

export type GQLBreadcrumb = {
__typename?: 'Breadcrumb';
id: Scalars['String'];
Expand Down Expand Up @@ -593,17 +577,6 @@ export type GQLFrontpageSearchResult = {
subject: Scalars['String'];
};

export type GQLFullArenaUser = GQLBaseUser & {
__typename?: 'FullArenaUser';
displayName: Scalars['String'];
groupTitleArray: Array<Scalars['String']>;
id: Scalars['Int'];
location?: Maybe<Scalars['String']>;
profilePicture?: Maybe<Scalars['String']>;
slug: Scalars['String'];
username: Scalars['String'];
};

export type GQLGloss = {
__typename?: 'Gloss';
examples?: Maybe<Array<Array<GQLExamples>>>;
Expand Down Expand Up @@ -1167,7 +1140,7 @@ export type GQLQuery = {
arenaRecentTopics: Array<GQLArenaTopic>;
arenaTopic?: Maybe<GQLArenaTopic>;
arenaTopicsByUser: Array<GQLArenaTopic>;
arenaUser?: Maybe<GQLFullArenaUser>;
arenaUser?: Maybe<GQLArenaUser>;
article?: Maybe<GQLArticle>;
articleResource?: Maybe<GQLResource>;
audio?: Maybe<GQLAudio>;
Expand Down Expand Up @@ -1955,7 +1928,6 @@ export type GQLResolversTypes = {
ArenaBreadcrumb: ResolverTypeWrapper<GQLArenaBreadcrumb>;
ArenaCategory: ResolverTypeWrapper<GQLArenaCategory>;
ArenaNotification: ResolverTypeWrapper<GQLArenaNotification>;
ArenaNotificationUser: ResolverTypeWrapper<GQLArenaNotificationUser>;
ArenaPost: ResolverTypeWrapper<GQLArenaPost>;
ArenaTopic: ResolverTypeWrapper<GQLArenaTopic>;
ArenaUser: ResolverTypeWrapper<GQLArenaUser>;
Expand All @@ -1970,7 +1942,6 @@ export type GQLResolversTypes = {
AudioLicense: ResolverTypeWrapper<GQLAudioLicense>;
AudioSearch: ResolverTypeWrapper<GQLAudioSearch>;
AudioSummary: ResolverTypeWrapper<GQLAudioSummary>;
BaseUser: GQLResolversTypes['ArenaNotificationUser'] | GQLResolversTypes['ArenaUser'] | GQLResolversTypes['FullArenaUser'];
Boolean: ResolverTypeWrapper<Scalars['Boolean']>;
Breadcrumb: ResolverTypeWrapper<GQLBreadcrumb>;
BrightcoveCustomFields: ResolverTypeWrapper<GQLBrightcoveCustomFields>;
Expand Down Expand Up @@ -2011,7 +1982,6 @@ export type GQLResolversTypes = {
FrontpageMenu: ResolverTypeWrapper<GQLFrontpageMenu>;
FrontpageSearch: ResolverTypeWrapper<GQLFrontpageSearch>;
FrontpageSearchResult: ResolverTypeWrapper<GQLFrontpageSearchResult>;
FullArenaUser: ResolverTypeWrapper<GQLFullArenaUser>;
Gloss: ResolverTypeWrapper<GQLGloss>;
GlossLicense: ResolverTypeWrapper<GQLGlossLicense>;
Grade: ResolverTypeWrapper<GQLGrade>;
Expand Down Expand Up @@ -2109,7 +2079,6 @@ export type GQLResolversParentTypes = {
ArenaBreadcrumb: GQLArenaBreadcrumb;
ArenaCategory: GQLArenaCategory;
ArenaNotification: GQLArenaNotification;
ArenaNotificationUser: GQLArenaNotificationUser;
ArenaPost: GQLArenaPost;
ArenaTopic: GQLArenaTopic;
ArenaUser: GQLArenaUser;
Expand All @@ -2124,7 +2093,6 @@ export type GQLResolversParentTypes = {
AudioLicense: GQLAudioLicense;
AudioSearch: GQLAudioSearch;
AudioSummary: GQLAudioSummary;
BaseUser: GQLResolversParentTypes['ArenaNotificationUser'] | GQLResolversParentTypes['ArenaUser'] | GQLResolversParentTypes['FullArenaUser'];
Boolean: Scalars['Boolean'];
Breadcrumb: GQLBreadcrumb;
BrightcoveCustomFields: GQLBrightcoveCustomFields;
Expand Down Expand Up @@ -2165,7 +2133,6 @@ export type GQLResolversParentTypes = {
FrontpageMenu: GQLFrontpageMenu;
FrontpageSearch: GQLFrontpageSearch;
FrontpageSearchResult: GQLFrontpageSearchResult;
FullArenaUser: GQLFullArenaUser;
Gloss: GQLGloss;
GlossLicense: GQLGlossLicense;
Grade: GQLGrade;
Expand Down Expand Up @@ -2300,16 +2267,7 @@ export type GQLArenaNotificationResolvers<ContextType = any, ParentType extends
topicId?: Resolver<GQLResolversTypes['Int'], ParentType, ContextType>;
topicTitle?: Resolver<GQLResolversTypes['String'], ParentType, ContextType>;
type?: Resolver<GQLResolversTypes['String'], ParentType, ContextType>;
user?: Resolver<GQLResolversTypes['ArenaNotificationUser'], ParentType, ContextType>;
__isTypeOf?: IsTypeOfResolverFn<ParentType, ContextType>;
};

export type GQLArenaNotificationUserResolvers<ContextType = any, ParentType extends GQLResolversParentTypes['ArenaNotificationUser'] = GQLResolversParentTypes['ArenaNotificationUser']> = {
displayName?: Resolver<GQLResolversTypes['String'], ParentType, ContextType>;
id?: Resolver<GQLResolversTypes['Int'], ParentType, ContextType>;
profilePicture?: Resolver<Maybe<GQLResolversTypes['String']>, ParentType, ContextType>;
slug?: Resolver<GQLResolversTypes['String'], ParentType, ContextType>;
username?: Resolver<GQLResolversTypes['String'], ParentType, ContextType>;
user?: Resolver<GQLResolversTypes['ArenaUser'], ParentType, ContextType>;
__isTypeOf?: IsTypeOfResolverFn<ParentType, ContextType>;
};

Expand Down Expand Up @@ -2338,8 +2296,9 @@ export type GQLArenaTopicResolvers<ContextType = any, ParentType extends GQLReso

export type GQLArenaUserResolvers<ContextType = any, ParentType extends GQLResolversParentTypes['ArenaUser'] = GQLResolversParentTypes['ArenaUser']> = {
displayName?: Resolver<GQLResolversTypes['String'], ParentType, ContextType>;
groupTitleArray?: Resolver<Array<GQLResolversTypes['String']>, ParentType, ContextType>;
groupTitleArray?: Resolver<Maybe<Array<GQLResolversTypes['String']>>, ParentType, ContextType>;
id?: Resolver<GQLResolversTypes['Int'], ParentType, ContextType>;
location?: Resolver<Maybe<GQLResolversTypes['String']>, ParentType, ContextType>;
profilePicture?: Resolver<Maybe<GQLResolversTypes['String']>, ParentType, ContextType>;
slug?: Resolver<GQLResolversTypes['String'], ParentType, ContextType>;
username?: Resolver<GQLResolversTypes['String'], ParentType, ContextType>;
Expand Down Expand Up @@ -2489,15 +2448,6 @@ export type GQLAudioSummaryResolvers<ContextType = any, ParentType extends GQLRe
__isTypeOf?: IsTypeOfResolverFn<ParentType, ContextType>;
};

export type GQLBaseUserResolvers<ContextType = any, ParentType extends GQLResolversParentTypes['BaseUser'] = GQLResolversParentTypes['BaseUser']> = {
__resolveType: TypeResolveFn<'ArenaNotificationUser' | 'ArenaUser' | 'FullArenaUser', ParentType, ContextType>;
displayName?: Resolver<GQLResolversTypes['String'], ParentType, ContextType>;
id?: Resolver<GQLResolversTypes['Int'], ParentType, ContextType>;
profilePicture?: Resolver<Maybe<GQLResolversTypes['String']>, ParentType, ContextType>;
slug?: Resolver<GQLResolversTypes['String'], ParentType, ContextType>;
username?: Resolver<GQLResolversTypes['String'], ParentType, ContextType>;
};

export type GQLBreadcrumbResolvers<ContextType = any, ParentType extends GQLResolversParentTypes['Breadcrumb'] = GQLResolversParentTypes['Breadcrumb']> = {
id?: Resolver<GQLResolversTypes['String'], ParentType, ContextType>;
name?: Resolver<GQLResolversTypes['String'], ParentType, ContextType>;
Expand Down Expand Up @@ -2826,17 +2776,6 @@ export type GQLFrontpageSearchResultResolvers<ContextType = any, ParentType exte
__isTypeOf?: IsTypeOfResolverFn<ParentType, ContextType>;
};

export type GQLFullArenaUserResolvers<ContextType = any, ParentType extends GQLResolversParentTypes['FullArenaUser'] = GQLResolversParentTypes['FullArenaUser']> = {
displayName?: Resolver<GQLResolversTypes['String'], ParentType, ContextType>;
groupTitleArray?: Resolver<Array<GQLResolversTypes['String']>, ParentType, ContextType>;
id?: Resolver<GQLResolversTypes['Int'], ParentType, ContextType>;
location?: Resolver<Maybe<GQLResolversTypes['String']>, ParentType, ContextType>;
profilePicture?: Resolver<Maybe<GQLResolversTypes['String']>, ParentType, ContextType>;
slug?: Resolver<GQLResolversTypes['String'], ParentType, ContextType>;
username?: Resolver<GQLResolversTypes['String'], ParentType, ContextType>;
__isTypeOf?: IsTypeOfResolverFn<ParentType, ContextType>;
};

export type GQLGlossResolvers<ContextType = any, ParentType extends GQLResolversParentTypes['Gloss'] = GQLResolversParentTypes['Gloss']> = {
examples?: Resolver<Maybe<Array<Array<GQLResolversTypes['Examples']>>>, ParentType, ContextType>;
gloss?: Resolver<GQLResolversTypes['String'], ParentType, ContextType>;
Expand Down Expand Up @@ -3299,7 +3238,7 @@ export type GQLQueryResolvers<ContextType = any, ParentType extends GQLResolvers
arenaRecentTopics?: Resolver<Array<GQLResolversTypes['ArenaTopic']>, ParentType, ContextType>;
arenaTopic?: Resolver<Maybe<GQLResolversTypes['ArenaTopic']>, ParentType, ContextType, RequireFields<GQLQueryArenaTopicArgs, 'topicId'>>;
arenaTopicsByUser?: Resolver<Array<GQLResolversTypes['ArenaTopic']>, ParentType, ContextType, RequireFields<GQLQueryArenaTopicsByUserArgs, 'userSlug'>>;
arenaUser?: Resolver<Maybe<GQLResolversTypes['FullArenaUser']>, ParentType, ContextType, RequireFields<GQLQueryArenaUserArgs, 'username'>>;
arenaUser?: Resolver<Maybe<GQLResolversTypes['ArenaUser']>, ParentType, ContextType, RequireFields<GQLQueryArenaUserArgs, 'username'>>;
article?: Resolver<Maybe<GQLResolversTypes['Article']>, ParentType, ContextType, RequireFields<GQLQueryArticleArgs, 'id'>>;
articleResource?: Resolver<Maybe<GQLResolversTypes['Resource']>, ParentType, ContextType, Partial<GQLQueryArticleResourceArgs>>;
audio?: Resolver<Maybe<GQLResolversTypes['Audio']>, ParentType, ContextType, RequireFields<GQLQueryAudioArgs, 'id'>>;
Expand Down Expand Up @@ -3719,7 +3658,6 @@ export type GQLResolvers<ContextType = any> = {
ArenaBreadcrumb?: GQLArenaBreadcrumbResolvers<ContextType>;
ArenaCategory?: GQLArenaCategoryResolvers<ContextType>;
ArenaNotification?: GQLArenaNotificationResolvers<ContextType>;
ArenaNotificationUser?: GQLArenaNotificationUserResolvers<ContextType>;
ArenaPost?: GQLArenaPostResolvers<ContextType>;
ArenaTopic?: GQLArenaTopicResolvers<ContextType>;
ArenaUser?: GQLArenaUserResolvers<ContextType>;
Expand All @@ -3734,7 +3672,6 @@ export type GQLResolvers<ContextType = any> = {
AudioLicense?: GQLAudioLicenseResolvers<ContextType>;
AudioSearch?: GQLAudioSearchResolvers<ContextType>;
AudioSummary?: GQLAudioSummaryResolvers<ContextType>;
BaseUser?: GQLBaseUserResolvers<ContextType>;
Breadcrumb?: GQLBreadcrumbResolvers<ContextType>;
BrightcoveCustomFields?: GQLBrightcoveCustomFieldsResolvers<ContextType>;
BrightcoveElement?: GQLBrightcoveElementResolvers<ContextType>;
Expand Down Expand Up @@ -3772,7 +3709,6 @@ export type GQLResolvers<ContextType = any> = {
FrontpageMenu?: GQLFrontpageMenuResolvers<ContextType>;
FrontpageSearch?: GQLFrontpageSearchResolvers<ContextType>;
FrontpageSearchResult?: GQLFrontpageSearchResultResolvers<ContextType>;
FullArenaUser?: GQLFullArenaUserResolvers<ContextType>;
Gloss?: GQLGlossResolvers<ContextType>;
GlossLicense?: GQLGlossLicenseResolvers<ContextType>;
Grade?: GQLGradeResolvers<ContextType>;
Expand Down

0 comments on commit 6f3ac9b

Please sign in to comment.