Skip to content

Commit

Permalink
Add extended user
Browse files Browse the repository at this point in the history
  • Loading branch information
gunnarvelle committed Nov 28, 2023
1 parent e793642 commit f803254
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 17 deletions.
12 changes: 9 additions & 3 deletions src/api/arenaApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
GQLArenaTopic,
GQLArenaUser,
GQLBaseUser,
GQLFullArenaUser,
GQLMutationNewArenaTopicArgs,
GQLMutationReplyToTopicArgs,
GQLQueryArenaCategoryArgs,
Expand All @@ -27,11 +28,16 @@ const toBaseUser = (user: any): Omit<GQLBaseUser, '__typename'> => ({
id: user.uid,
displayName: user.displayname,
username: user.username,
location: user.location,
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,
Expand Down Expand Up @@ -131,13 +137,13 @@ export const fetchCsrfTokenForSession = async (
export const fetchArenaUser = async (
{ username }: GQLQueryArenaUserArgs,
context: Context,
): Promise<GQLArenaUser> => {
): Promise<GQLFullArenaUser> => {
const response = await fetch(
`/groups/api/user/username/${username}`,
context,
);
const resolved: any = await resolveJson(response);
return toArenaUser(resolved);
return toFullArenaUser(resolved);
};

export const fetchArenaCategories = async (
Expand Down
5 changes: 2 additions & 3 deletions src/resolvers/arenaResolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@ import {
fetchArenaTopic,
fetchArenaTopicsByUser,
fetchArenaNotifications,
fetchCsrfTokenForSession,
newTopic,
replyToTopic,
} from '../api/arenaApi';
import {
GQLArenaCategory,
GQLArenaUser,
GQLArenaTopic,
GQLFullArenaUser,
GQLQueryArenaCategoryArgs,
GQLQueryArenaUserArgs,
GQLQueryArenaTopicArgs,
Expand All @@ -47,7 +46,7 @@ export const Query: Pick<
_: any,
params: GQLQueryArenaUserArgs,
context: ContextWithLoaders,
): Promise<GQLArenaUser> {
): Promise<GQLFullArenaUser> {
return fetchArenaUser(params, context);
},
async arenaCategories(
Expand Down
2 changes: 0 additions & 2 deletions src/resolvers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ import {

import {
Query as ArenaQuery,
resolvers as ArenaResolvers,
Mutations as ArenaMutations,
} from './arenaResolvers';

Expand Down Expand Up @@ -113,7 +112,6 @@ export const resolvers = {
...uptimeResolvers,
...ImageResolvers,
...ProgrammeResolvers,
...ArenaResolvers,
TaxonomyEntity: {
// Resolves TaxonomyEntity interface
__resolveType(entity: any) {
Expand Down
13 changes: 11 additions & 2 deletions src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1199,7 +1199,7 @@ export const typeDefs = gql`
slug: String!
}
type ArenaUser implements BaseUser {
type FullArenaUser implements BaseUser {
id: Int!
displayName: String!
username: String!
Expand All @@ -1209,6 +1209,15 @@ export const typeDefs = gql`
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!
Expand Down Expand Up @@ -1392,7 +1401,7 @@ export const typeDefs = gql`
resourceEmbeds(resources: [ResourceEmbedInput!]!): ResourceEmbed!
arenaCategories: [ArenaCategory!]!
arenaCategory(categoryId: Int!, page: Int!): ArenaCategory
arenaUser(username: String!): ArenaUser
arenaUser(username: String!): FullArenaUser
arenaTopic(topicId: Int!, page: Int): ArenaTopic
arenaRecentTopics: [ArenaTopic!]!
arenaTopicsByUser(userSlug: String!): [ArenaTopic!]!
Expand Down
37 changes: 30 additions & 7 deletions src/types/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ export type GQLArenaUser = GQLBaseUser & {
displayName: Scalars['String'];
groupTitleArray: Array<Scalars['String']>;
id: Scalars['Int'];
location?: Maybe<Scalars['String']>;
profilePicture?: Maybe<Scalars['String']>;
slug: Scalars['String'];
username: Scalars['String'];
Expand Down Expand Up @@ -593,6 +592,17 @@ 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 @@ -1156,7 +1166,7 @@ export type GQLQuery = {
arenaRecentTopics: Array<GQLArenaTopic>;
arenaTopic?: Maybe<GQLArenaTopic>;
arenaTopicsByUser: Array<GQLArenaTopic>;
arenaUser?: Maybe<GQLArenaUser>;
arenaUser?: Maybe<GQLFullArenaUser>;
article?: Maybe<GQLArticle>;
articleResource?: Maybe<GQLResource>;
audio?: Maybe<GQLAudio>;
Expand Down Expand Up @@ -1959,7 +1969,7 @@ export type GQLResolversTypes = {
AudioLicense: ResolverTypeWrapper<GQLAudioLicense>;
AudioSearch: ResolverTypeWrapper<GQLAudioSearch>;
AudioSummary: ResolverTypeWrapper<GQLAudioSummary>;
BaseUser: GQLResolversTypes['ArenaNotificationUser'] | GQLResolversTypes['ArenaUser'];
BaseUser: GQLResolversTypes['ArenaNotificationUser'] | GQLResolversTypes['ArenaUser'] | GQLResolversTypes['FullArenaUser'];
Boolean: ResolverTypeWrapper<Scalars['Boolean']>;
Breadcrumb: ResolverTypeWrapper<GQLBreadcrumb>;
BrightcoveCustomFields: ResolverTypeWrapper<GQLBrightcoveCustomFields>;
Expand Down Expand Up @@ -2000,6 +2010,7 @@ 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 @@ -2112,7 +2123,7 @@ export type GQLResolversParentTypes = {
AudioLicense: GQLAudioLicense;
AudioSearch: GQLAudioSearch;
AudioSummary: GQLAudioSummary;
BaseUser: GQLResolversParentTypes['ArenaNotificationUser'] | GQLResolversParentTypes['ArenaUser'];
BaseUser: GQLResolversParentTypes['ArenaNotificationUser'] | GQLResolversParentTypes['ArenaUser'] | GQLResolversParentTypes['FullArenaUser'];
Boolean: Scalars['Boolean'];
Breadcrumb: GQLBreadcrumb;
BrightcoveCustomFields: GQLBrightcoveCustomFields;
Expand Down Expand Up @@ -2153,6 +2164,7 @@ export type GQLResolversParentTypes = {
FrontpageMenu: GQLFrontpageMenu;
FrontpageSearch: GQLFrontpageSearch;
FrontpageSearchResult: GQLFrontpageSearchResult;
FullArenaUser: GQLFullArenaUser;
Gloss: GQLGloss;
GlossLicense: GQLGlossLicense;
Grade: GQLGrade;
Expand Down Expand Up @@ -2327,7 +2339,6 @@ export type GQLArenaUserResolvers<ContextType = any, ParentType extends GQLResol
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>;
Expand Down Expand Up @@ -2478,7 +2489,7 @@ export type GQLAudioSummaryResolvers<ContextType = any, ParentType extends GQLRe
};

export type GQLBaseUserResolvers<ContextType = any, ParentType extends GQLResolversParentTypes['BaseUser'] = GQLResolversParentTypes['BaseUser']> = {
__resolveType: TypeResolveFn<'ArenaNotificationUser' | 'ArenaUser', ParentType, ContextType>;
__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>;
Expand Down Expand Up @@ -2813,6 +2824,17 @@ 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 @@ -3275,7 +3297,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['ArenaUser']>, ParentType, ContextType, RequireFields<GQLQueryArenaUserArgs, 'username'>>;
arenaUser?: Resolver<Maybe<GQLResolversTypes['FullArenaUser']>, 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 @@ -3748,6 +3770,7 @@ 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 f803254

Please sign in to comment.