mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
Merge pull request #4275 from omnivore-app/fix/include-content-if-requested
fix: select readable_content from library_item table if content is requested by search api
This commit is contained in:
commit
f12eb79a3f
3 changed files with 33 additions and 3 deletions
|
|
@ -99,7 +99,7 @@ import { Merge } from '../../util'
|
|||
import { analytics } from '../../utils/analytics'
|
||||
import { isSiteBlockedForParse } from '../../utils/blocked'
|
||||
import { enqueueBulkAction } from '../../utils/createTask'
|
||||
import { authorized } from '../../utils/gql-utils'
|
||||
import { authorized, isFieldInSelectionSet } from '../../utils/gql-utils'
|
||||
import {
|
||||
cleanUrl,
|
||||
errorHandler,
|
||||
|
|
@ -596,7 +596,7 @@ export const searchResolver = authorized<
|
|||
>,
|
||||
SearchError,
|
||||
QuerySearchArgs
|
||||
>(async (_obj, params, { uid }) => {
|
||||
>(async (_obj, params, { uid }, info) => {
|
||||
const startCursor = params.after || ''
|
||||
const first = Math.min(params.first || 10, 100) // limit to 100 items
|
||||
|
||||
|
|
@ -605,9 +605,14 @@ export const searchResolver = authorized<
|
|||
return { errorCodes: [SearchErrorCode.QueryTooLong] }
|
||||
}
|
||||
|
||||
const selectionSet = info.fieldNodes[0].selectionSet
|
||||
const isContentRequested = selectionSet
|
||||
? isFieldInSelectionSet(selectionSet, 'content')
|
||||
: false
|
||||
|
||||
const searchLibraryItemArgs = {
|
||||
includePending: true,
|
||||
includeContent: params.includeContent ?? true, // by default include content for offline use for now
|
||||
includeContent: params.includeContent || isContentRequested,
|
||||
includeDeleted: params.query?.includes('in:trash'),
|
||||
query: params.query,
|
||||
useFolders: params.query?.includes('use:folders'),
|
||||
|
|
|
|||
|
|
@ -577,6 +577,7 @@ export const functionResolvers = {
|
|||
pageType: (item: LibraryItem) => item.itemType,
|
||||
highlightsCount: (item: LibraryItem) => item.highlightAnnotations?.length,
|
||||
...readingProgressHandlers,
|
||||
content: (item: LibraryItem) => item.readableContent,
|
||||
},
|
||||
PageInfo: {
|
||||
async totalCount(
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
import { SelectionSetNode } from 'graphql'
|
||||
import { ResolverFn } from '../generated/graphql'
|
||||
import { Claims, ResolverContext } from '../resolvers/types'
|
||||
|
||||
|
|
@ -24,3 +25,26 @@ export function authorized<
|
|||
return { errorCodes: ['UNAUTHORIZED'] } as TError
|
||||
}
|
||||
}
|
||||
|
||||
export const isFieldInSelectionSet = (
|
||||
selectionSet: SelectionSetNode,
|
||||
fieldName: string
|
||||
) => {
|
||||
// recursively check if the field is in the selection set
|
||||
for (const selection of selectionSet.selections) {
|
||||
if (selection.kind === 'Field' && selection.name.value === fieldName) {
|
||||
return true
|
||||
}
|
||||
|
||||
if (
|
||||
(selection.kind === 'InlineFragment' || selection.kind === 'Field') &&
|
||||
selection.selectionSet
|
||||
) {
|
||||
if (isFieldInSelectionSet(selection.selectionSet, fieldName)) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue