diff --git a/src/api/articleApi.ts b/src/api/articleApi.ts index 721ed2a8..14dcbf57 100644 --- a/src/api/articleApi.ts +++ b/src/api/articleApi.ts @@ -10,7 +10,12 @@ import { IArticleV2DTO } from "@ndla/types-backend/article-api"; import { queryNodes } from "./taxonomyApi"; import { transformArticle } from "./transformArticleApi"; import { ndlaUrl } from "../config"; -import { GQLArticleTransformedContentArgs, GQLRelatedContent, GQLTransformedArticleContent } from "../types/schema"; +import { + GQLArticleTransformedContentArgs, + GQLRelatedContent, + GQLTransformedArticleContent, + GQLTransformedDisclaimerContent, +} from "../types/schema"; import { fetch, resolveJson } from "../utils/apiHelpers"; import { getArticleIdFromUrn, findPrimaryPath } from "../utils/articleHelpers"; @@ -46,6 +51,15 @@ export const fetchTransformedContent = async ( }; }; +export const fetchTransformedDisclaimer = async ( + article: IArticleV2DTO, + context: Context, +): Promise => { + if (!article.disclaimer?.disclaimer) return { content: "" }; + const { content } = await transformArticle(article.disclaimer.disclaimer, context, undefined, {}); + return { content: content ?? "" }; +}; + export async function fetchRelatedContent( article: IArticleV2DTO, params: { subjectId?: string }, diff --git a/src/resolvers/articleResolvers.ts b/src/resolvers/articleResolvers.ts index 2ba65ef1..3d9060ec 100644 --- a/src/resolvers/articleResolvers.ts +++ b/src/resolvers/articleResolvers.ts @@ -19,7 +19,7 @@ import { fetchSubjectTopics, searchConcepts, } from "../api"; -import { fetchTransformedContent, fetchRelatedContent } from "../api/articleApi"; +import { fetchTransformedContent, fetchRelatedContent, fetchTransformedDisclaimer } from "../api/articleApi"; import { ndlaUrl } from "../config"; import { GQLCompetenceGoal, @@ -31,6 +31,7 @@ import { GQLRelatedContent, GQLVisualElementOembed, GQLMetaImageWithCopyright, + GQLTransformedDisclaimerContent, } from "../types/schema"; export const Query = { @@ -139,6 +140,13 @@ export const resolvers = { language(article: IArticleV2DTO): string { return article.content.language; }, + async transformedDisclaimer( + article: IArticleV2DTO, + _: any, + context: ContextWithLoaders, + ): Promise { + return fetchTransformedDisclaimer(article, context); + }, async transformedContent( article: IArticleV2DTO, args: GQLArticleTransformedContentArgs, diff --git a/src/schema.ts b/src/schema.ts index 364c0892..5197e75b 100644 --- a/src/schema.ts +++ b/src/schema.ts @@ -711,6 +711,7 @@ export const typeDefs = gql` language: String! transformedContent(transformArgs: TransformedArticleContentInput): TransformedArticleContent! oembed: String + transformedDisclaimer: TransformedDisclaimerContent! } input TransformedArticleContentInput { @@ -731,6 +732,10 @@ export const typeDefs = gql` visualElementEmbed: ResourceEmbed } + type TransformedDisclaimerContent { + content: String! + } + type EmbedVisualelement { visualElement: VisualElement } diff --git a/src/types/schema.d.ts b/src/types/schema.d.ts index 21ea143c..689009b7 100644 --- a/src/types/schema.d.ts +++ b/src/types/schema.d.ts @@ -241,6 +241,7 @@ export type GQLArticle = { tags?: Maybe>; title: Scalars['String']['output']; transformedContent: GQLTransformedArticleContent; + transformedDisclaimer: GQLTransformedDisclaimerContent; updated: Scalars['String']['output']; }; @@ -2610,6 +2611,11 @@ export type GQLTransformedArticleContentInput = { subjectId?: InputMaybe; }; +export type GQLTransformedDisclaimerContent = { + __typename?: 'TransformedDisclaimerContent'; + content: Scalars['String']['output']; +}; + export type GQLUpdatedFolder = { __typename?: 'UpdatedFolder'; name?: Maybe; @@ -2925,6 +2931,7 @@ export type GQLResolversTypes = { Transcription: ResolverTypeWrapper; TransformedArticleContent: ResolverTypeWrapper; TransformedArticleContentInput: GQLTransformedArticleContentInput; + TransformedDisclaimerContent: ResolverTypeWrapper; UpdatedFolder: ResolverTypeWrapper; UpdatedFolderResource: ResolverTypeWrapper; UptimeAlert: ResolverTypeWrapper; @@ -3108,6 +3115,7 @@ export type GQLResolversParentTypes = { Transcription: GQLTranscription; TransformedArticleContent: GQLTransformedArticleContent; TransformedArticleContentInput: GQLTransformedArticleContentInput; + TransformedDisclaimerContent: GQLTransformedDisclaimerContent; UpdatedFolder: GQLUpdatedFolder; UpdatedFolderResource: GQLUpdatedFolderResource; UptimeAlert: GQLUptimeAlert; @@ -3334,6 +3342,7 @@ export type GQLArticleResolvers>, ParentType, ContextType>; title?: Resolver; transformedContent?: Resolver>; + transformedDisclaimer?: Resolver; updated?: Resolver; __isTypeOf?: IsTypeOfResolverFn; }; @@ -4870,6 +4879,11 @@ export type GQLTransformedArticleContentResolvers; }; +export type GQLTransformedDisclaimerContentResolvers = { + content?: Resolver; + __isTypeOf?: IsTypeOfResolverFn; +}; + export type GQLUpdatedFolderResolvers = { name?: Resolver, ParentType, ContextType>; status?: Resolver, ParentType, ContextType>; @@ -5090,6 +5104,7 @@ export type GQLResolvers = { TopiclessArenaCategoryV2?: GQLTopiclessArenaCategoryV2Resolvers; Transcription?: GQLTranscriptionResolvers; TransformedArticleContent?: GQLTransformedArticleContentResolvers; + TransformedDisclaimerContent?: GQLTransformedDisclaimerContentResolvers; UpdatedFolder?: GQLUpdatedFolderResolvers; UpdatedFolderResource?: GQLUpdatedFolderResourceResolvers; UptimeAlert?: GQLUptimeAlertResolvers;