Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disclaimer to article #530

Merged
merged 2 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/api/articleApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,29 @@ export const fetchTransformedContent = async (
};
};

export const fetchTransformedDisclaimer = async (
article: IArticleV2DTO,
_params: GQLArticleTransformedContentArgs,
context: Context,
): Promise<GQLTransformedArticleContent> => {
if (!article.disclaimer?.disclaimer) return { content: "" };
katrinewi marked this conversation as resolved.
Show resolved Hide resolved
const params = _params.transformArgs ?? {};
const subject = params.subjectId;
const { content, metaData, visualElement, visualElementEmbed } = await transformArticle(
article.disclaimer.disclaimer,
context,
undefined,
{
subject,
draftConcept: params.draftConcept,
previewH5p: params.previewH5p,
absoluteUrl: params.absoluteUrl,
showVisualElement: params.showVisualElement === "true",
},
);
return { content: content ?? "", metaData, visualElement, visualElementEmbed: visualElementEmbed };
};

export async function fetchRelatedContent(
article: IArticleV2DTO,
params: { subjectId?: string },
Expand Down
9 changes: 8 additions & 1 deletion src/resolvers/articleResolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -139,6 +139,13 @@ export const resolvers = {
language(article: IArticleV2DTO): string {
return article.content.language;
},
async transformedDisclaimer(
article: IArticleV2DTO,
args: GQLArticleTransformedContentArgs,
context: ContextWithLoaders,
): Promise<GQLTransformedArticleContent> {
return fetchTransformedDisclaimer(article, args, context);
},
async transformedContent(
article: IArticleV2DTO,
args: GQLArticleTransformedContentArgs,
Expand Down
1 change: 1 addition & 0 deletions src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,7 @@ export const typeDefs = gql`
language: String!
transformedContent(transformArgs: TransformedArticleContentInput): TransformedArticleContent!
oembed: String
transformedDisclaimer(transformArgs: TransformedArticleContentInput): TransformedArticleContent!
}

input TransformedArticleContentInput {
Expand Down
7 changes: 7 additions & 0 deletions src/types/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ export type GQLArticle = {
tags?: Maybe<Array<Scalars['String']['output']>>;
title: Scalars['String']['output'];
transformedContent: GQLTransformedArticleContent;
transformedDisclaimer: GQLTransformedArticleContent;
updated: Scalars['String']['output'];
};

Expand All @@ -259,6 +260,11 @@ export type GQLArticleTransformedContentArgs = {
transformArgs?: InputMaybe<GQLTransformedArticleContentInput>;
};


export type GQLArticleTransformedDisclaimerArgs = {
transformArgs?: InputMaybe<GQLTransformedArticleContentInput>;
};

export type GQLArticleFolderResourceMeta = GQLFolderResourceMeta & {
__typename?: 'ArticleFolderResourceMeta';
description: Scalars['String']['output'];
Expand Down Expand Up @@ -3337,6 +3343,7 @@ export type GQLArticleResolvers<ContextType = any, ParentType extends GQLResolve
tags?: Resolver<Maybe<Array<GQLResolversTypes['String']>>, ParentType, ContextType>;
title?: Resolver<GQLResolversTypes['String'], ParentType, ContextType>;
transformedContent?: Resolver<GQLResolversTypes['TransformedArticleContent'], ParentType, ContextType, Partial<GQLArticleTransformedContentArgs>>;
transformedDisclaimer?: Resolver<GQLResolversTypes['TransformedArticleContent'], ParentType, ContextType, Partial<GQLArticleTransformedDisclaimerArgs>>;
updated?: Resolver<GQLResolversTypes['String'], ParentType, ContextType>;
__isTypeOf?: IsTypeOfResolverFn<ParentType, ContextType>;
};
Expand Down
Loading