From 083230a3a1df96f37bd3d45918a66787efcf1cff Mon Sep 17 00:00:00 2001 From: Jonas Ege Carlsen Date: Wed, 16 Aug 2023 13:55:52 +0200 Subject: [PATCH 1/2] Allow for one to query all fields on frontpage article with a single API call --- src/resolvers/frontpageResolvers.ts | 43 ++--------------------------- src/schema.ts | 15 ++++------ src/types/schema.d.ts | 43 ++++++++++------------------- 3 files changed, 22 insertions(+), 79 deletions(-) diff --git a/src/resolvers/frontpageResolvers.ts b/src/resolvers/frontpageResolvers.ts index 753916c9..6841d223 100644 --- a/src/resolvers/frontpageResolvers.ts +++ b/src/resolvers/frontpageResolvers.ts @@ -60,50 +60,13 @@ export const Query = { }; export const resolvers = { - Frontpage: { + FrontpageMenu: { async article( - frontpage: IFrontPage, + menu: IFrontPage, _: any, context: ContextWithLoaders, ): Promise { - return fetchArticle( - { - articleId: `${frontpage.articleId}`, - convertEmbeds: true, - }, - context, - ); - }, - }, - - Menu: { - async title( - menu: IMenu, - _: any, - context: ContextWithLoaders, - ): Promise { - const article = await fetchArticle( - { - articleId: `${menu.articleId}`, - convertEmbeds: true, - }, - context, - ); - return article.title; - }, - async slug( - menu: IMenu, - _: any, - context: ContextWithLoaders, - ): Promise { - const article = await fetchArticle( - { - articleId: `${menu.articleId}`, - convertEmbeds: true, - }, - context, - ); - return article.slug || ''; + return fetchArticle({ articleId: `${menu.articleId}` }, context); }, }, diff --git a/src/schema.ts b/src/schema.ts index 47b2f6dd..6618ccd7 100644 --- a/src/schema.ts +++ b/src/schema.ts @@ -566,15 +566,10 @@ export const typeDefs = gql` code: String } - type Menu { - title: String - slug: String - menu: [Menu]! - } - - type Frontpage { - article: Article - menu: [Menu]! + type FrontpageMenu { + articleId: Int! + article: Article! + menu: [FrontpageMenu]! } type SubjectPageVisualElement { @@ -1143,7 +1138,7 @@ export const typeDefs = gql` ): [Subject!] topic(id: String!, subjectId: String): Topic topics(contentUri: String, filterVisible: Boolean): [Topic!] - frontpage: Frontpage + frontpage: FrontpageMenu competenceGoals(codes: [String], language: String): [CompetenceGoal!] competenceGoal(code: String!, language: String): CompetenceGoal coreElements(codes: [String], language: String): [CoreElement!] diff --git a/src/types/schema.d.ts b/src/types/schema.d.ts index adcad449..03279c22 100644 --- a/src/types/schema.d.ts +++ b/src/types/schema.d.ts @@ -461,10 +461,11 @@ export type GQLFrontPageResources = { totalCount: Scalars['Int']; }; -export type GQLFrontpage = { - __typename?: 'Frontpage'; - article?: Maybe; - menu: Array>; +export type GQLFrontpageMenu = { + __typename?: 'FrontpageMenu'; + article: GQLArticle; + articleId: Scalars['Int']; + menu: Array>; }; export type GQLFrontpageSearch = { @@ -724,13 +725,6 @@ export type GQLManuscript = { manuscript: Scalars['String']; }; -export type GQLMenu = { - __typename?: 'Menu'; - menu: Array>; - slug?: Maybe; - title?: Maybe; -}; - export type GQLMeta = { __typename?: 'Meta'; availability?: Maybe; @@ -998,7 +992,7 @@ export type GQLQuery = { folderResourceMeta?: Maybe; folderResourceMetaSearch: Array; folders: Array; - frontpage?: Maybe; + frontpage?: Maybe; frontpageSearch?: Maybe; groupSearch?: Maybe>; image?: Maybe; @@ -1763,7 +1757,7 @@ export type GQLResolversTypes = { FolderResourceResourceType: ResolverTypeWrapper; FootNote: ResolverTypeWrapper; FrontPageResources: ResolverTypeWrapper; - Frontpage: ResolverTypeWrapper; + FrontpageMenu: ResolverTypeWrapper; FrontpageSearch: ResolverTypeWrapper; FrontpageSearchResult: ResolverTypeWrapper; Grade: ResolverTypeWrapper; @@ -1790,7 +1784,6 @@ export type GQLResolversTypes = { License: ResolverTypeWrapper; ListingPage: ResolverTypeWrapper; Manuscript: ResolverTypeWrapper; - Menu: ResolverTypeWrapper; Meta: ResolverTypeWrapper; MetaImage: ResolverTypeWrapper; Movie: ResolverTypeWrapper; @@ -1902,7 +1895,7 @@ export type GQLResolversParentTypes = { FolderResourceResourceType: GQLFolderResourceResourceType; FootNote: GQLFootNote; FrontPageResources: GQLFrontPageResources; - Frontpage: GQLFrontpage; + FrontpageMenu: GQLFrontpageMenu; FrontpageSearch: GQLFrontpageSearch; FrontpageSearchResult: GQLFrontpageSearchResult; Grade: GQLGrade; @@ -1929,7 +1922,6 @@ export type GQLResolversParentTypes = { License: GQLLicense; ListingPage: GQLListingPage; Manuscript: GQLManuscript; - Menu: GQLMenu; Meta: GQLMeta; MetaImage: GQLMetaImage; Movie: GQLMovie; @@ -2428,9 +2420,10 @@ export type GQLFrontPageResourcesResolvers; }; -export type GQLFrontpageResolvers = { - article?: Resolver, ParentType, ContextType>; - menu?: Resolver>, ParentType, ContextType>; +export type GQLFrontpageMenuResolvers = { + article?: Resolver; + articleId?: Resolver; + menu?: Resolver>, ParentType, ContextType>; __isTypeOf?: IsTypeOfResolverFn; }; @@ -2691,13 +2684,6 @@ export type GQLManuscriptResolvers; }; -export type GQLMenuResolvers = { - menu?: Resolver>, ParentType, ContextType>; - slug?: Resolver, ParentType, ContextType>; - title?: Resolver, ParentType, ContextType>; - __isTypeOf?: IsTypeOfResolverFn; -}; - export type GQLMetaResolvers = { availability?: Resolver, ParentType, ContextType>; id?: Resolver; @@ -2889,7 +2875,7 @@ export type GQLQueryResolvers, ParentType, ContextType, RequireFields>; folderResourceMetaSearch?: Resolver, ParentType, ContextType, RequireFields>; folders?: Resolver, ParentType, ContextType, Partial>; - frontpage?: Resolver, ParentType, ContextType>; + frontpage?: Resolver, ParentType, ContextType>; frontpageSearch?: Resolver, ParentType, ContextType, Partial>; groupSearch?: Resolver>, ParentType, ContextType, Partial>; image?: Resolver, ParentType, ContextType, RequireFields>; @@ -3311,7 +3297,7 @@ export type GQLResolvers = { FolderResourceResourceType?: GQLFolderResourceResourceTypeResolvers; FootNote?: GQLFootNoteResolvers; FrontPageResources?: GQLFrontPageResourcesResolvers; - Frontpage?: GQLFrontpageResolvers; + FrontpageMenu?: GQLFrontpageMenuResolvers; FrontpageSearch?: GQLFrontpageSearchResolvers; FrontpageSearchResult?: GQLFrontpageSearchResultResolvers; Grade?: GQLGradeResolvers; @@ -3337,7 +3323,6 @@ export type GQLResolvers = { License?: GQLLicenseResolvers; ListingPage?: GQLListingPageResolvers; Manuscript?: GQLManuscriptResolvers; - Menu?: GQLMenuResolvers; Meta?: GQLMetaResolvers; MetaImage?: GQLMetaImageResolvers; Movie?: GQLMovieResolvers; From 19fffda84c99e6a002aa98d7b1beb8f54bf95d4c Mon Sep 17 00:00:00 2001 From: Jonas Ege Carlsen Date: Wed, 16 Aug 2023 13:58:13 +0200 Subject: [PATCH 2/2] Remove unused import --- src/resolvers/frontpageResolvers.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/resolvers/frontpageResolvers.ts b/src/resolvers/frontpageResolvers.ts index 6841d223..4012a095 100644 --- a/src/resolvers/frontpageResolvers.ts +++ b/src/resolvers/frontpageResolvers.ts @@ -11,7 +11,6 @@ import { ISubjectPageData, IFilmFrontPageData, IMovieTheme, - IMenu, } from '@ndla/types-backend/frontpage-api'; import { TaxonomyContext } from '@ndla/types-taxonomy'; import {