Skip to content
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
17 changes: 7 additions & 10 deletions src/api/articleApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ import { getArticleIdFromUrn } from "../utils/articleHelpers";
import { createAuthClient, resolveJsonOATS } from "../utils/openapi-fetch/utils";
import { transformArticle, transformVisualElement } from "./transformArticleApi";

interface ArticleParams {
articleId: string;
}

const client = createAuthClient<paths>();

export const fetchTransformedContent = async (
Expand Down Expand Up @@ -114,7 +110,7 @@ export async function fetchRelatedContent(
};
}
try {
const related = await fetchSimpleArticle(`urn:article:${rc}`, context);
const related = await fetchArticle(`urn:article:${rc}`, undefined, context);
const nodes = await context.loaders.nodesLoader.load({
contentURI: `urn:article:${related.id}`,
language: context.language,
Expand Down Expand Up @@ -144,10 +140,6 @@ export async function fetchRelatedContent(
return relatedContent as GQLRelatedContent[];
}

export async function fetchArticle(params: ArticleParams, context: Context): Promise<ArticleV2DTO> {
return await fetchSimpleArticle(params.articleId, context);
}

export async function fetchArticlesPage(
articleIds: number[],
context: Context,
Expand Down Expand Up @@ -189,7 +181,11 @@ export async function fetchArticles(articleIds: string[], context: Context): Pro
return articleIds.map((id) => articles.find((article) => article.id.toString() === id.toString()));
}

export async function fetchSimpleArticle(articleUrn: string, context: Context): Promise<ArticleV2DTO> {
export async function fetchArticle(
articleUrn: string,
revision: number | undefined,
context: Context,
): Promise<ArticleV2DTO> {
return await client
.GET("/article-api/v2/articles/{article_id}", {
params: {
Expand All @@ -198,6 +194,7 @@ export async function fetchSimpleArticle(articleUrn: string, context: Context):
},
query: {
language: context.language,
revision,
license: "all",
fallback: true,
},
Expand Down
4 changes: 2 additions & 2 deletions src/api/embedsApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import { getBrightcoveCopyright } from "../utils/brightcoveUtils";
import { CheerioEmbed, getEmbedsFromContent } from "../utils/getEmbedsFromContent";
import highlightCode from "../utils/highlightCode";
import parseMarkdown from "../utils/parseMarkdown";
import { fetchSimpleArticle } from "./articleApi";
import { fetchArticle } from "./articleApi";
import { fetchAudioV2 } from "./audioApi";
import { fetchEmbedConcept } from "./conceptApi";
import { fetchExternalOembed } from "./externalApi";
Expand Down Expand Up @@ -235,7 +235,7 @@ const relatedContentMeta: Fetch<RelatedContentMetaData> = async ({ embedData, co
const articleId = embedData.articleId;
if (typeof articleId === "string" || typeof articleId === "number") {
const [article, resources] = await Promise.all([
fetchSimpleArticle(`urn:article:${articleId}`, context),
fetchArticle(`urn:article:${articleId}`, undefined, context),
context.loaders.nodesLoader.load({
contentURI: `urn:article:${articleId}`,
language: context.language,
Expand Down
12 changes: 4 additions & 8 deletions src/resolvers/articleResolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@

import { ArticleV2DTO } from "@ndla/types-backend/article-api";
import { ConceptSummaryDTO } from "@ndla/types-backend/concept-api";
import { fetchArticle, fetchSubjectTopics, searchConcepts } from "../api";
import { fetchSubjectTopics, searchConcepts } from "../api";
import {
fetchTransformedContent,
fetchRelatedContent,
fetchTransformedDisclaimer,
fetchVisualElementEmbed,
fetchRevisions,
fetchArticle,
} from "../api/articleApi";
import { coreElements, fetchCrossSubjectTopicsByCode, grepSearch } from "../api/searchApi";
import { ndlaUrl } from "../config";
Expand All @@ -32,13 +33,8 @@ import {
} from "../types/schema";

export const Query = {
async article(_: any, { id }: GQLQueryArticleArgs, context: ContextWithLoaders): Promise<ArticleV2DTO> {
return fetchArticle(
{
articleId: id,
},
context,
);
async article(_: any, { id, revision }: GQLQueryArticleArgs, context: ContextWithLoaders): Promise<ArticleV2DTO> {
return fetchArticle(id, revision, context);
},
async revisions(_: any, { articleId }: GQLQueryRevisionsArgs, context: ContextWithLoaders): Promise<number[]> {
return fetchRevisions(articleId, context);
Expand Down
2 changes: 1 addition & 1 deletion src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1460,7 +1460,7 @@ export const typeDefs = gql`
nodeByArticleId(articleId: String, nodeId: String): Node
resource(id: String!, subjectId: String, topicId: String): Resource
articleResource(articleId: String, taxonomyId: String): Resource
article(id: String!): Article
article(id: String!, revision: Int): Article
subject(id: String!): Subject
subjectpage(id: Int!): SubjectPage
filmfrontpage: FilmFrontpage
Expand Down
1 change: 1 addition & 0 deletions src/types/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1469,6 +1469,7 @@ export type GQLQueryAllMyNdlaResourcesArgs = {

export type GQLQueryArticleArgs = {
id: Scalars['String']['input'];
revision?: InputMaybe<Scalars['Int']['input']>;
};


Expand Down