From 00397e0535b918083a1652014a60224c539bd0f4 Mon Sep 17 00:00:00 2001 From: Gunnar Velle Date: Fri, 24 Nov 2023 12:33:17 +0100 Subject: [PATCH 1/9] Add feide groups. Adds myNdlaUser query --- src/resolvers/folderResolvers.ts | 8 ++++++++ src/schema.ts | 10 ++++++++++ src/types/schema.d.ts | 25 +++++++++++++++++++++++++ 3 files changed, 43 insertions(+) diff --git a/src/resolvers/folderResolvers.ts b/src/resolvers/folderResolvers.ts index 585e4f8b..8e45e1e0 100644 --- a/src/resolvers/folderResolvers.ts +++ b/src/resolvers/folderResolvers.ts @@ -62,6 +62,7 @@ export const Query: Pick< | 'allFolderResources' | 'folderResourceMetaSearch' | 'folderResourceMeta' + | 'myNdlaUser' | 'personalData' > = { async folders( @@ -106,6 +107,13 @@ export const Query: Pick< ): Promise { return fetchFolderResourceMeta(params, context); }, + async myNdlaUser( + _: any, + __: any, + context: ContextWithLoaders, + ): Promise { + return getPersonalData(context); + }, async personalData( _: any, __: any, diff --git a/src/schema.ts b/src/schema.ts index e2b73385..8cbd79a9 100644 --- a/src/schema.ts +++ b/src/schema.ts @@ -1138,13 +1138,22 @@ export const typeDefs = gql` parentId: String } + type MyNdlaGroup { + id: String! + displayName: String! + isPrimarySchool: Boolean! + parentId: String + } + type MyNdlaPersonalData { id: Int! + username: String! favoriteSubjects: [String!]! role: String! arenaEnabled: Boolean! shareName: Boolean! organization: String! + groups: [MyNdlaGroup]! } type ConfigMetaBoolean { @@ -1381,6 +1390,7 @@ export const typeDefs = gql` includeResources: Boolean ): SharedFolder! allFolderResources(size: Int): [FolderResource!]! + myNdlaUser: MyNdlaPersonalData! personalData: MyNdlaPersonalData! image(id: String!): ImageMetaInformationV2 examLockStatus: ConfigMetaBoolean! diff --git a/src/types/schema.d.ts b/src/types/schema.d.ts index e2534c23..8117025e 100644 --- a/src/types/schema.d.ts +++ b/src/types/schema.d.ts @@ -1024,14 +1024,24 @@ 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']; favoriteSubjects: Array; + groups: Array>; id: Scalars['Int']; organization: Scalars['String']; role: Scalars['String']; shareName: Scalars['Boolean']; + username: Scalars['String']; }; export type GQLName = { @@ -1176,6 +1186,7 @@ export type GQLQuery = { image?: Maybe; learningpath?: Maybe; listingPage?: Maybe; + myNdlaUser: GQLMyNdlaPersonalData; personalData: GQLMyNdlaPersonalData; podcastSearch?: Maybe; podcastSeries?: Maybe; @@ -2032,6 +2043,7 @@ export type GQLResolversTypes = { MovieResourceTypes: ResolverTypeWrapper; MovieTheme: ResolverTypeWrapper; Mutation: ResolverTypeWrapper<{}>; + MyNdlaGroup: ResolverTypeWrapper; MyNdlaPersonalData: ResolverTypeWrapper; Name: ResolverTypeWrapper; NewFolder: ResolverTypeWrapper; @@ -2185,6 +2197,7 @@ export type GQLResolversParentTypes = { MovieResourceTypes: GQLMovieResourceTypes; MovieTheme: GQLMovieTheme; Mutation: {}; + MyNdlaGroup: GQLMyNdlaGroup; MyNdlaPersonalData: GQLMyNdlaPersonalData; Name: GQLName; NewFolder: GQLNewFolder; @@ -3141,13 +3154,23 @@ export type GQLMutationResolvers>; }; +export type GQLMyNdlaGroupResolvers = { + displayName?: Resolver; + id?: Resolver; + isPrimarySchool?: Resolver; + parentId?: Resolver, ParentType, ContextType>; + __isTypeOf?: IsTypeOfResolverFn; +}; + export type GQLMyNdlaPersonalDataResolvers = { arenaEnabled?: Resolver; favoriteSubjects?: Resolver, ParentType, ContextType>; + groups?: Resolver>, ParentType, ContextType>; id?: Resolver; organization?: Resolver; role?: Resolver; shareName?: Resolver; + username?: Resolver; __isTypeOf?: IsTypeOfResolverFn; }; @@ -3293,6 +3316,7 @@ export type GQLQueryResolvers, ParentType, ContextType, RequireFields>; learningpath?: Resolver, ParentType, ContextType, RequireFields>; listingPage?: Resolver, ParentType, ContextType, Partial>; + myNdlaUser?: Resolver; personalData?: Resolver; podcastSearch?: Resolver, ParentType, ContextType, RequireFields>; podcastSeries?: Resolver, ParentType, ContextType, RequireFields>; @@ -3777,6 +3801,7 @@ export type GQLResolvers = { MovieResourceTypes?: GQLMovieResourceTypesResolvers; MovieTheme?: GQLMovieThemeResolvers; Mutation?: GQLMutationResolvers; + MyNdlaGroup?: GQLMyNdlaGroupResolvers; MyNdlaPersonalData?: GQLMyNdlaPersonalDataResolvers; Name?: GQLNameResolvers; NewFolder?: GQLNewFolderResolvers; From b9c3b4be1f800e544e99f42d92ab187b484391af Mon Sep 17 00:00:00 2001 From: Gunnar Velle Date: Fri, 24 Nov 2023 14:33:11 +0100 Subject: [PATCH 2/9] Add displayname. Add error handling. --- src/api/folderApi.ts | 14 +++++++++----- src/schema.ts | 3 ++- src/types/schema.d.ts | 2 ++ 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/api/folderApi.ts b/src/api/folderApi.ts index 05048e00..4fe88fb8 100644 --- a/src/api/folderApi.ts +++ b/src/api/folderApi.ts @@ -202,11 +202,15 @@ 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); + 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/schema.ts b/src/schema.ts index 8cbd79a9..3b95cb19 100644 --- a/src/schema.ts +++ b/src/schema.ts @@ -1148,6 +1148,7 @@ export const typeDefs = gql` type MyNdlaPersonalData { id: Int! username: String! + displayName: String! favoriteSubjects: [String!]! role: String! arenaEnabled: Boolean! @@ -1390,7 +1391,7 @@ export const typeDefs = gql` includeResources: Boolean ): SharedFolder! allFolderResources(size: Int): [FolderResource!]! - myNdlaUser: MyNdlaPersonalData! + myNdlaUser: MyNdlaPersonalData personalData: MyNdlaPersonalData! image(id: String!): ImageMetaInformationV2 examLockStatus: ConfigMetaBoolean! diff --git a/src/types/schema.d.ts b/src/types/schema.d.ts index 8117025e..5d7a7893 100644 --- a/src/types/schema.d.ts +++ b/src/types/schema.d.ts @@ -1035,6 +1035,7 @@ export type GQLMyNdlaGroup = { export type GQLMyNdlaPersonalData = { __typename?: 'MyNdlaPersonalData'; arenaEnabled: Scalars['Boolean']; + displayName: Scalars['String']; favoriteSubjects: Array; groups: Array>; id: Scalars['Int']; @@ -3164,6 +3165,7 @@ export type GQLMyNdlaGroupResolvers = { arenaEnabled?: Resolver; + displayName?: Resolver; favoriteSubjects?: Resolver, ParentType, ContextType>; groups?: Resolver>, ParentType, ContextType>; id?: Resolver; From d9cd1cb6f4f39c062f041f4f3ee147e704dc2bf8 Mon Sep 17 00:00:00 2001 From: Jonas Ege Carlsen Date: Sat, 25 Nov 2023 14:30:18 +0100 Subject: [PATCH 3/9] fmt --- src/api/folderApi.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/api/folderApi.ts b/src/api/folderApi.ts index 4fe88fb8..1d18824d 100644 --- a/src/api/folderApi.ts +++ b/src/api/folderApi.ts @@ -207,8 +207,8 @@ export async function getPersonalData(context: Context): Promise { ...context, shouldUseCache: false, }); - return await resolveJson(response); - } catch(e) { + return await resolveJson(response); + } catch (e) { return undefined; } } From fe5bba9368b0b9a5d22490b246126d909a9631f0 Mon Sep 17 00:00:00 2001 From: Gunnar Velle Date: Mon, 27 Nov 2023 08:42:00 +0100 Subject: [PATCH 4/9] Only one endpoint --- src/api/folderApi.ts | 2 +- src/resolvers/folderResolvers.ts | 9 +-------- src/schema.ts | 3 +-- src/types/schema.d.ts | 6 ++---- 4 files changed, 5 insertions(+), 15 deletions(-) diff --git a/src/api/folderApi.ts b/src/api/folderApi.ts index 1d18824d..87dc617d 100644 --- a/src/api/folderApi.ts +++ b/src/api/folderApi.ts @@ -201,7 +201,7 @@ export async function deletePersonalData(context: Context): Promise { } } -export async function getPersonalData(context: Context): Promise { +export async function getPersonalData(context: Context): Promise { try { const response = await fetch(`/learningpath-api/v1/users/`, { ...context, diff --git a/src/resolvers/folderResolvers.ts b/src/resolvers/folderResolvers.ts index 8e45e1e0..92bb751d 100644 --- a/src/resolvers/folderResolvers.ts +++ b/src/resolvers/folderResolvers.ts @@ -107,18 +107,11 @@ export const Query: Pick< ): Promise { return fetchFolderResourceMeta(params, context); }, - async myNdlaUser( - _: any, - __: any, - context: ContextWithLoaders, - ): Promise { - return getPersonalData(context); - }, async personalData( _: any, __: any, context: ContextWithLoaders, - ): Promise { + ): Promise { return getPersonalData(context); }, }; diff --git a/src/schema.ts b/src/schema.ts index 3b95cb19..98e715d0 100644 --- a/src/schema.ts +++ b/src/schema.ts @@ -1391,8 +1391,7 @@ export const typeDefs = gql` includeResources: Boolean ): SharedFolder! allFolderResources(size: Int): [FolderResource!]! - myNdlaUser: MyNdlaPersonalData - 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 5d7a7893..ad627c99 100644 --- a/src/types/schema.d.ts +++ b/src/types/schema.d.ts @@ -1187,8 +1187,7 @@ export type GQLQuery = { image?: Maybe; learningpath?: Maybe; listingPage?: Maybe; - myNdlaUser: GQLMyNdlaPersonalData; - personalData: GQLMyNdlaPersonalData; + personalData?: Maybe; podcastSearch?: Maybe; podcastSeries?: Maybe; podcastSeriesSearch?: Maybe; @@ -3318,8 +3317,7 @@ export type GQLQueryResolvers, ParentType, ContextType, RequireFields>; learningpath?: Resolver, ParentType, ContextType, RequireFields>; listingPage?: Resolver, ParentType, ContextType, Partial>; - myNdlaUser?: Resolver; - personalData?: Resolver; + personalData?: Resolver, ParentType, ContextType>; podcastSearch?: Resolver, ParentType, ContextType, RequireFields>; podcastSeries?: Resolver, ParentType, ContextType, RequireFields>; podcastSeriesSearch?: Resolver, ParentType, ContextType, RequireFields>; From 2706e195593c6761703ebb4c2ac77e2d5537fabe Mon Sep 17 00:00:00 2001 From: Gunnar Velle Date: Mon, 27 Nov 2023 09:55:50 +0100 Subject: [PATCH 5/9] Use string for id. --- src/schema.ts | 2 +- src/types/schema.d.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/schema.ts b/src/schema.ts index 98e715d0..7003cc4e 100644 --- a/src/schema.ts +++ b/src/schema.ts @@ -1146,7 +1146,7 @@ export const typeDefs = gql` } type MyNdlaPersonalData { - id: Int! + id: String! username: String! displayName: String! favoriteSubjects: [String!]! diff --git a/src/types/schema.d.ts b/src/types/schema.d.ts index ad627c99..e0acc34f 100644 --- a/src/types/schema.d.ts +++ b/src/types/schema.d.ts @@ -1038,7 +1038,7 @@ export type GQLMyNdlaPersonalData = { displayName: Scalars['String']; favoriteSubjects: Array; groups: Array>; - id: Scalars['Int']; + id: Scalars['String']; organization: Scalars['String']; role: Scalars['String']; shareName: Scalars['Boolean']; @@ -3167,7 +3167,7 @@ export type GQLMyNdlaPersonalDataResolvers; favoriteSubjects?: Resolver, ParentType, ContextType>; groups?: Resolver>, ParentType, ContextType>; - id?: Resolver; + id?: Resolver; organization?: Resolver; role?: Resolver; shareName?: Resolver; From 861570c1c7b94c3dd78828bc2f3eb4d0a76f53aa Mon Sep 17 00:00:00 2001 From: Gunnar Velle Date: Mon, 27 Nov 2023 11:00:56 +0100 Subject: [PATCH 6/9] Add feideid --- src/resolvers/folderResolvers.ts | 1 - src/schema.ts | 3 ++- src/types/schema.d.ts | 6 ++++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/resolvers/folderResolvers.ts b/src/resolvers/folderResolvers.ts index 92bb751d..e2219bcd 100644 --- a/src/resolvers/folderResolvers.ts +++ b/src/resolvers/folderResolvers.ts @@ -62,7 +62,6 @@ export const Query: Pick< | 'allFolderResources' | 'folderResourceMetaSearch' | 'folderResourceMeta' - | 'myNdlaUser' | 'personalData' > = { async folders( diff --git a/src/schema.ts b/src/schema.ts index 7003cc4e..3dd856f1 100644 --- a/src/schema.ts +++ b/src/schema.ts @@ -1146,7 +1146,8 @@ export const typeDefs = gql` } type MyNdlaPersonalData { - id: String! + id: Int! + feideId: String! username: String! displayName: String! favoriteSubjects: [String!]! diff --git a/src/types/schema.d.ts b/src/types/schema.d.ts index e0acc34f..916ab482 100644 --- a/src/types/schema.d.ts +++ b/src/types/schema.d.ts @@ -1037,8 +1037,9 @@ export type GQLMyNdlaPersonalData = { arenaEnabled: Scalars['Boolean']; displayName: Scalars['String']; favoriteSubjects: Array; + feideId: Scalars['String']; groups: Array>; - id: Scalars['String']; + id: Scalars['Int']; organization: Scalars['String']; role: Scalars['String']; shareName: Scalars['Boolean']; @@ -3166,8 +3167,9 @@ export type GQLMyNdlaPersonalDataResolvers; displayName?: Resolver; favoriteSubjects?: Resolver, ParentType, ContextType>; + feideId?: Resolver; groups?: Resolver>, ParentType, ContextType>; - id?: Resolver; + id?: Resolver; organization?: Resolver; role?: Resolver; shareName?: Resolver; From 4a1979558490bb26716bb6864ed84d027e7b597a Mon Sep 17 00:00:00 2001 From: Gunnar Velle Date: Tue, 28 Nov 2023 17:01:57 +0100 Subject: [PATCH 7/9] Add email. --- src/schema.ts | 1 + src/types/schema.d.ts | 2 ++ 2 files changed, 3 insertions(+) diff --git a/src/schema.ts b/src/schema.ts index 3dd856f1..aa4ae512 100644 --- a/src/schema.ts +++ b/src/schema.ts @@ -1149,6 +1149,7 @@ export const typeDefs = gql` id: Int! feideId: String! username: String! + email: String! displayName: String! favoriteSubjects: [String!]! role: String! diff --git a/src/types/schema.d.ts b/src/types/schema.d.ts index 916ab482..089875d7 100644 --- a/src/types/schema.d.ts +++ b/src/types/schema.d.ts @@ -1036,6 +1036,7 @@ export type GQLMyNdlaPersonalData = { __typename?: 'MyNdlaPersonalData'; arenaEnabled: Scalars['Boolean']; displayName: Scalars['String']; + email: Scalars['String']; favoriteSubjects: Array; feideId: Scalars['String']; groups: Array>; @@ -3166,6 +3167,7 @@ export type GQLMyNdlaGroupResolvers = { arenaEnabled?: Resolver; displayName?: Resolver; + email?: Resolver; favoriteSubjects?: Resolver, ParentType, ContextType>; feideId?: Resolver; groups?: Resolver>, ParentType, ContextType>; From 9c9a22a810668746c7a67b76a9f82edc719f13f3 Mon Sep 17 00:00:00 2001 From: Gunnar Velle Date: Wed, 29 Nov 2023 09:34:43 +0100 Subject: [PATCH 8/9] Bump packages --- package.json | 4 ++-- src/api/folderApi.ts | 4 +++- yarn.lock | 16 ++++++++-------- 3 files changed, 13 insertions(+), 11 deletions(-) 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/folderApi.ts b/src/api/folderApi.ts index 87dc617d..6f2d3ba2 100644 --- a/src/api/folderApi.ts +++ b/src/api/folderApi.ts @@ -201,7 +201,9 @@ export async function deletePersonalData(context: Context): Promise { } } -export async function getPersonalData(context: Context): Promise { +export async function getPersonalData( + context: Context, +): Promise { try { const response = await fetch(`/learningpath-api/v1/users/`, { ...context, 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" From 755282f149d7b06faebc783f5329cfe599a5b660 Mon Sep 17 00:00:00 2001 From: Gunnar Velle Date: Wed, 29 Nov 2023 09:57:39 +0100 Subject: [PATCH 9/9] Dirty casting of type --- src/resolvers/folderResolvers.ts | 4 ++-- src/schema.ts | 2 +- src/types/schema.d.ts | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/resolvers/folderResolvers.ts b/src/resolvers/folderResolvers.ts index e2219bcd..f8d8b40f 100644 --- a/src/resolvers/folderResolvers.ts +++ b/src/resolvers/folderResolvers.ts @@ -110,8 +110,8 @@ export const Query: Pick< _: any, __: any, context: ContextWithLoaders, - ): Promise { - return getPersonalData(context); + ): Promise { + return (getPersonalData(context) as unknown) as GQLMyNdlaPersonalData; }, }; diff --git a/src/schema.ts b/src/schema.ts index aa4ae512..7315a9a7 100644 --- a/src/schema.ts +++ b/src/schema.ts @@ -1156,7 +1156,7 @@ export const typeDefs = gql` arenaEnabled: Boolean! shareName: Boolean! organization: String! - groups: [MyNdlaGroup]! + groups: [MyNdlaGroup!]! } type ConfigMetaBoolean { diff --git a/src/types/schema.d.ts b/src/types/schema.d.ts index 089875d7..a11cda9c 100644 --- a/src/types/schema.d.ts +++ b/src/types/schema.d.ts @@ -1039,7 +1039,7 @@ export type GQLMyNdlaPersonalData = { email: Scalars['String']; favoriteSubjects: Array; feideId: Scalars['String']; - groups: Array>; + groups: Array; id: Scalars['Int']; organization: Scalars['String']; role: Scalars['String']; @@ -3170,7 +3170,7 @@ export type GQLMyNdlaPersonalDataResolvers; favoriteSubjects?: Resolver, ParentType, ContextType>; feideId?: Resolver; - groups?: Resolver>, ParentType, ContextType>; + groups?: Resolver, ParentType, ContextType>; id?: Resolver; organization?: Resolver; role?: Resolver;