Add contentReader to the typeAheadSearchResult
This commit is contained in:
@ -635,7 +635,7 @@ export const searchAsYouType = async (
|
||||
],
|
||||
},
|
||||
},
|
||||
_source: ['title', 'slug', 'siteName'],
|
||||
_source: ['title', 'slug', 'siteName', 'pageType'],
|
||||
size,
|
||||
},
|
||||
})
|
||||
|
||||
@ -2723,6 +2723,7 @@ export enum TypeaheadSearchErrorCode {
|
||||
|
||||
export type TypeaheadSearchItem = {
|
||||
__typename?: 'TypeaheadSearchItem';
|
||||
contentReader: ContentReader;
|
||||
id: Scalars['ID'];
|
||||
siteName?: Maybe<Scalars['String']>;
|
||||
slug: Scalars['String'];
|
||||
@ -5720,6 +5721,7 @@ export type TypeaheadSearchErrorResolvers<ContextType = ResolverContext, ParentT
|
||||
};
|
||||
|
||||
export type TypeaheadSearchItemResolvers<ContextType = ResolverContext, ParentType extends ResolversParentTypes['TypeaheadSearchItem'] = ResolversParentTypes['TypeaheadSearchItem']> = {
|
||||
contentReader?: Resolver<ResolversTypes['ContentReader'], ParentType, ContextType>;
|
||||
id?: Resolver<ResolversTypes['ID'], ParentType, ContextType>;
|
||||
siteName?: Resolver<Maybe<ResolversTypes['String']>, ParentType, ContextType>;
|
||||
slug?: Resolver<ResolversTypes['String'], ParentType, ContextType>;
|
||||
|
||||
@ -2080,6 +2080,7 @@ enum TypeaheadSearchErrorCode {
|
||||
}
|
||||
|
||||
type TypeaheadSearchItem {
|
||||
contentReader: ContentReader!
|
||||
id: ID!
|
||||
siteName: String
|
||||
slug: String!
|
||||
|
||||
@ -65,6 +65,7 @@ import {
|
||||
SortParams,
|
||||
TypeaheadSearchError,
|
||||
TypeaheadSearchErrorCode,
|
||||
TypeaheadSearchItem,
|
||||
TypeaheadSearchSuccess,
|
||||
UpdateReason,
|
||||
UpdatesSinceError,
|
||||
@ -993,7 +994,13 @@ export const typeaheadSearchResolver = authorized<
|
||||
},
|
||||
})
|
||||
|
||||
return { items: await searchAsYouType(claims.uid, query, first || undefined) }
|
||||
const results = await searchAsYouType(claims.uid, query, first || undefined)
|
||||
const items: TypeaheadSearchItem[] = results.map((r) => ({
|
||||
...r,
|
||||
contentReader: contentReaderForPageType(r.pageType),
|
||||
}))
|
||||
|
||||
return { items }
|
||||
})
|
||||
|
||||
export const updatesSinceResolver = authorized<
|
||||
|
||||
@ -8,7 +8,6 @@ import { getPageByParam } from '../elastic/pages'
|
||||
import {
|
||||
Article,
|
||||
ArticleHighlightsInput,
|
||||
ContentReader,
|
||||
Highlight,
|
||||
HighlightType,
|
||||
LinkShareInfo,
|
||||
|
||||
@ -1854,6 +1854,7 @@ const schema = gql`
|
||||
title: String!
|
||||
slug: String!
|
||||
siteName: String
|
||||
contentReader: ContentReader!
|
||||
}
|
||||
|
||||
union UpdatesSinceResult = UpdatesSinceSuccess | UpdatesSinceError
|
||||
|
||||
@ -2,6 +2,7 @@ import * as chai from 'chai'
|
||||
import { expect } from 'chai'
|
||||
import chaiString from 'chai-string'
|
||||
import 'mocha'
|
||||
import sinon from 'sinon'
|
||||
import { createPubSubClient } from '../../src/datalayer/pubsub'
|
||||
import { refreshIndex } from '../../src/elastic'
|
||||
import { addHighlightToPage } from '../../src/elastic/highlights'
|
||||
@ -30,6 +31,8 @@ import {
|
||||
UpdateReason,
|
||||
UploadFileStatus,
|
||||
} from '../../src/generated/graphql'
|
||||
import * as createTask from '../../src/utils/createTask'
|
||||
import * as uploads from '../../src/utils/uploads'
|
||||
import { createTestUser, deleteTestUser } from '../db'
|
||||
import {
|
||||
createTestElasticPage,
|
||||
@ -37,9 +40,6 @@ import {
|
||||
graphqlRequest,
|
||||
request,
|
||||
} from '../util'
|
||||
import sinon from 'sinon'
|
||||
import * as createTask from '../../src/utils/createTask'
|
||||
import * as uploads from '../../src/utils/uploads'
|
||||
|
||||
chai.use(chaiString)
|
||||
|
||||
@ -362,6 +362,7 @@ const typeaheadSearchQuery = (keyword: string) => {
|
||||
id
|
||||
slug
|
||||
title
|
||||
contentReader
|
||||
}
|
||||
}
|
||||
... on TypeaheadSearchError {
|
||||
@ -1105,6 +1106,7 @@ describe('Article API', () => {
|
||||
expect(res.body.data.typeaheadSearch.items[2].id).to.eq(pages[2].id)
|
||||
expect(res.body.data.typeaheadSearch.items[3].id).to.eq(pages[3].id)
|
||||
expect(res.body.data.typeaheadSearch.items[4].id).to.eq(pages[4].id)
|
||||
expect(res.body.data.typeaheadSearch.items[0].contentReader).to.eq('WEB')
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user