Skip to content

Commit

Permalink
Disclaimer to article
Browse files Browse the repository at this point in the history
  • Loading branch information
katrinewi committed Jan 6, 2025
1 parent 78a93a5 commit 9f08271
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 2 deletions.
15 changes: 14 additions & 1 deletion src/api/articleApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -46,6 +51,14 @@ export const fetchTransformedContent = async (
};
};

export const fetchTransformedDisclaimer = async (
article: IArticleV2DTO,
context: Context,
): Promise<GQLTransformedDisclaimerContent> => {
const { content } = await transformArticle(article.disclaimer?.disclaimer ?? "", context, undefined, {});
return { content: content ?? "" };
};

export async function fetchRelatedContent(
article: IArticleV2DTO,
params: { subjectId?: string },
Expand Down
10 changes: 9 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 All @@ -31,6 +31,7 @@ import {
GQLRelatedContent,
GQLVisualElementOembed,
GQLMetaImageWithCopyright,
GQLTransformedDisclaimerContent,
} from "../types/schema";

export const Query = {
Expand Down Expand Up @@ -139,6 +140,13 @@ export const resolvers = {
language(article: IArticleV2DTO): string {
return article.content.language;
},
async transformedDisclaimer(
article: IArticleV2DTO,
_: any,
context: ContextWithLoaders,
): Promise<GQLTransformedDisclaimerContent> {
return fetchTransformedDisclaimer(article, context);
},
async transformedContent(
article: IArticleV2DTO,
args: GQLArticleTransformedContentArgs,
Expand Down
5 changes: 5 additions & 0 deletions src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,7 @@ export const typeDefs = gql`
language: String!
transformedContent(transformArgs: TransformedArticleContentInput): TransformedArticleContent!
oembed: String
transformedDisclaimer: TransformedDisclaimerContent!
}
input TransformedArticleContentInput {
Expand All @@ -731,6 +732,10 @@ export const typeDefs = gql`
visualElementEmbed: ResourceEmbed
}
type TransformedDisclaimerContent {
content: String!
}
type EmbedVisualelement {
visualElement: VisualElement
}
Expand Down
15 changes: 15 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: GQLTransformedDisclaimerContent;
updated: Scalars['String']['output'];
};

Expand Down Expand Up @@ -2610,6 +2611,11 @@ export type GQLTransformedArticleContentInput = {
subjectId?: InputMaybe<Scalars['String']['input']>;
};

export type GQLTransformedDisclaimerContent = {
__typename?: 'TransformedDisclaimerContent';
content: Scalars['String']['output'];
};

export type GQLUpdatedFolder = {
__typename?: 'UpdatedFolder';
name?: Maybe<Scalars['String']['output']>;
Expand Down Expand Up @@ -2925,6 +2931,7 @@ export type GQLResolversTypes = {
Transcription: ResolverTypeWrapper<GQLTranscription>;
TransformedArticleContent: ResolverTypeWrapper<GQLTransformedArticleContent>;
TransformedArticleContentInput: GQLTransformedArticleContentInput;
TransformedDisclaimerContent: ResolverTypeWrapper<GQLTransformedDisclaimerContent>;
UpdatedFolder: ResolverTypeWrapper<GQLUpdatedFolder>;
UpdatedFolderResource: ResolverTypeWrapper<GQLUpdatedFolderResource>;
UptimeAlert: ResolverTypeWrapper<GQLUptimeAlert>;
Expand Down Expand Up @@ -3108,6 +3115,7 @@ export type GQLResolversParentTypes = {
Transcription: GQLTranscription;
TransformedArticleContent: GQLTransformedArticleContent;
TransformedArticleContentInput: GQLTransformedArticleContentInput;
TransformedDisclaimerContent: GQLTransformedDisclaimerContent;
UpdatedFolder: GQLUpdatedFolder;
UpdatedFolderResource: GQLUpdatedFolderResource;
UptimeAlert: GQLUptimeAlert;
Expand Down Expand Up @@ -3334,6 +3342,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['TransformedDisclaimerContent'], ParentType, ContextType>;
updated?: Resolver<GQLResolversTypes['String'], ParentType, ContextType>;
__isTypeOf?: IsTypeOfResolverFn<ParentType, ContextType>;
};
Expand Down Expand Up @@ -4870,6 +4879,11 @@ export type GQLTransformedArticleContentResolvers<ContextType = any, ParentType
__isTypeOf?: IsTypeOfResolverFn<ParentType, ContextType>;
};

export type GQLTransformedDisclaimerContentResolvers<ContextType = any, ParentType extends GQLResolversParentTypes['TransformedDisclaimerContent'] = GQLResolversParentTypes['TransformedDisclaimerContent']> = {
content?: Resolver<GQLResolversTypes['String'], ParentType, ContextType>;
__isTypeOf?: IsTypeOfResolverFn<ParentType, ContextType>;
};

export type GQLUpdatedFolderResolvers<ContextType = any, ParentType extends GQLResolversParentTypes['UpdatedFolder'] = GQLResolversParentTypes['UpdatedFolder']> = {
name?: Resolver<Maybe<GQLResolversTypes['String']>, ParentType, ContextType>;
status?: Resolver<Maybe<GQLResolversTypes['String']>, ParentType, ContextType>;
Expand Down Expand Up @@ -5090,6 +5104,7 @@ export type GQLResolvers<ContextType = any> = {
TopiclessArenaCategoryV2?: GQLTopiclessArenaCategoryV2Resolvers<ContextType>;
Transcription?: GQLTranscriptionResolvers<ContextType>;
TransformedArticleContent?: GQLTransformedArticleContentResolvers<ContextType>;
TransformedDisclaimerContent?: GQLTransformedDisclaimerContentResolvers<ContextType>;
UpdatedFolder?: GQLUpdatedFolderResolvers<ContextType>;
UpdatedFolderResource?: GQLUpdatedFolderResourceResolvers<ContextType>;
UptimeAlert?: GQLUptimeAlertResolvers<ContextType>;
Expand Down

0 comments on commit 9f08271

Please sign in to comment.