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

Add possibility to get html-version of node name #501

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 7 additions & 0 deletions src/resolvers/resourceResolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ export const resolvers = {
}
return defaultAvailability;
},
async name(node: GQLResource, _: any, context: ContextWithLoaders): Promise<String | null> {
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<GQLMeta | null> {
if (resource.contentUri?.startsWith("urn:learningpath")) {
const learningpath = await context.loaders.learningpathsLoader.load(
Expand Down
31 changes: 22 additions & 9 deletions src/resolvers/taxonomyResolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string | undefined> {
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<GQLLearningpath | null> {
if (node.contentUri?.startsWith("urn:learningpath")) {
Expand All @@ -111,9 +113,18 @@ export const resolvers = {
return null;
},
async meta(node: Node, _: any, context: ContextWithLoaders): Promise<GQLMeta | null> {
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<String | null> {
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;
gunnarvelle marked this conversation as resolved.
Show resolved Hide resolved
},
async children(
node: GQLTaxonomyEntity,
Expand All @@ -128,8 +139,10 @@ export const resolvers = {
return filterMissingArticles(entities, context);
},
async subjectpage(node: GQLTaxonomyEntity, __: any, context: ContextWithLoaders): Promise<ISubjectPageData | null> {
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<string[]> {
if (node.metadata?.grepCodes) {
Expand Down
7 changes: 7 additions & 0 deletions src/resolvers/topicResolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<String | null> {
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,
Expand Down
Loading