diff --git a/package.json b/package.json index 42f789b5..effc1219 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/api/arenaApi.ts b/src/api/arenaApi.ts index 549c15e3..9f855a71 100644 --- a/src/api/arenaApi.ts +++ b/src/api/arenaApi.ts @@ -10,11 +10,9 @@ import { GraphQLError } from 'graphql'; import { GQLArenaCategory, GQLArenaNotification, - GQLArenaNotificationUser, GQLArenaPost, GQLArenaTopic, GQLArenaUser, - GQLBaseUser, GQLMutationNewArenaTopicArgs, GQLMutationNewFlagArgs, GQLMutationReplyToTopicArgs, @@ -25,23 +23,16 @@ import { } from '../types/schema'; import { fetch, resolveJson } from '../utils/apiHelpers'; -const toBaseUser = (user: any): Omit => ({ +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, @@ -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, diff --git a/src/api/folderApi.ts b/src/api/folderApi.ts index 05048e00..6f2d3ba2 100644 --- a/src/api/folderApi.ts +++ b/src/api/folderApi.ts @@ -201,12 +201,18 @@ export async function deletePersonalData(context: Context): Promise { } } -export async function getPersonalData(context: Context): Promise { - const response = await fetch(`/learningpath-api/v1/users/`, { - ...context, - shouldUseCache: false, - }); - return await resolveJson(response); +export async function getPersonalData( + context: Context, +): Promise { + try { + const response = await fetch(`/learningpath-api/v1/users/`, { + ...context, + shouldUseCache: false, + }); + return await resolveJson(response); + } catch (e) { + return undefined; + } } export async function patchPersonalData( diff --git a/src/resolvers/arenaResolvers.ts b/src/resolvers/arenaResolvers.ts index 958d6699..b7de4575 100644 --- a/src/resolvers/arenaResolvers.ts +++ b/src/resolvers/arenaResolvers.ts @@ -20,7 +20,6 @@ import { } from '../api/arenaApi'; import { GQLArenaCategory, - GQLArenaUser, GQLArenaTopic, GQLQueryArenaCategoryArgs, GQLQueryArenaUserArgs, @@ -30,7 +29,10 @@ import { GQLArenaNotification, GQLMutationResolvers, GQLMutationMarkNotificationAsReadArgs, + GQLMutationNewArenaTopicArgs, GQLArenaPost, + GQLMutationReplyToTopicArgs, + GQLArenaUser, } from '../types/schema'; export const Query: Pick< @@ -100,17 +102,17 @@ export const Mutations: Pick< > = { async newArenaTopic( _: any, - params, + params: GQLMutationNewArenaTopicArgs, context: ContextWithLoaders, ): Promise { - return newTopic(params, context); + return await newTopic(params, context); }, async replyToTopic( _: any, - params, + params: GQLMutationReplyToTopicArgs, context: ContextWithLoaders, ): Promise { - return replyToTopic(params, context); + return await replyToTopic(params, context); }, async markNotificationAsRead( _: any, diff --git a/src/resolvers/folderResolvers.ts b/src/resolvers/folderResolvers.ts index 585e4f8b..f8d8b40f 100644 --- a/src/resolvers/folderResolvers.ts +++ b/src/resolvers/folderResolvers.ts @@ -111,7 +111,7 @@ export const Query: Pick< __: any, context: ContextWithLoaders, ): Promise { - return getPersonalData(context); + return (getPersonalData(context) as unknown) as GQLMyNdlaPersonalData; }, }; diff --git a/src/resolvers/frontpageResolvers.ts b/src/resolvers/frontpageResolvers.ts index f8246fb2..432957e5 100644 --- a/src/resolvers/frontpageResolvers.ts +++ b/src/resolvers/frontpageResolvers.ts @@ -142,4 +142,23 @@ export const resolvers = { return nodes[0]?.resourceTypes ?? []; }, }, + + FilmFrontpage: { + async article( + frontpage: IFilmFrontPageData, + _: any, + context: ContextWithLoaders, + ): Promise { + if (frontpage.article) { + return fetchArticle( + { + articleId: `${getArticleIdFromUrn(frontpage.article)}`, + convertEmbeds: true, + }, + context, + ); + } + return undefined; + }, + }, }; diff --git a/src/schema.ts b/src/schema.ts index a6ba8ca5..40d7b340 100644 --- a/src/schema.ts +++ b/src/schema.ts @@ -640,6 +640,7 @@ export const typeDefs = gql` about: [FilmPageAbout!]! movieThemes: [MovieTheme!]! slideShow: [Movie!]! + article: Article } type MovieTheme { @@ -1009,6 +1010,7 @@ export const typeDefs = gql` resources: [FolderResource!]! created: String! updated: String! + owner: Owner } type Owner { @@ -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 { @@ -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 { @@ -1250,7 +1249,7 @@ export const typeDefs = gql` importance: Int! datetimeISO: String! read: Boolean! - user: ArenaNotificationUser! + user: ArenaUser! image: String readClass: String! postId: Int! @@ -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 diff --git a/src/types/schema.d.ts b/src/types/schema.d.ts index 7cc71c81..0c4d3d7b 100644 --- a/src/types/schema.d.ts +++ b/src/types/schema.d.ts @@ -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; - slug: Scalars['String']; - username: Scalars['String']; + user: GQLArenaUser; }; export type GQLArenaPost = { @@ -95,11 +86,12 @@ export type GQLArenaTopic = { title: Scalars['String']; }; -export type GQLArenaUser = GQLBaseUser & { +export type GQLArenaUser = { __typename?: 'ArenaUser'; displayName: Scalars['String']; - groupTitleArray: Array; + groupTitleArray?: Maybe>; id: Scalars['Int']; + location?: Maybe; profilePicture?: Maybe; slug: Scalars['String']; username: Scalars['String']; @@ -253,14 +245,6 @@ 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']; @@ -494,6 +478,7 @@ export type GQLExamples = { export type GQLFilmFrontpage = { __typename?: 'FilmFrontpage'; about: Array; + article?: Maybe; movieThemes: Array; name: Scalars['String']; slideShow: Array; @@ -514,6 +499,7 @@ export type GQLFolder = { description?: Maybe; id: Scalars['String']; name: Scalars['String']; + owner?: Maybe; parentId?: Maybe; resources: Array; status: Scalars['String']; @@ -1033,14 +1019,27 @@ export type GQLMutationUpdatePersonalDataArgs = { shareName?: InputMaybe; }; +export type GQLMyNdlaGroup = { + __typename?: 'MyNdlaGroup'; + displayName: Scalars['String']; + id: Scalars['String']; + isPrimarySchool: Scalars['Boolean']; + parentId?: Maybe; +}; + export type GQLMyNdlaPersonalData = { __typename?: 'MyNdlaPersonalData'; arenaEnabled: Scalars['Boolean']; + displayName: Scalars['String']; + email: Scalars['String']; favoriteSubjects: Array; + feideId: Scalars['String']; + groups: Array; id: Scalars['Int']; organization: Scalars['String']; role: Scalars['String']; shareName: Scalars['Boolean']; + username: Scalars['String']; }; export type GQLName = { @@ -1185,7 +1184,7 @@ export type GQLQuery = { image?: Maybe; learningpath?: Maybe; listingPage?: Maybe; - personalData: GQLMyNdlaPersonalData; + personalData?: Maybe; podcastSearch?: Maybe; podcastSeries?: Maybe; podcastSeriesSearch?: Maybe; @@ -1951,7 +1950,6 @@ export type GQLResolversTypes = { ArenaBreadcrumb: ResolverTypeWrapper; ArenaCategory: ResolverTypeWrapper; ArenaNotification: ResolverTypeWrapper; - ArenaNotificationUser: ResolverTypeWrapper; ArenaPost: ResolverTypeWrapper; ArenaTopic: ResolverTypeWrapper; ArenaUser: ResolverTypeWrapper; @@ -1966,7 +1964,6 @@ export type GQLResolversTypes = { AudioLicense: ResolverTypeWrapper; AudioSearch: ResolverTypeWrapper; AudioSummary: ResolverTypeWrapper; - BaseUser: GQLResolversTypes['ArenaNotificationUser'] | GQLResolversTypes['ArenaUser']; Boolean: ResolverTypeWrapper; Breadcrumb: ResolverTypeWrapper; BrightcoveCustomFields: ResolverTypeWrapper; @@ -2041,6 +2038,7 @@ export type GQLResolversTypes = { MovieResourceTypes: ResolverTypeWrapper; MovieTheme: ResolverTypeWrapper; Mutation: ResolverTypeWrapper<{}>; + MyNdlaGroup: ResolverTypeWrapper; MyNdlaPersonalData: ResolverTypeWrapper; Name: ResolverTypeWrapper; NewFolder: ResolverTypeWrapper; @@ -2104,7 +2102,6 @@ export type GQLResolversParentTypes = { ArenaBreadcrumb: GQLArenaBreadcrumb; ArenaCategory: GQLArenaCategory; ArenaNotification: GQLArenaNotification; - ArenaNotificationUser: GQLArenaNotificationUser; ArenaPost: GQLArenaPost; ArenaTopic: GQLArenaTopic; ArenaUser: GQLArenaUser; @@ -2119,7 +2116,6 @@ export type GQLResolversParentTypes = { AudioLicense: GQLAudioLicense; AudioSearch: GQLAudioSearch; AudioSummary: GQLAudioSummary; - BaseUser: GQLResolversParentTypes['ArenaNotificationUser'] | GQLResolversParentTypes['ArenaUser']; Boolean: Scalars['Boolean']; Breadcrumb: GQLBreadcrumb; BrightcoveCustomFields: GQLBrightcoveCustomFields; @@ -2194,6 +2190,7 @@ export type GQLResolversParentTypes = { MovieResourceTypes: GQLMovieResourceTypes; MovieTheme: GQLMovieTheme; Mutation: {}; + MyNdlaGroup: GQLMyNdlaGroup; MyNdlaPersonalData: GQLMyNdlaPersonalData; Name: GQLName; NewFolder: GQLNewFolder; @@ -2294,16 +2291,7 @@ export type GQLArenaNotificationResolvers; topicTitle?: Resolver; type?: Resolver; - user?: Resolver; - __isTypeOf?: IsTypeOfResolverFn; -}; - -export type GQLArenaNotificationUserResolvers = { - displayName?: Resolver; - id?: Resolver; - profilePicture?: Resolver, ParentType, ContextType>; - slug?: Resolver; - username?: Resolver; + user?: Resolver; __isTypeOf?: IsTypeOfResolverFn; }; @@ -2333,8 +2321,9 @@ export type GQLArenaTopicResolvers = { displayName?: Resolver; - groupTitleArray?: Resolver, ParentType, ContextType>; + groupTitleArray?: Resolver>, ParentType, ContextType>; id?: Resolver; + location?: Resolver, ParentType, ContextType>; profilePicture?: Resolver, ParentType, ContextType>; slug?: Resolver; username?: Resolver; @@ -2484,15 +2473,6 @@ export type GQLAudioSummaryResolvers; }; -export type GQLBaseUserResolvers = { - __resolveType: TypeResolveFn<'ArenaNotificationUser' | 'ArenaUser', ParentType, ContextType>; - displayName?: Resolver; - id?: Resolver; - profilePicture?: Resolver, ParentType, ContextType>; - slug?: Resolver; - username?: Resolver; -}; - export type GQLBreadcrumbResolvers = { id?: Resolver; name?: Resolver; @@ -2725,6 +2705,7 @@ export type GQLExamplesResolvers = { about?: Resolver, ParentType, ContextType>; + article?: Resolver, ParentType, ContextType>; movieThemes?: Resolver, ParentType, ContextType>; name?: Resolver; slideShow?: Resolver, ParentType, ContextType>; @@ -2745,6 +2726,7 @@ export type GQLFolderResolvers, ParentType, ContextType>; id?: Resolver; name?: Resolver; + owner?: Resolver, ParentType, ContextType>; parentId?: Resolver, ParentType, ContextType>; resources?: Resolver, ParentType, ContextType>; status?: Resolver; @@ -3152,13 +3134,26 @@ export type GQLMutationResolvers>; }; +export type GQLMyNdlaGroupResolvers = { + displayName?: Resolver; + id?: Resolver; + isPrimarySchool?: Resolver; + parentId?: Resolver, ParentType, ContextType>; + __isTypeOf?: IsTypeOfResolverFn; +}; + export type GQLMyNdlaPersonalDataResolvers = { arenaEnabled?: Resolver; + displayName?: Resolver; + email?: Resolver; favoriteSubjects?: Resolver, ParentType, ContextType>; + feideId?: Resolver; + groups?: Resolver, ParentType, ContextType>; id?: Resolver; organization?: Resolver; role?: Resolver; shareName?: Resolver; + username?: Resolver; __isTypeOf?: IsTypeOfResolverFn; }; @@ -3304,7 +3299,7 @@ export type GQLQueryResolvers, ParentType, ContextType, RequireFields>; learningpath?: Resolver, ParentType, ContextType, RequireFields>; listingPage?: Resolver, ParentType, ContextType, Partial>; - personalData?: Resolver; + personalData?: Resolver, ParentType, ContextType>; podcastSearch?: Resolver, ParentType, ContextType, RequireFields>; podcastSeries?: Resolver, ParentType, ContextType, RequireFields>; podcastSeriesSearch?: Resolver, ParentType, ContextType, RequireFields>; @@ -3702,7 +3697,6 @@ export type GQLResolvers = { ArenaBreadcrumb?: GQLArenaBreadcrumbResolvers; ArenaCategory?: GQLArenaCategoryResolvers; ArenaNotification?: GQLArenaNotificationResolvers; - ArenaNotificationUser?: GQLArenaNotificationUserResolvers; ArenaPost?: GQLArenaPostResolvers; ArenaTopic?: GQLArenaTopicResolvers; ArenaUser?: GQLArenaUserResolvers; @@ -3717,7 +3711,6 @@ export type GQLResolvers = { AudioLicense?: GQLAudioLicenseResolvers; AudioSearch?: GQLAudioSearchResolvers; AudioSummary?: GQLAudioSummaryResolvers; - BaseUser?: GQLBaseUserResolvers; Breadcrumb?: GQLBreadcrumbResolvers; BrightcoveCustomFields?: GQLBrightcoveCustomFieldsResolvers; BrightcoveElement?: GQLBrightcoveElementResolvers; @@ -3788,6 +3781,7 @@ export type GQLResolvers = { MovieResourceTypes?: GQLMovieResourceTypesResolvers; MovieTheme?: GQLMovieThemeResolvers; Mutation?: GQLMutationResolvers; + MyNdlaGroup?: GQLMyNdlaGroupResolvers; MyNdlaPersonalData?: GQLMyNdlaPersonalDataResolvers; Name?: GQLNameResolvers; NewFolder?: GQLNewFolderResolvers; diff --git a/yarn.lock b/yarn.lock index fd48c3ca..36bf44e3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1506,20 +1506,20 @@ resolved "https://registry.yarnpkg.com/@ndla/licenses/-/licenses-7.2.2.tgz#5b165694638acac7a431266b9ece3751a6497578" integrity sha512-DGMdoa/5QGdnZcOLLL3tbC95dEc+YWhjavtj6aRoeCbl4vsTX1nzMY4ZsdbiDxtZsnlcASouvG5ffYTbCW3s0Q== -"@ndla/types-backend@^0.2.29": - version "0.2.29" - resolved "https://registry.yarnpkg.com/@ndla/types-backend/-/types-backend-0.2.29.tgz#0c6b611f701b077bb427297395069959a6bbda23" - integrity sha512-VkPoyNMi9wLHZb8ikHCdYKz7xc3TbNqHqvz9/lgjlL+pTZCSsvXpPnix/E3FnZGf9jq+SCfZGqkbvBJR4e2gQA== +"@ndla/types-backend@^0.2.30": + version "0.2.30" + resolved "https://registry.yarnpkg.com/@ndla/types-backend/-/types-backend-0.2.30.tgz#048d8f7a292602f3cf1852c29c6e3f8187c48da3" + integrity sha512-lJStzANa90o5INue8TlCKzw9e/b0bgeD5vs4zDii+3rAnfIogTd5jBQEqsyqbfu+MynJdYG+oBVx5EZMZjNStg== "@ndla/types-embed@^4.0.7": version "4.0.7" resolved "https://registry.yarnpkg.com/@ndla/types-embed/-/types-embed-4.0.7.tgz#6dd6d4eb17db22e8ee6d4182888cd18fef29624d" integrity sha512-PduZNoLAegJk8DnseqYzZ0+P3J20ol4lx1qcMlgn61YbWHwRC8oEKkL85zHkv+EkqCf8tRgJfVG5YcTh+jfBzQ== -"@ndla/types-taxonomy@^1.0.19": - version "1.0.19" - resolved "https://registry.yarnpkg.com/@ndla/types-taxonomy/-/types-taxonomy-1.0.19.tgz#9fdfd8a5934a9108421f0b30f8f4a135a5fa7642" - integrity sha512-F0rN7OWD7iUnJv8F/R9ZMW5Zu1ZjEd9pXHxO/BsiaxqaJWXT8b4TQtF0pUQ17pEXZkZlr156+hyfx3bQTw8+iw== +"@ndla/types-taxonomy@^1.0.21": + version "1.0.21" + resolved "https://registry.yarnpkg.com/@ndla/types-taxonomy/-/types-taxonomy-1.0.21.tgz#fe3db31cbd859385fa21b27ade81f98a6d314200" + integrity sha512-80QnSj1cg0vgX001W13Sl/VJTreTWNFx5uC5ZJcDGJNbU+dK1fQ8zRUkNa46od61+JjX6ZNWYBqpVCOb0urexQ== "@nicolo-ribaudo/eslint-scope-5-internals@5.1.1-v1": version "5.1.1-v1"