Skip to content

Commit

Permalink
Merge pull request #396 from NDLANO/add-location-from-api
Browse files Browse the repository at this point in the history
Henter FullUser.
  • Loading branch information
gunnarvelle authored Nov 28, 2023
2 parents 8924923 + f803254 commit b84bcdd
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 11 deletions.
11 changes: 9 additions & 2 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 @@ -31,6 +32,12 @@ const toBaseUser = (user: any): Omit<GQLBaseUser, '__typename'> => ({
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 @@ -130,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
12 changes: 11 additions & 1 deletion src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1200,6 +1200,16 @@ export const typeDefs = gql`
slug: String!
}
type FullArenaUser implements BaseUser {
id: Int!
displayName: String!
username: String!
location: String
profilePicture: String
slug: String!
groupTitleArray: [String!]!
}
type ArenaUser implements BaseUser {
id: Int!
displayName: String!
Expand Down Expand Up @@ -1392,7 +1402,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
35 changes: 30 additions & 5 deletions src/types/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,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 +1167,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 +1970,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 +2011,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 +2124,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 +2165,7 @@ export type GQLResolversParentTypes = {
FrontpageMenu: GQLFrontpageMenu;
FrontpageSearch: GQLFrontpageSearch;
FrontpageSearchResult: GQLFrontpageSearchResult;
FullArenaUser: GQLFullArenaUser;
Gloss: GQLGloss;
GlossLicense: GQLGlossLicense;
Grade: GQLGrade;
Expand Down Expand Up @@ -2477,7 +2490,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 +2826,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 +3299,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 +3772,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 b84bcdd

Please sign in to comment.