diff --git a/packages/api/src/resolvers/article/index.ts b/packages/api/src/resolvers/article/index.ts index 83ea4830b..8a4c8c8c3 100644 --- a/packages/api/src/resolvers/article/index.ts +++ b/packages/api/src/resolvers/article/index.ts @@ -46,7 +46,6 @@ import { TypeaheadSearchSuccess, UpdateReason, UpdatesSinceError, - UpdatesSinceErrorCode, UpdatesSinceSuccess, } from '../../generated/graphql' import { getColumns } from '../../repository' @@ -54,6 +53,7 @@ import { getInternalLabelWithColor } from '../../repository/label' import { libraryItemRepository } from '../../repository/library_item' import { userRepository } from '../../repository/user' import { createPageSaveRequest } from '../../services/create_page_save_request' +import { findHighlightsByLibraryItemId } from '../../services/highlights' import { addLabelsToLibraryItem, findLabelsByIds, @@ -661,28 +661,40 @@ export const searchResolver = authorized< libraryItems.pop() } - const edges = libraryItems.map((libraryItem) => { - if (params.includeContent && libraryItem.readableContent) { - // convert html to the requested format - const format = params.format || ArticleFormat.Html - try { - const converter = contentConverter(format) - if (converter) { - libraryItem.readableContent = converter( - libraryItem.readableContent, - libraryItem.highlights - ) - } - } catch (error) { - log.error('Error converting content', error) + const edges = await Promise.all( + libraryItems.map(async (libraryItem) => { + if ( + libraryItem.highlightAnnotations && + libraryItem.highlightAnnotations.length > 0 + ) { + libraryItem.highlights = await findHighlightsByLibraryItemId( + libraryItem.id, + uid + ) } - } - return { - node: libraryItemToSearchItem(libraryItem), - cursor: endCursor, - } - }) + if (params.includeContent && libraryItem.readableContent) { + // convert html to the requested format + const format = params.format || ArticleFormat.Html + try { + const converter = contentConverter(format) + if (converter) { + libraryItem.readableContent = converter( + libraryItem.readableContent, + libraryItem.highlights + ) + } + } catch (error) { + log.error('Error converting content', error) + } + } + + return { + node: libraryItemToSearchItem(libraryItem), + cursor: endCursor, + } + }) + ) return { edges, diff --git a/packages/api/src/resolvers/function_resolvers.ts b/packages/api/src/resolvers/function_resolvers.ts index 397867f17..365a32162 100644 --- a/packages/api/src/resolvers/function_resolvers.ts +++ b/packages/api/src/resolvers/function_resolvers.ts @@ -3,23 +3,21 @@ /* eslint-disable @typescript-eslint/no-unsafe-return */ /* eslint-disable @typescript-eslint/no-unsafe-member-access */ /* eslint-disable @typescript-eslint/explicit-module-boundary-types */ +import { createHmac } from 'crypto' import { Subscription } from '../entity/subscription' import { env } from '../env' import { Article, - Highlight, Label, PageType, Recommendation, SearchItem, User, } from '../generated/graphql' -import { findHighlightsByLibraryItemId } from '../services/highlights' import { findLabelsByLibraryItemId } from '../services/labels' import { findRecommendationsByLibraryItemId } from '../services/recommendation' import { findUploadFileById } from '../services/upload_file' import { - highlightDataToHighlight, isBase64Image, recommandationDataToRecommendation, validatedDate, @@ -128,7 +126,6 @@ import { markEmailAsItemResolver, recentEmailsResolver } from './recent_emails' import { recentSearchesResolver } from './recent_searches' import { WithDataSourcesContext } from './types' import { updateEmailResolver } from './user' -import { createHmac } from 'crypto' /* eslint-disable @typescript-eslint/naming-convention */ type ResultResolveType = { @@ -378,24 +375,6 @@ export const functionResolvers = { return item.siteIcon }, - async highlights( - item: { - id: string - highlights?: Highlight[] - highlightAnnotations?: string[] | null - }, - _: unknown, - ctx: WithDataSourcesContext - ) { - if (item.highlights) return item.highlights - - if (item.highlightAnnotations && item.highlightAnnotations.length > 0) { - const highlights = await findHighlightsByLibraryItemId(item.id, ctx.uid) - return highlights.map(highlightDataToHighlight) - } - - return [] - }, async labels( item: { id: string; labels?: Label[]; labelNames?: string[] | null }, _: unknown,