Skip to content

Commit

Permalink
Merge pull request #351 from NDLANO/proper-resolvers-for-frontpage
Browse files Browse the repository at this point in the history
Allow for one to query all fields on frontpage article with a single API call
  • Loading branch information
Jonas-C authored Aug 17, 2023
2 parents f5be085 + 19fffda commit ee8c222
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 80 deletions.
44 changes: 3 additions & 41 deletions src/resolvers/frontpageResolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
ISubjectPageData,
IFilmFrontPageData,
IMovieTheme,
IMenu,
} from '@ndla/types-backend/frontpage-api';
import { TaxonomyContext } from '@ndla/types-taxonomy';
import {
Expand Down Expand Up @@ -60,50 +59,13 @@ export const Query = {
};

export const resolvers = {
Frontpage: {
FrontpageMenu: {
async article(
frontpage: IFrontPage,
menu: IFrontPage,
_: any,
context: ContextWithLoaders,
): Promise<GQLArticle> {
return fetchArticle(
{
articleId: `${frontpage.articleId}`,
convertEmbeds: true,
},
context,
);
},
},

Menu: {
async title(
menu: IMenu,
_: any,
context: ContextWithLoaders,
): Promise<string> {
const article = await fetchArticle(
{
articleId: `${menu.articleId}`,
convertEmbeds: true,
},
context,
);
return article.title;
},
async slug(
menu: IMenu,
_: any,
context: ContextWithLoaders,
): Promise<string> {
const article = await fetchArticle(
{
articleId: `${menu.articleId}`,
convertEmbeds: true,
},
context,
);
return article.slug || '';
return fetchArticle({ articleId: `${menu.articleId}` }, context);
},
},

Expand Down
15 changes: 5 additions & 10 deletions src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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!]
Expand Down
43 changes: 14 additions & 29 deletions src/types/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -461,10 +461,11 @@ export type GQLFrontPageResources = {
totalCount: Scalars['Int'];
};

export type GQLFrontpage = {
__typename?: 'Frontpage';
article?: Maybe<GQLArticle>;
menu: Array<Maybe<GQLMenu>>;
export type GQLFrontpageMenu = {
__typename?: 'FrontpageMenu';
article: GQLArticle;
articleId: Scalars['Int'];
menu: Array<Maybe<GQLFrontpageMenu>>;
};

export type GQLFrontpageSearch = {
Expand Down Expand Up @@ -724,13 +725,6 @@ export type GQLManuscript = {
manuscript: Scalars['String'];
};

export type GQLMenu = {
__typename?: 'Menu';
menu: Array<Maybe<GQLMenu>>;
slug?: Maybe<Scalars['String']>;
title?: Maybe<Scalars['String']>;
};

export type GQLMeta = {
__typename?: 'Meta';
availability?: Maybe<Scalars['String']>;
Expand Down Expand Up @@ -1005,7 +999,7 @@ export type GQLQuery = {
folderResourceMeta?: Maybe<GQLFolderResourceMeta>;
folderResourceMetaSearch: Array<GQLFolderResourceMeta>;
folders: Array<GQLFolder>;
frontpage?: Maybe<GQLFrontpage>;
frontpage?: Maybe<GQLFrontpageMenu>;
frontpageSearch?: Maybe<GQLFrontpageSearch>;
groupSearch?: Maybe<Array<GQLGroupSearch>>;
image?: Maybe<GQLImageMetaInformationV2>;
Expand Down Expand Up @@ -1770,7 +1764,7 @@ export type GQLResolversTypes = {
FolderResourceResourceType: ResolverTypeWrapper<GQLFolderResourceResourceType>;
FootNote: ResolverTypeWrapper<GQLFootNote>;
FrontPageResources: ResolverTypeWrapper<GQLFrontPageResources>;
Frontpage: ResolverTypeWrapper<GQLFrontpage>;
FrontpageMenu: ResolverTypeWrapper<GQLFrontpageMenu>;
FrontpageSearch: ResolverTypeWrapper<GQLFrontpageSearch>;
FrontpageSearchResult: ResolverTypeWrapper<GQLFrontpageSearchResult>;
Grade: ResolverTypeWrapper<GQLGrade>;
Expand All @@ -1797,7 +1791,6 @@ export type GQLResolversTypes = {
License: ResolverTypeWrapper<GQLLicense>;
ListingPage: ResolverTypeWrapper<GQLListingPage>;
Manuscript: ResolverTypeWrapper<GQLManuscript>;
Menu: ResolverTypeWrapper<GQLMenu>;
Meta: ResolverTypeWrapper<GQLMeta>;
MetaImage: ResolverTypeWrapper<GQLMetaImage>;
Movie: ResolverTypeWrapper<GQLMovie>;
Expand Down Expand Up @@ -1909,7 +1902,7 @@ export type GQLResolversParentTypes = {
FolderResourceResourceType: GQLFolderResourceResourceType;
FootNote: GQLFootNote;
FrontPageResources: GQLFrontPageResources;
Frontpage: GQLFrontpage;
FrontpageMenu: GQLFrontpageMenu;
FrontpageSearch: GQLFrontpageSearch;
FrontpageSearchResult: GQLFrontpageSearchResult;
Grade: GQLGrade;
Expand All @@ -1936,7 +1929,6 @@ export type GQLResolversParentTypes = {
License: GQLLicense;
ListingPage: GQLListingPage;
Manuscript: GQLManuscript;
Menu: GQLMenu;
Meta: GQLMeta;
MetaImage: GQLMetaImage;
Movie: GQLMovie;
Expand Down Expand Up @@ -2435,9 +2427,10 @@ export type GQLFrontPageResourcesResolvers<ContextType = any, ParentType extends
__isTypeOf?: IsTypeOfResolverFn<ParentType, ContextType>;
};

export type GQLFrontpageResolvers<ContextType = any, ParentType extends GQLResolversParentTypes['Frontpage'] = GQLResolversParentTypes['Frontpage']> = {
article?: Resolver<Maybe<GQLResolversTypes['Article']>, ParentType, ContextType>;
menu?: Resolver<Array<Maybe<GQLResolversTypes['Menu']>>, ParentType, ContextType>;
export type GQLFrontpageMenuResolvers<ContextType = any, ParentType extends GQLResolversParentTypes['FrontpageMenu'] = GQLResolversParentTypes['FrontpageMenu']> = {
article?: Resolver<GQLResolversTypes['Article'], ParentType, ContextType>;
articleId?: Resolver<GQLResolversTypes['Int'], ParentType, ContextType>;
menu?: Resolver<Array<Maybe<GQLResolversTypes['FrontpageMenu']>>, ParentType, ContextType>;
__isTypeOf?: IsTypeOfResolverFn<ParentType, ContextType>;
};

Expand Down Expand Up @@ -2698,13 +2691,6 @@ export type GQLManuscriptResolvers<ContextType = any, ParentType extends GQLReso
__isTypeOf?: IsTypeOfResolverFn<ParentType, ContextType>;
};

export type GQLMenuResolvers<ContextType = any, ParentType extends GQLResolversParentTypes['Menu'] = GQLResolversParentTypes['Menu']> = {
menu?: Resolver<Array<Maybe<GQLResolversTypes['Menu']>>, ParentType, ContextType>;
slug?: Resolver<Maybe<GQLResolversTypes['String']>, ParentType, ContextType>;
title?: Resolver<Maybe<GQLResolversTypes['String']>, ParentType, ContextType>;
__isTypeOf?: IsTypeOfResolverFn<ParentType, ContextType>;
};

export type GQLMetaResolvers<ContextType = any, ParentType extends GQLResolversParentTypes['Meta'] = GQLResolversParentTypes['Meta']> = {
availability?: Resolver<Maybe<GQLResolversTypes['String']>, ParentType, ContextType>;
id?: Resolver<GQLResolversTypes['Int'], ParentType, ContextType>;
Expand Down Expand Up @@ -2897,7 +2883,7 @@ export type GQLQueryResolvers<ContextType = any, ParentType extends GQLResolvers
folderResourceMeta?: Resolver<Maybe<GQLResolversTypes['FolderResourceMeta']>, ParentType, ContextType, RequireFields<GQLQueryFolderResourceMetaArgs, 'resource'>>;
folderResourceMetaSearch?: Resolver<Array<GQLResolversTypes['FolderResourceMeta']>, ParentType, ContextType, RequireFields<GQLQueryFolderResourceMetaSearchArgs, 'resources'>>;
folders?: Resolver<Array<GQLResolversTypes['Folder']>, ParentType, ContextType, Partial<GQLQueryFoldersArgs>>;
frontpage?: Resolver<Maybe<GQLResolversTypes['Frontpage']>, ParentType, ContextType>;
frontpage?: Resolver<Maybe<GQLResolversTypes['FrontpageMenu']>, ParentType, ContextType>;
frontpageSearch?: Resolver<Maybe<GQLResolversTypes['FrontpageSearch']>, ParentType, ContextType, Partial<GQLQueryFrontpageSearchArgs>>;
groupSearch?: Resolver<Maybe<Array<GQLResolversTypes['GroupSearch']>>, ParentType, ContextType, Partial<GQLQueryGroupSearchArgs>>;
image?: Resolver<Maybe<GQLResolversTypes['ImageMetaInformationV2']>, ParentType, ContextType, RequireFields<GQLQueryImageArgs, 'id'>>;
Expand Down Expand Up @@ -3319,7 +3305,7 @@ export type GQLResolvers<ContextType = any> = {
FolderResourceResourceType?: GQLFolderResourceResourceTypeResolvers<ContextType>;
FootNote?: GQLFootNoteResolvers<ContextType>;
FrontPageResources?: GQLFrontPageResourcesResolvers<ContextType>;
Frontpage?: GQLFrontpageResolvers<ContextType>;
FrontpageMenu?: GQLFrontpageMenuResolvers<ContextType>;
FrontpageSearch?: GQLFrontpageSearchResolvers<ContextType>;
FrontpageSearchResult?: GQLFrontpageSearchResultResolvers<ContextType>;
Grade?: GQLGradeResolvers<ContextType>;
Expand All @@ -3345,7 +3331,6 @@ export type GQLResolvers<ContextType = any> = {
License?: GQLLicenseResolvers<ContextType>;
ListingPage?: GQLListingPageResolvers<ContextType>;
Manuscript?: GQLManuscriptResolvers<ContextType>;
Menu?: GQLMenuResolvers<ContextType>;
Meta?: GQLMetaResolvers<ContextType>;
MetaImage?: GQLMetaImageResolvers<ContextType>;
Movie?: GQLMovieResolvers<ContextType>;
Expand Down

0 comments on commit ee8c222

Please sign in to comment.