Skip to content

Commit

Permalink
Merge branch 'master' of github.com:NDLANO/graphql-api into create_fl…
Browse files Browse the repository at this point in the history
…ag_arena
  • Loading branch information
katrinewi committed Nov 29, 2023
2 parents cce467c + 13731e5 commit e56ba86
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 102 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@
"@graphql-codegen/typescript-operations": "^2.5.6",
"@graphql-codegen/typescript-resolvers": "^2.7.6",
"@graphql-eslint/eslint-plugin": "^3.12.0",
"@ndla/types-backend": "^0.2.29",
"@ndla/types-backend": "^0.2.30",
"@ndla/types-embed": "^4.0.7",
"@ndla/types-taxonomy": "^1.0.19",
"@ndla/types-taxonomy": "^1.0.21",
"@types/bunyan": "^1.8.5",
"@types/compression": "^1.7.2",
"@types/cors": "^2.8.4",
Expand Down
15 changes: 3 additions & 12 deletions src/api/arenaApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@ import { GraphQLError } from 'graphql';
import {
GQLArenaCategory,
GQLArenaNotification,
GQLArenaNotificationUser,
GQLArenaPost,
GQLArenaTopic,
GQLArenaUser,
GQLBaseUser,
GQLMutationNewArenaTopicArgs,
GQLMutationNewFlagArgs,
GQLMutationReplyToTopicArgs,
Expand All @@ -25,23 +23,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 toArenaUser = (user: any): GQLArenaUser => ({
...toBaseUser(user),
location: user.location,
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 @@ -95,7 +86,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
18 changes: 12 additions & 6 deletions src/api/folderApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,18 @@ export async function deletePersonalData(context: Context): Promise<boolean> {
}
}

export async function getPersonalData(context: Context): Promise<IMyNDLAUser> {
const response = await fetch(`/learningpath-api/v1/users/`, {
...context,
shouldUseCache: false,
});
return await resolveJson(response);
export async function getPersonalData(
context: Context,
): Promise<IMyNDLAUser | undefined> {
try {
const response = await fetch(`/learningpath-api/v1/users/`, {
...context,
shouldUseCache: false,
});
return await resolveJson(response);
} catch (e) {
return undefined;
}
}

export async function patchPersonalData(
Expand Down
12 changes: 7 additions & 5 deletions src/resolvers/arenaResolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {
} from '../api/arenaApi';
import {
GQLArenaCategory,
GQLArenaUser,
GQLArenaTopic,
GQLQueryArenaCategoryArgs,
GQLQueryArenaUserArgs,
Expand All @@ -30,7 +29,10 @@ import {
GQLArenaNotification,
GQLMutationResolvers,
GQLMutationMarkNotificationAsReadArgs,
GQLMutationNewArenaTopicArgs,
GQLArenaPost,
GQLMutationReplyToTopicArgs,
GQLArenaUser,
} from '../types/schema';

export const Query: Pick<
Expand Down Expand Up @@ -100,17 +102,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
2 changes: 1 addition & 1 deletion src/resolvers/folderResolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export const Query: Pick<
__: any,
context: ContextWithLoaders,
): Promise<GQLMyNdlaPersonalData> {
return getPersonalData(context);
return (getPersonalData(context) as unknown) as GQLMyNdlaPersonalData;
},
};

Expand Down
19 changes: 19 additions & 0 deletions src/resolvers/frontpageResolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,23 @@ export const resolvers = {
return nodes[0]?.resourceTypes ?? [];
},
},

FilmFrontpage: {
async article(
frontpage: IFilmFrontPageData,
_: any,
context: ContextWithLoaders,
): Promise<GQLArticle | undefined> {
if (frontpage.article) {
return fetchArticle(
{
articleId: `${getArticleIdFromUrn(frontpage.article)}`,
convertEmbeds: true,
},
context,
);
}
return undefined;
},
},
};
39 changes: 19 additions & 20 deletions src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,7 @@ export const typeDefs = gql`
about: [FilmPageAbout!]!
movieThemes: [MovieTheme!]!
slideShow: [Movie!]!
article: Article
}
type MovieTheme {
Expand Down Expand Up @@ -1009,6 +1010,7 @@ export const typeDefs = gql`
resources: [FolderResource!]!
created: String!
updated: String!
owner: Owner
}
type Owner {
Expand Down Expand Up @@ -1138,13 +1140,25 @@ export const typeDefs = gql`
parentId: String
}
type MyNdlaGroup {
id: String!
displayName: String!
isPrimarySchool: Boolean!
parentId: String
}
type MyNdlaPersonalData {
id: Int!
feideId: String!
username: String!
email: String!
displayName: String!
favoriteSubjects: [String!]!
role: String!
arenaEnabled: Boolean!
shareName: Boolean!
organization: String!
groups: [MyNdlaGroup!]!
}
type ConfigMetaBoolean {
Expand Down Expand Up @@ -1190,29 +1204,14 @@ export const typeDefs = gql`
topics: [ArenaTopic!]
}
interface BaseUser {
id: Int!
displayName: String!
username: String!
profilePicture: String
slug: String!
}
type ArenaUser implements BaseUser {
id: Int!
displayName: String!
username: String!
profilePicture: String
slug: String!
groupTitleArray: [String!]!
}
type ArenaNotificationUser implements BaseUser {
type ArenaUser {
id: Int!
displayName: String!
username: String!
profilePicture: String
slug: String!
groupTitleArray: [String!]
location: String
}
type ArenaPost {
Expand Down Expand Up @@ -1250,7 +1249,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 @@ -1382,7 +1381,7 @@ export const typeDefs = gql`
includeResources: Boolean
): SharedFolder!
allFolderResources(size: Int): [FolderResource!]!
personalData: MyNdlaPersonalData!
personalData: MyNdlaPersonalData
image(id: String!): ImageMetaInformationV2
examLockStatus: ConfigMetaBoolean!
aiEnabledOrgs: ConfigMetaStringList
Expand Down
Loading

0 comments on commit e56ba86

Please sign in to comment.