From 828f9b1ec4a1b2a41571867cc3d134b1edfa884d Mon Sep 17 00:00:00 2001 From: Gunnar Velle Date: Thu, 31 Oct 2024 12:36:44 +0100 Subject: [PATCH 1/2] Replace name from tax with html-version of articlename --- src/resolvers/resourceResolvers.ts | 7 +++++++ src/resolvers/taxonomyResolvers.ts | 31 +++++++++++++++++++++--------- src/resolvers/topicResolvers.ts | 7 +++++++ 3 files changed, 36 insertions(+), 9 deletions(-) diff --git a/src/resolvers/resourceResolvers.ts b/src/resolvers/resourceResolvers.ts index a9758cb8..545e0d53 100644 --- a/src/resolvers/resourceResolvers.ts +++ b/src/resolvers/resourceResolvers.ts @@ -64,6 +64,13 @@ export const resolvers = { } return defaultAvailability; }, + async name(node: GQLResource, _: any, context: ContextWithLoaders): Promise { + if (node.contentUri?.startsWith("urn:article")) { + const article = await context.loaders.articlesLoader.load(getArticleIdFromUrn(node.contentUri)); + return article ? article.title.htmlTitle : null; + } + return node.name; + }, async meta(resource: GQLResource, _: any, context: ContextWithLoaders): Promise { if (resource.contentUri?.startsWith("urn:learningpath")) { const learningpath = await context.loaders.learningpathsLoader.load( diff --git a/src/resolvers/taxonomyResolvers.ts b/src/resolvers/taxonomyResolvers.ts index 12be55ea..52858466 100644 --- a/src/resolvers/taxonomyResolvers.ts +++ b/src/resolvers/taxonomyResolvers.ts @@ -98,10 +98,12 @@ export const resolvers = { } return undefined; }, - async availability(node: GQLTaxonomyEntity, _: any, context: ContextWithLoaders) { - if (!node.contentUri) return undefined; - const article = await context.loaders.articlesLoader.load(getArticleIdFromUrn(node.contentUri)); - return article?.availability; + async availability(node: GQLTaxonomyEntity, _: any, context: ContextWithLoaders): Promise { + if (node.contentUri?.startsWith("urn:article")) { + const article = await context.loaders.articlesLoader.load(getArticleIdFromUrn(node.contentUri)); + return article?.availability; + } + return undefined; }, async learningpath(node: GQLTaxonomyEntity, _: any, context: ContextWithLoaders): Promise { if (node.contentUri?.startsWith("urn:learningpath")) { @@ -111,9 +113,18 @@ export const resolvers = { return null; }, async meta(node: Node, _: any, context: ContextWithLoaders): Promise { - if (!node.contentUri?.startsWith("urn:article")) return null; - const article = await context.loaders.articlesLoader.load(getArticleIdFromUrn(node.contentUri)); - return article ? articleToMeta(article) : null; + if (node.contentUri?.startsWith("urn:article")) { + const article = await context.loaders.articlesLoader.load(getArticleIdFromUrn(node.contentUri)); + return article ? articleToMeta(article) : null; + } + return null; + }, + async name(node: Node, _: any, context: ContextWithLoaders): Promise { + if (node.contentUri?.startsWith("urn:article")) { + const article = await context.loaders.articlesLoader.load(getArticleIdFromUrn(node.contentUri)); + return article ? article.title.htmlTitle : null; + } + return node.name; }, async children( node: GQLTaxonomyEntity, @@ -128,8 +139,10 @@ export const resolvers = { return filterMissingArticles(entities, context); }, async subjectpage(node: GQLTaxonomyEntity, __: any, context: ContextWithLoaders): Promise { - if (!node.contentUri?.startsWith("urn:frontpage")) return null; - return context.loaders.subjectpageLoader.load(node.contentUri.replace("urn:frontpage:", "")); + if (node.contentUri?.startsWith("urn:frontpage")) { + return context.loaders.subjectpageLoader.load(node.contentUri.replace("urn:frontpage:", "")); + } + return null; }, async grepCodes(node: GQLTaxonomyEntity, __: any, context: ContextWithLoaders): Promise { if (node.metadata?.grepCodes) { diff --git a/src/resolvers/topicResolvers.ts b/src/resolvers/topicResolvers.ts index 529b95a4..39f2c8b1 100644 --- a/src/resolvers/topicResolvers.ts +++ b/src/resolvers/topicResolvers.ts @@ -70,6 +70,13 @@ export const resolvers = { const article = await context.loaders.articlesLoader.load(getArticleIdFromUrn(topic.contentUri)); return article ? articleToMeta(article) : null; }, + async name(node: Node, _: any, context: ContextWithLoaders): Promise { + if (node.contentUri?.startsWith("urn:article")) { + const article = await context.loaders.articlesLoader.load(getArticleIdFromUrn(node.contentUri)); + return article ? article.title.htmlTitle : null; + } + return node.name; + }, async coreResources( topic: Node, args: GQLTopicCoreResourcesArgs, From 22acb4e26c1733c8a416ab6dd1bb38faf8573224 Mon Sep 17 00:00:00 2001 From: Gunnar Velle Date: Fri, 8 Nov 2024 09:54:42 +0100 Subject: [PATCH 2/2] Use separate name to get html title. --- src/resolvers/resourceResolvers.ts | 2 +- src/resolvers/taxonomyResolvers.ts | 2 +- src/resolvers/topicResolvers.ts | 2 +- src/schema.ts | 4 ++++ src/types/schema.d.ts | 8 ++++++++ 5 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/resolvers/resourceResolvers.ts b/src/resolvers/resourceResolvers.ts index 545e0d53..1a0482f8 100644 --- a/src/resolvers/resourceResolvers.ts +++ b/src/resolvers/resourceResolvers.ts @@ -64,7 +64,7 @@ export const resolvers = { } return defaultAvailability; }, - async name(node: GQLResource, _: any, context: ContextWithLoaders): Promise { + async htmlTitle(node: GQLResource, _: any, context: ContextWithLoaders): Promise { if (node.contentUri?.startsWith("urn:article")) { const article = await context.loaders.articlesLoader.load(getArticleIdFromUrn(node.contentUri)); return article ? article.title.htmlTitle : null; diff --git a/src/resolvers/taxonomyResolvers.ts b/src/resolvers/taxonomyResolvers.ts index 52858466..57582f47 100644 --- a/src/resolvers/taxonomyResolvers.ts +++ b/src/resolvers/taxonomyResolvers.ts @@ -119,7 +119,7 @@ export const resolvers = { } return null; }, - async name(node: Node, _: any, context: ContextWithLoaders): Promise { + async htmlTitle(node: Node, _: any, context: ContextWithLoaders): Promise { if (node.contentUri?.startsWith("urn:article")) { const article = await context.loaders.articlesLoader.load(getArticleIdFromUrn(node.contentUri)); return article ? article.title.htmlTitle : null; diff --git a/src/resolvers/topicResolvers.ts b/src/resolvers/topicResolvers.ts index 39f2c8b1..11574ef6 100644 --- a/src/resolvers/topicResolvers.ts +++ b/src/resolvers/topicResolvers.ts @@ -70,7 +70,7 @@ export const resolvers = { const article = await context.loaders.articlesLoader.load(getArticleIdFromUrn(topic.contentUri)); return article ? articleToMeta(article) : null; }, - async name(node: Node, _: any, context: ContextWithLoaders): Promise { + async htmlTitle(node: Node, _: any, context: ContextWithLoaders): Promise { if (node.contentUri?.startsWith("urn:article")) { const article = await context.loaders.articlesLoader.load(getArticleIdFromUrn(node.contentUri)); return article ? article.title.htmlTitle : null; diff --git a/src/schema.ts b/src/schema.ts index bc487e35..7046a9d8 100644 --- a/src/schema.ts +++ b/src/schema.ts @@ -302,6 +302,7 @@ export const typeDefs = gql` contentUri: String article: Article availability: String + htmlTitle: String meta: Meta } @@ -330,6 +331,7 @@ export const typeDefs = gql` meta: Meta article: Article availability: String + htmlTitle: String learningpath: Learningpath subjectpage: SubjectPage grepCodes: [String!] @@ -358,6 +360,7 @@ export const typeDefs = gql` learningpath: Learningpath article: Article availability: String + htmlTitle: String } type TaxonomyCrumb implements TaxBase { @@ -400,6 +403,7 @@ export const typeDefs = gql` meta: Meta article: Article availability: String + htmlTitle: String isPrimary: Boolean parentId: String subtopics: [Topic!] diff --git a/src/types/schema.d.ts b/src/types/schema.d.ts index 2ef9909b..68e38dc9 100644 --- a/src/types/schema.d.ts +++ b/src/types/schema.d.ts @@ -1401,6 +1401,7 @@ export type GQLNode = GQLTaxBase & GQLTaxonomyEntity & GQLWithArticle & { contextId?: Maybe; contexts: Array; grepCodes?: Maybe>; + htmlTitle?: Maybe; id: Scalars['String']; language?: Maybe; learningpath?: Maybe; @@ -1990,6 +1991,7 @@ export type GQLResource = GQLTaxBase & GQLTaxonomyEntity & GQLWithArticle & { context?: Maybe; contextId?: Maybe; contexts: Array; + htmlTitle?: Maybe; id: Scalars['String']; language?: Maybe; learningpath?: Maybe; @@ -2295,6 +2297,7 @@ export type GQLTopic = GQLTaxBase & GQLTaxonomyEntity & GQLWithArticle & { contextId?: Maybe; contexts: Array; coreResources?: Maybe>; + htmlTitle?: Maybe; id: Scalars['String']; isPrimary?: Maybe; language?: Maybe; @@ -2424,6 +2427,7 @@ export type GQLWithArticle = { article?: Maybe; availability?: Maybe; contentUri?: Maybe; + htmlTitle?: Maybe; meta?: Maybe; }; @@ -3904,6 +3908,7 @@ export type GQLNodeResolvers, ParentType, ContextType>; contexts?: Resolver, ParentType, ContextType>; grepCodes?: Resolver>, ParentType, ContextType>; + htmlTitle?: Resolver, ParentType, ContextType>; id?: Resolver; language?: Resolver, ParentType, ContextType>; learningpath?: Resolver, ParentType, ContextType>; @@ -4133,6 +4138,7 @@ export type GQLResourceResolvers, ParentType, ContextType>; contextId?: Resolver, ParentType, ContextType>; contexts?: Resolver, ParentType, ContextType>; + htmlTitle?: Resolver, ParentType, ContextType>; id?: Resolver; language?: Resolver, ParentType, ContextType>; learningpath?: Resolver, ParentType, ContextType>; @@ -4434,6 +4440,7 @@ export type GQLTopicResolvers, ParentType, ContextType>; contexts?: Resolver, ParentType, ContextType>; coreResources?: Resolver>, ParentType, ContextType, Partial>; + htmlTitle?: Resolver, ParentType, ContextType>; id?: Resolver; isPrimary?: Resolver, ParentType, ContextType>; language?: Resolver, ParentType, ContextType>; @@ -4544,6 +4551,7 @@ export type GQLWithArticleResolvers, ParentType, ContextType>; availability?: Resolver, ParentType, ContextType>; contentUri?: Resolver, ParentType, ContextType>; + htmlTitle?: Resolver, ParentType, ContextType>; meta?: Resolver, ParentType, ContextType>; };