Skip to content

Commit

Permalink
fix: facet size can be configured / changed at query time (#796)
Browse files Browse the repository at this point in the history
fix #791
  • Loading branch information
joemcelroy committed Dec 5, 2020
1 parent 293cb9e commit beb567f
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docs/docs/guides-graphql-schema.md
Expand Up @@ -89,7 +89,7 @@ Used for facet interactions such as for search or for when displaying more facet
facet(
id: "actors",
query: "a", <-- query prefix to filter entries
page: { from: 0, size: 20 } <--- pagination options on facet
size: 20 <--- size options on facet
) {
id
label
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/searchkit-apollo-resolvers.md
Expand Up @@ -234,7 +234,7 @@ Supports facet values querying via the facet node. Great for UIs where you have
```gql
{
results(query: "heat", filters: []) {
facet(id: "type", query: "movi") {
facet(id: "type", query: "movi", size: 10) {
id
entries {
id
Expand Down
2 changes: 1 addition & 1 deletion packages/searchkit-apollo-resolvers/src/schema.ts
Expand Up @@ -28,7 +28,7 @@ export default gql`
summary: Summary
hits(page: PageInput, sortBy: String): HitResults
facets: [FacetSet]
facet(id: String!, query: String, page: PageInput): FacetSet
facet(id: String!, query: String, size: Float): FacetSet
}
type PageInfo {
Expand Down
75 changes: 75 additions & 0 deletions packages/searchkit-apollo-resolvers/tests/FacetResolver.test.ts
Expand Up @@ -88,5 +88,80 @@ describe('Facet Resolver', () => {
expect(response.body.data).toMatchSnapshot()
expect(response.status).toEqual(200)
})

it('Adjust size at query time', async () => {
setupTestServer(config)

const gql = `
{
results(query: "") {
facet(id: "writers", size: 20) {
id
type
label
display
entries {
id
count
label
}
}
}
}
`

const scope = nock('http://localhost:9200')
.post('/movies/_search')
.reply((uri, body: any) => {
expect(body.aggs.facet_bucket_all.aggs.writers.terms.size).toEqual(20)
return [200, FacetMock]
})

const response = await runQuery(gql)
expect(response.status).toEqual(200)
})

it('Adjust size at configuration', async () => {
setupTestServer({
...config,
facets: [
new RefinementSelectFacet({
id: 'writers',
field: 'writers.raw',
label: 'Writers',
multipleSelect: true,
size: 30
})
]
})

const gql = `
{
results(query: "") {
facet(id: "writers") {
id
type
label
display
entries {
id
count
label
}
}
}
}
`

const scope = nock('http://localhost:9200')
.post('/movies/_search')
.reply((uri, body: any) => {
expect(body.aggs.facet_bucket_all.aggs.writers.terms.size).toEqual(30)
return [200, FacetMock]
})

const response = await runQuery(gql)
expect(response.status).toEqual(200)
})
})
})

1 comment on commit beb567f

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deploy preview for searchkit-docs ready!

✅ Preview
https://searchkit-docs-mtk2tqdan.vercel.app

Built with commit beb567f.
This pull request is being automatically deployed with vercel-action

Please sign in to comment.