Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@searchkit/apollo-resolvers

Package Overview
Dependencies
Maintainers
2
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@searchkit/apollo-resolvers - npm Package Compare versions

Comparing version 3.0.0-canary.16 to 3.0.0-canary.17

18

CHANGELOG.md

@@ -6,2 +6,20 @@ # Change Log

# [3.0.0-canary.17](https://github.com/searchkit/searchkit/compare/v3.0.0-canary.12...v3.0.0-canary.17) (2020-12-05)
### Bug Fixes
* facet size can be configured / changed at query time ([#796](https://github.com/searchkit/searchkit/issues/796)) ([beb567f](https://github.com/searchkit/searchkit/commit/beb567f931ffe7013d11251e7d8beeaf4a473f35)), closes [#791](https://github.com/searchkit/searchkit/issues/791)
* fix apollo client cache issues ([da9191b](https://github.com/searchkit/searchkit/commit/da9191b4528fc72f73ffdbf3e1f92de3f88231fc)), closes [#797](https://github.com/searchkit/searchkit/issues/797)
### BREAKING CHANGES
* For all facets, id now is identifier. Apollo client network policy is now the
default cache-first strategy
# [3.0.0-canary.16](https://github.com/searchkit/searchkit/compare/v3.0.0-canary.12...v3.0.0-canary.16) (2020-12-04)

@@ -8,0 +26,0 @@

8

lib/core/FacetsFns.js

@@ -6,3 +6,3 @@ "use strict";

const subFilters = facets.reduce((subFilters, facet) => {
const facetSubFilter = queryManager.getFiltersById(facet.getId());
const facetSubFilter = queryManager.getFiltersById(facet.getIdentifier());
if (facetSubFilter) {

@@ -23,3 +23,3 @@ return [...subFilters, facet.getFilters(facetSubFilter)];

buckets.push({
name: `facet_bucket_${facet.getId()}`,
name: `facet_bucket_${facet.getIdentifier()}`,
aggs: [facet],

@@ -36,3 +36,3 @@ filters: facetsConfig.filter((f) => f !== facet)

const aggs = aggBuckets.reduce((sum, bucket) => {
const subAggs = bucket.aggs.reduce((subAggs, subAgg) => (Object.assign(Object.assign({}, subAggs), subAgg.getAggregation(overrides[subAgg.getId()]))), {});
const subAggs = bucket.aggs.reduce((subAggs, subAgg) => (Object.assign(Object.assign({}, subAggs), subAgg.getAggregation(overrides[subAgg.getIdentifier()]))), {});
return Object.assign(Object.assign({}, sum), { [bucket.name]: {

@@ -53,5 +53,5 @@ aggs: subAggs,

return facetsConfig.map((facet) => {
const aggFacetResponse = collapsedFacetAggsMap[facet.getId()];
const aggFacetResponse = collapsedFacetAggsMap[facet.getIdentifier()];
return facet.transformResponse(aggFacetResponse);
});
};
export declare type ValueFilter = {
id: string;
identifier: string;
value: string;
};
export declare type RangeFilter = {
id: string;
identifier: string;
value?: string;

@@ -12,3 +12,3 @@ min: number;

export declare type DateRangeFilter = {
id: string;
identifier: string;
value?: string;

@@ -15,0 +15,0 @@ dateMin: string;

@@ -23,3 +23,3 @@ "use strict";

return null;
const idFilters = this.filters.filter((filter) => filter.id === id);
const idFilters = this.filters.filter((filter) => filter.identifier === id);
return idFilters.length > 0 ? idFilters : null;

@@ -26,0 +26,0 @@ }

@@ -8,3 +8,3 @@ import { MixedFilter } from '../core/QueryManager';

excludeOwnFilters: boolean;
getId(): string;
getIdentifier(): string;
getLabel(): string;

@@ -11,0 +11,0 @@ getAggregation(overrides: FacetOptions): any;

import { DateRangeFilter } from '../core/QueryManager';
import { BaseFacet } from './BaseFacet';
interface DateRangeFacetConfig {
id: string;
identifier: string;
field: string;

@@ -21,3 +21,3 @@ label: string;

getLabel(): string;
getId(): string;
getIdentifier(): string;
getFilters(filters: Array<DateRangeFilter>): {

@@ -33,3 +33,3 @@ range: {

transformResponse(): {
id: string;
identifier: string;
label: string;

@@ -36,0 +36,0 @@ type: string;

@@ -11,4 +11,4 @@ "use strict";

}
getId() {
return this.config.id;
getIdentifier() {
return this.config.identifier;
}

@@ -23,3 +23,3 @@ getFilters(filters) {

return {
id: this.getId(),
identifier: this.getIdentifier(),
label: this.getLabel(),

@@ -26,0 +26,0 @@ type: 'DateRangeFacet',

import { RangeFilter } from '../core/QueryManager';
import { BaseFacet } from './BaseFacet';
interface RangeFacetConfig {
id: string;
identifier: string;
field: string;

@@ -21,3 +21,3 @@ label: string;

getLabel(): string;
getId(): string;
getIdentifier(): string;
getFilters(filters: Array<RangeFilter>): {

@@ -45,3 +45,3 @@ range: {

transformResponse(response: any): {
id: string;
identifier: string;
label: string;

@@ -48,0 +48,0 @@ display: string;

@@ -11,4 +11,4 @@ "use strict";

}
getId() {
return this.config.id;
getIdentifier() {
return this.config.identifier;
}

@@ -20,3 +20,3 @@ getFilters(filters) {

return {
[this.config.id]: {
[this.getIdentifier()]: {
histogram: {

@@ -33,3 +33,3 @@ field: this.config.field,

return {
id: this.getId(),
identifier: this.getIdentifier(),
label: this.getLabel(),

@@ -39,3 +39,3 @@ display: this.config.display || 'RangeSliderFacet',

entries: response.buckets.map((entry) => ({
id: `${this.getId()}_${entry.key}`,
id: `${this.getIdentifier()}_${entry.key}`,
label: entry.key,

@@ -42,0 +42,0 @@ count: entry.doc_count

import { ValueFilter } from '../core/QueryManager';
import { BaseFacet, FacetOptions } from './BaseFacet';
interface RefinementSelectFacetConfig {
id: string;
identifier: string;
field: string;

@@ -16,3 +16,3 @@ size?: number;

getLabel(): string;
getId(): string;
getIdentifier(): string;
getFilters(filters: Array<ValueFilter>): {

@@ -37,3 +37,3 @@ bool: {

transformResponse(response: any): {
id: string;
identifier: string;
label: string;

@@ -40,0 +40,0 @@ display: string;

@@ -13,4 +13,4 @@ "use strict";

}
getId() {
return this.config.id;
getIdentifier() {
return this.config.identifier;
}

@@ -27,3 +27,3 @@ getFilters(filters) {

return {
[this.config.id]: {
[this.getIdentifier()]: {
terms: Object.assign({ field: this.config.field, size: (overrides === null || overrides === void 0 ? void 0 : overrides.size) || this.config.size || 5 }, ((overrides === null || overrides === void 0 ? void 0 : overrides.query) ? { include: utils_1.createRegexQuery(overrides.query) } : {}))

@@ -35,3 +35,3 @@ }

return {
id: this.getId(),
identifier: this.getIdentifier(),
label: this.getLabel(),

@@ -41,3 +41,3 @@ display: this.config.display || 'ListFacet',

entries: response.buckets.map((entry) => ({
id: `${this.getId()}_${entry.key}`,
id: `${this.getIdentifier()}_${entry.key}`,
label: entry.key,

@@ -44,0 +44,0 @@ count: entry.doc_count

export interface FacetResolverParameters {
id: string;
identifier: string;
query: string;

@@ -4,0 +4,0 @@ size: number;

@@ -17,3 +17,3 @@ "use strict";

const skRequest = ctx.searchkit.skRequest;
const facet = config.facets && config.facets.find((facet) => facet.getId() === parameters.id);
const facet = config.facets && config.facets.find((facet) => facet.getIdentifier() === parameters.identifier);
if (!facet)

@@ -23,3 +23,3 @@ return null;

const aggs = FacetsFns_1.getAggregationsFromFacets(queryManager, {
[facet.getId()]: {
[facet.getIdentifier()]: {
query: parameters.query,

@@ -26,0 +26,0 @@ size: parameters.size

@@ -35,3 +35,5 @@ "use strict";

});
const hitsTotal = (typeof hits.total.value === "number" ? hits.total.value : hits.total);
const hitsTotal = (typeof hits.total.value === 'number'
? hits.total.value
: hits.total);
return {

@@ -38,0 +40,0 @@ items: hits.hits.map((hit) => ({

@@ -31,3 +31,3 @@ import { SearchkitConfig } from './ResultsResolver';

label: string;
id: string;
identifier: string;
value: string;

@@ -34,0 +34,0 @@ }[];

@@ -12,3 +12,3 @@ declare const _default: (parent: any, {}: {}, ctx: any) => Promise<{

label: string;
id: string;
identifier: string;
value: string;

@@ -15,0 +15,0 @@ }[];

@@ -19,3 +19,5 @@ "use strict";

return {
total: typeof results.hits.total.value === "number" ? results.hits.total.value : results.hits.total,
total: typeof results.hits.total.value === 'number'
? results.hits.total.value
: results.hits.total,
query: queryManager.getQuery(),

@@ -27,6 +29,6 @@ sortOptions: config.sortOptions.map((sortOption) => ({

appliedFilters: queryManager.getFilters().map((filterSet) => {
const facetConfig = config.facets.find((facet) => facet.getId() === filterSet.id);
const facetConfig = config.facets.find((facet) => facet.getIdentifier() === filterSet.identifier);
return {
label: facetConfig.getLabel(),
id: facetConfig.getId(),
identifier: facetConfig.getIdentifier(),
value: filterSet.value

@@ -33,0 +35,0 @@ };

@@ -9,3 +9,3 @@ "use strict";

type Hit {
id: String
id: ID!
fields: HitFields

@@ -15,8 +15,8 @@ }

type SortOption {
id: String
label: String
id: ID!
label: String!
}
type Summary {
total: Float
total: Float!
appliedFilters: [SelectedFilter]

@@ -28,4 +28,4 @@ query: String

type SelectedFilter {
id: String
label: String
identifier: String!
label: String!
value: String

@@ -38,3 +38,3 @@ }

facets: [FacetSet]
facet(id: String!, query: String, page: PageInput): FacetSet
facet(identifier: String!, query: String, size: Float): FacetSet
}

@@ -62,3 +62,3 @@

input FiltersSet {
id: String
identifier: String!
value: String

@@ -72,3 +72,3 @@ min: Float

interface FacetSet {
id: String
identifier: String
label: String

@@ -81,3 +81,3 @@ type: String

type FacetSetEntry {
id: String
id: ID!
label: String

@@ -89,3 +89,3 @@ count: Float

type RefinementSelectFacet implements FacetSet {
id: String
identifier: String
label: String

@@ -98,3 +98,3 @@ type: String

type RangeFacet implements FacetSet {
id: String
identifier: String
label: String

@@ -107,3 +107,3 @@ type: String

type DateRangeFacet implements FacetSet {
id: String
identifier: String
label: String

@@ -110,0 +110,0 @@ type: String

{
"name": "@searchkit/apollo-resolvers",
"version": "3.0.0-canary.16",
"version": "3.0.0-canary.17",
"main": "lib/index.js",

@@ -45,3 +45,3 @@ "author": "Joseph McElroy <phoey1@gmail.com>",

},
"gitHead": "729f50f60415e8665c369e96b93d2c5d4bf81d94"
"gitHead": "3aa1385da6d9d338e951e89b950a3963f7931392"
}

@@ -16,1 +16,125 @@ # <a href="https://searchkit.co/">Searchkit</a>

[https://searchkit.co/docs/reference/apollo-resolvers](https://searchkit.co/docs/reference/apollo-resolvers)
### Quick Intro
From a configuration
```js
const searchkitConfig = {
host: 'https://localhost:9200',
index: 'movies',
hits: {
fields: [ 'title', 'plot', 'poster' ]
},
query: new MultiMatchQuery({
fields: [ 'plot','title^4']
}),
facets: [
new RefinementSelectFacet({
field: 'type.raw',
identifier: 'type',
label: 'Type'
}),
new RefinementSelectFacet({
field: 'writers.raw',
identifier: 'writers',
label: 'Writers',
multipleSelect: true
}),
new RangeFacet({
field: 'metaScore',
identifier: 'metascore',
label: 'Metascore',
range: {
min: 0,
max: 100,
interval: 5
}
}),
new DateRangeFacet({
field: 'released',
identifier: 'released',
label: 'Released'
})
]
}
```
Will provide a GraphQL API where you can perform queries like:
#### Simple Hits
[Try it out](https://demo.searchkit.co/api/graphql)
```graphql
{
results(query: "heat") {
hits {
items {
id
fields {
title
}
}
}
}
}
```
#### Facets
[Try it out](https://demo.searchkit.co/api/graphql)
```graphql
{
results(query: "heat") {
facets {
id
label
type
display
entries {
id
label
count
}
}
hits {
items {
id
fields {
title
}
}
}
}
}
```
#### Filtering
[Try it out](https://demo.searchkit.co/api/graphql)
```graphql
{
results(filters: [{id: "type", value: "Movie"}, {id: "metascore", min: 30}]) {
facets {
identifier
label
type
display
entries {
id
label
count
}
}
hits {
items {
id
fields {
title
}
}
}
}
}
```
See [Schema Query Guide](https://searchkit.co/docs/guides/graphql-schema-queries-cheatsheet) for more examples.

@@ -9,13 +9,40 @@ import { filterTransform, getAggregationsFromFacets, getFacetsFromResponse } from '../FacetsFns'

it('create aggregations for one facet ', () => {
const qm = new QueryManager([{ id: 'test', value: 'testValue' }], '')
const facetConfig = [new RefinementSelectFacet({ field: 'test', id: 'test', label: 'Test' })]
const qm = new QueryManager([{ identifier: 'test', value: 'testValue' }], '')
const facetConfig = [
new RefinementSelectFacet({ field: 'test', identifier: 'test', label: 'Test' })
]
expect(getAggregationsFromFacets(qm, {}, facetConfig)).toEqual({
aggs: {
facet_bucket_all: {
aggs: { test: { terms: { field: 'test', size: 5 } } },
filter: { bool: { must: [{ bool: { must: [{ term: { test: 'testValue' } }] } }] } }
}
expect(getAggregationsFromFacets(qm, {}, facetConfig)).toMatchInlineSnapshot(`
Object {
"aggs": Object {
"facet_bucket_all": Object {
"aggs": Object {
"test": Object {
"terms": Object {
"field": "test",
"size": 5,
},
},
},
"filter": Object {
"bool": Object {
"must": Array [
Object {
"bool": Object {
"must": Array [
Object {
"term": Object {
"test": "testValue",
},
},
],
},
},
],
},
},
},
},
}
})
`)
})

@@ -26,4 +53,4 @@

[
{ id: 'test', value: 'testValue' },
{ id: 'test3', value: 'testValue' }
{ identifier: 'test', value: 'testValue' },
{ identifier: 'test3', value: 'testValue' }
],

@@ -33,7 +60,7 @@ ''

const facetConfig = [
new RefinementSelectFacet({ field: 'test', id: 'test', label: 'Test' }),
new RefinementSelectFacet({ field: 'test2', id: 'test2', label: 'Test 2' }),
new RefinementSelectFacet({ field: 'test', identifier: 'test', label: 'Test' }),
new RefinementSelectFacet({ field: 'test2', identifier: 'test2', label: 'Test 2' }),
new RefinementSelectFacet({
field: 'test3',
id: 'test3',
identifier: 'test3',
label: 'Test 3',

@@ -169,7 +196,7 @@ multipleSelect: true

const facetConfig = [
new RefinementSelectFacet({ field: 'test', id: 'test', label: 'Test 1' }),
new RefinementSelectFacet({ field: 'test2', id: 'test2', label: 'Test 2' }),
new RefinementSelectFacet({ field: 'test', identifier: 'test', label: 'Test 1' }),
new RefinementSelectFacet({ field: 'test2', identifier: 'test2', label: 'Test 2' }),
new RefinementSelectFacet({
field: 'test3',
id: 'test3',
identifier: 'test3',
label: 'Test 3',

@@ -187,3 +214,3 @@ multipleSelect: true

],
id: 'test',
identifier: 'test',
label: 'Test 1',

@@ -201,3 +228,3 @@ display: 'ListFacet',

],
id: 'test2',
identifier: 'test2',
label: 'Test 2',

@@ -215,3 +242,3 @@ display: 'ListFacet',

],
id: 'test3',
identifier: 'test3',
label: 'Test 3',

@@ -227,11 +254,11 @@ display: 'ListFacet',

it('should get filter for test', () => {
const qm = new QueryManager([{ id: 'test', value: 'testValue' }], '')
const qm = new QueryManager([{ identifier: 'test', value: 'testValue' }], '')
const facetConfig = [
new RefinementSelectFacet({
field: 'test',
id: 'test',
identifier: 'test',
label: 'Test',
multipleSelect: true
}),
new RefinementSelectFacet({ field: 'test2', id: 'test2', label: 'Test 2' })
new RefinementSelectFacet({ field: 'test2', identifier: 'test2', label: 'Test 2' })
]

@@ -246,4 +273,4 @@ expect(filterTransform(qm, facetConfig)).toEqual({

[
{ id: 'test', value: 'testValue' },
{ id: 'test2', value: 'testValue2' }
{ identifier: 'test', value: 'testValue' },
{ identifier: 'test2', value: 'testValue2' }
],

@@ -255,7 +282,7 @@ ''

field: 'test',
id: 'test',
identifier: 'test',
label: 'Test',
multipleSelect: true
}),
new RefinementSelectFacet({ field: 'test2', id: 'test2', label: 'Test 2' })
new RefinementSelectFacet({ field: 'test2', identifier: 'test2', label: 'Test 2' })
]

@@ -275,4 +302,4 @@ expect(filterTransform(qm, facetConfig)).toEqual({

[
{ id: 'test', value: 'testValue' },
{ id: 'test2', value: 'testValue2' }
{ identifier: 'test', value: 'testValue' },
{ identifier: 'test2', value: 'testValue2' }
],

@@ -284,3 +311,3 @@ ''

field: 'test',
id: 'test',
identifier: 'test',
label: 'Test',

@@ -287,0 +314,0 @@ multipleSelect: true

@@ -13,6 +13,6 @@ import QueryManager from '../QueryManager'

it('query manager with test filter', () => {
const qm = new QueryManager([{ id: 'test', value: 'bob' }], null)
const qm = new QueryManager([{ identifier: 'test', value: 'bob' }], null)
expect(qm.hasFilters()).toEqual(true)
expect(qm.getFilters()).toEqual([{ id: 'test', value: 'bob' }])
expect(qm.getFiltersById('test')).toEqual([{ id: 'test', value: 'bob' }])
expect(qm.getFilters()).toEqual([{ identifier: 'test', value: 'bob' }])
expect(qm.getFiltersById('test')).toEqual([{ identifier: 'test', value: 'bob' }])
expect(qm.getFiltersById('nomatch')).toBeNull()

@@ -19,0 +19,0 @@ })

@@ -7,3 +7,3 @@ import { BaseFacet } from '../facets/BaseFacet'

const subFilters = facets.reduce((subFilters, facet) => {
const facetSubFilter = queryManager.getFiltersById(facet.getId())
const facetSubFilter = queryManager.getFiltersById(facet.getIdentifier())
if (facetSubFilter) {

@@ -31,3 +31,3 @@ return [...subFilters, facet.getFilters(facetSubFilter)]

buckets.push({
name: `facet_bucket_${facet.getId()}`,
name: `facet_bucket_${facet.getIdentifier()}`,
aggs: [facet],

@@ -49,3 +49,3 @@ filters: facetsConfig.filter((f) => f !== facet)

...subAggs,
...subAgg.getAggregation(overrides[subAgg.getId()])
...subAgg.getAggregation(overrides[subAgg.getIdentifier()])
}),

@@ -91,5 +91,5 @@ {}

return facetsConfig.map((facet) => {
const aggFacetResponse = collapsedFacetAggsMap[facet.getId()]
const aggFacetResponse = collapsedFacetAggsMap[facet.getIdentifier()]
return facet.transformResponse(aggFacetResponse)
})
}
export type ValueFilter = {
id: string
identifier: string
value: string

@@ -7,3 +7,3 @@ }

export type RangeFilter = {
id: string
identifier: string
value?: string

@@ -15,3 +15,3 @@ min: number

export type DateRangeFilter = {
id: string
identifier: string
value?: string

@@ -45,5 +45,5 @@ dateMin: string

if (!this.hasFilters()) return null
const idFilters = this.filters.filter((filter) => filter.id === id)
const idFilters = this.filters.filter((filter) => filter.identifier === id)
return idFilters.length > 0 ? idFilters : null
}
}
import RefinementSelectFacet from '../RefinementSelectFacet'
describe('Multiple Select Facet', () => {
const msf = new RefinementSelectFacet({ id: 'testId', label: 'Test', field: 'testField' })
const msf = new RefinementSelectFacet({ identifier: 'testId', label: 'Test', field: 'testField' })

@@ -9,12 +9,36 @@ it('getFilter', () => {

msf.getFilters([
{ id: 'test', value: 'testValue' },
{ id: 'test', value: 'testValue2' }
{ identifier: 'test', value: 'testValue' },
{ identifier: 'test', value: 'testValue2' }
])
).toEqual({
bool: { must: [{ term: { testField: 'testValue' } }, { term: { testField: 'testValue2' } }] }
})
).toMatchInlineSnapshot(`
Object {
"bool": Object {
"must": Array [
Object {
"term": Object {
"testField": "testValue",
},
},
Object {
"term": Object {
"testField": "testValue2",
},
},
],
},
}
`)
})
it('getAggregation', () => {
expect(msf.getAggregation(null)).toEqual({ testId: { terms: { field: 'testField', size: 5 } } })
expect(msf.getAggregation(null)).toMatchInlineSnapshot(`
Object {
"testId": Object {
"terms": Object {
"field": "testField",
"size": 5,
},
},
}
`)
})

@@ -30,13 +54,25 @@

})
).toEqual({
entries: [
{ count: 1, id: 'testId_bla', label: 'bla' },
{ count: 1, id: 'testId_da', label: 'da' }
],
id: 'testId',
label: 'Test',
display: 'ListFacet',
type: 'RefinementSelectFacet'
})
).toMatchInlineSnapshot(
`
Object {
"display": "ListFacet",
"entries": Array [
Object {
"count": 1,
"id": "testId_bla",
"label": "bla",
},
Object {
"count": 1,
"id": "testId_da",
"label": "da",
},
],
"identifier": "testId",
"label": "Test",
"type": "RefinementSelectFacet",
}
`
)
})
})

@@ -10,3 +10,3 @@ import { MixedFilter } from '../core/QueryManager'

excludeOwnFilters: boolean
getId(): string
getIdentifier(): string
getLabel(): string

@@ -13,0 +13,0 @@ getAggregation(overrides: FacetOptions): any

@@ -5,3 +5,3 @@ import { DateRangeFilter } from '../core/QueryManager'

interface DateRangeFacetConfig {
id: string
identifier: string
field: string

@@ -27,4 +27,4 @@ label: string

getId() {
return this.config.id
getIdentifier() {
return this.config.identifier
}

@@ -42,3 +42,3 @@

return {
id: this.getId(),
identifier: this.getIdentifier(),
label: this.getLabel(),

@@ -45,0 +45,0 @@ type: 'DateRangeFacet',

@@ -5,3 +5,3 @@ import { RangeFilter } from '../core/QueryManager'

interface RangeFacetConfig {
id: string
identifier: string
field: string

@@ -27,4 +27,4 @@ label: string

getId(): string {
return this.config.id
getIdentifier(): string {
return this.config.identifier
}

@@ -38,3 +38,3 @@

return {
[this.config.id]: {
[this.getIdentifier()]: {
histogram: {

@@ -52,3 +52,3 @@ field: this.config.field,

return {
id: this.getId(),
identifier: this.getIdentifier(),
label: this.getLabel(),

@@ -58,3 +58,3 @@ display: this.config.display || 'RangeSliderFacet',

entries: response.buckets.map((entry) => ({
id: `${this.getId()}_${entry.key}`,
id: `${this.getIdentifier()}_${entry.key}`,
label: entry.key,

@@ -61,0 +61,0 @@ count: entry.doc_count

@@ -6,3 +6,3 @@ import { ValueFilter } from '../core/QueryManager'

interface RefinementSelectFacetConfig {
id: string
identifier: string
field: string

@@ -25,4 +25,4 @@ size?: number

getId() {
return this.config.id
getIdentifier() {
return this.config.identifier
}

@@ -41,3 +41,3 @@

return {
[this.config.id]: {
[this.getIdentifier()]: {
terms: {

@@ -54,3 +54,3 @@ field: this.config.field,

return {
id: this.getId(),
identifier: this.getIdentifier(),
label: this.getLabel(),

@@ -60,3 +60,3 @@ display: this.config.display || 'ListFacet',

entries: response.buckets.map((entry) => ({
id: `${this.getId()}_${entry.key}`,
id: `${this.getIdentifier()}_${entry.key}`,
label: entry.key,

@@ -63,0 +63,0 @@ count: entry.doc_count

@@ -7,3 +7,3 @@ import SearchkitRequest from '../core/SearchkitRequest'

export interface FacetResolverParameters {
id: string
identifier: string
query: string

@@ -18,3 +18,4 @@ size: number

const facet = config.facets && config.facets.find((facet) => facet.getId() === parameters.id)
const facet =
config.facets && config.facets.find((facet) => facet.getIdentifier() === parameters.identifier)
if (!facet) return null

@@ -26,3 +27,3 @@

{
[facet.getId()]: {
[facet.getIdentifier()]: {
query: parameters.query,

@@ -29,0 +30,0 @@ size: parameters.size

@@ -38,3 +38,5 @@ import SearchkitRequest from '../core/SearchkitRequest'

const hitsTotal = (typeof hits.total.value === "number" ? hits.total.value : hits.total) as number
const hitsTotal = (typeof hits.total.value === 'number'
? hits.total.value
: hits.total) as number

@@ -41,0 +43,0 @@ return {

@@ -13,3 +13,6 @@ import SearchkitRequest from '../core/SearchkitRequest'

return {
total: typeof results.hits.total.value === "number" ? results.hits.total.value : results.hits.total,
total:
typeof results.hits.total.value === 'number'
? results.hits.total.value
: results.hits.total,
query: queryManager.getQuery(),

@@ -21,6 +24,8 @@ sortOptions: config.sortOptions.map((sortOption) => ({

appliedFilters: queryManager.getFilters().map((filterSet) => {
const facetConfig = config.facets.find((facet) => facet.getId() === filterSet.id)
const facetConfig = config.facets.find(
(facet) => facet.getIdentifier() === filterSet.identifier
)
return {
label: facetConfig.getLabel(),
id: facetConfig.getId(),
identifier: facetConfig.getIdentifier(),
value: filterSet.value

@@ -27,0 +32,0 @@ }

@@ -5,3 +5,3 @@ import gql from 'graphql-tag'

type Hit {
id: String
id: ID!
fields: HitFields

@@ -11,8 +11,8 @@ }

type SortOption {
id: String
label: String
id: ID!
label: String!
}
type Summary {
total: Float
total: Float!
appliedFilters: [SelectedFilter]

@@ -24,4 +24,4 @@ query: String

type SelectedFilter {
id: String
label: String
identifier: String!
label: String!
value: String

@@ -34,3 +34,3 @@ }

facets: [FacetSet]
facet(id: String!, query: String, page: PageInput): FacetSet
facet(identifier: String!, query: String, size: Float): FacetSet
}

@@ -58,3 +58,3 @@

input FiltersSet {
id: String
identifier: String!
value: String

@@ -68,3 +68,3 @@ min: Float

interface FacetSet {
id: String
identifier: String
label: String

@@ -77,3 +77,3 @@ type: String

type FacetSetEntry {
id: String
id: ID!
label: String

@@ -85,3 +85,3 @@ count: Float

type RefinementSelectFacet implements FacetSet {
id: String
identifier: String
label: String

@@ -94,3 +94,3 @@ type: String

type RangeFacet implements FacetSet {
id: String
identifier: String
label: String

@@ -103,3 +103,3 @@ type: String

type DateRangeFacet implements FacetSet {
id: String
identifier: String
label: String

@@ -106,0 +106,0 @@ type: String

@@ -0,1 +1,2 @@

import nock from 'nock'
import { SearchkitConfig } from '../src/resolvers/ResultsResolver'

@@ -5,3 +6,2 @@ import { MultiMatchQuery } from '../src'

import { setupTestServer, callQuery } from './support/helper'
import nock from 'nock'
import FacetMock from './__mock-data__/FacetResolver/Facet.json'

@@ -25,3 +25,3 @@

new RefinementSelectFacet({
id: 'writers',
identifier: 'writers',
field: 'writers.raw',

@@ -40,4 +40,4 @@ label: 'Writers',

results(query: "") {
facet(id: "writers", query: "te") {
id
facet(identifier: "writers", query: "te") {
identifier
type

@@ -94,3 +94,78 @@ label

})
it('Adjust size at query time', async () => {
setupTestServer(config)
const gql = `
{
results(query: "") {
facet(identifier: "writers", size: 20) {
identifier
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({
identifier: 'writers',
field: 'writers.raw',
label: 'Writers',
multipleSelect: true,
size: 30
})
]
})
const gql = `
{
results(query: "") {
facet(identifier: "writers") {
identifier
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)
})
})
})

@@ -0,1 +1,2 @@

import nock from 'nock'
import { SearchkitConfig } from '../src/resolvers/ResultsResolver'

@@ -5,3 +6,2 @@ import { MultiMatchQuery } from '../src'

import { setupTestServer, callQuery } from './support/helper'
import nock from 'nock'
import HitsMock from './__mock-data__/FacetsResolver/results.json'

@@ -25,3 +25,3 @@

new RefinementSelectFacet({
id: 'writers',
identifier: 'writers',
field: 'writers.raw',

@@ -32,5 +32,5 @@ label: 'Writers',

}),
new RefinementSelectFacet({ id: 'actors', field: 'actors.raw', label: 'Actors' }),
new RefinementSelectFacet({ id: 'type', field: 'type.raw', label: 'Type' }),
new RefinementSelectFacet({ id: 'genres', field: 'genres.raw', label: 'Genres' })
new RefinementSelectFacet({ identifier: 'actors', field: 'actors.raw', label: 'Actors' }),
new RefinementSelectFacet({ identifier: 'type', field: 'type.raw', label: 'Type' }),
new RefinementSelectFacet({ identifier: 'genres', field: 'genres.raw', label: 'Genres' })
]

@@ -51,3 +51,3 @@ }

facets {
id
identifier
type

@@ -136,4 +136,4 @@ label

filters: [
{ id: "writers", value: "Damon Lindelof" },
{ id: "actors", value: "Damon Lindelof" },
{ identifier: "writers", value: "Damon Lindelof" },
{ identifier: "actors", value: "Damon Lindelof" },
]

@@ -147,3 +147,3 @@ ) {

facets {
id
identifier
type

@@ -150,0 +150,0 @@ label

@@ -0,5 +1,5 @@

import nock from 'nock'
import { SearchkitConfig } from '../src/resolvers/ResultsResolver'
import { MultiMatchQuery } from '../src'
import { setupTestServer, callQuery } from './support/helper'
import nock from 'nock'
import HitsMock from './__mock-data__/HitResolver/Hits.json'

@@ -175,3 +175,2 @@

})
})

@@ -0,5 +1,5 @@

import nock from 'nock'
import { SearchkitConfig } from '../src/resolvers/ResultsResolver'
import { MultiMatchQuery } from '../src'
import { setupTestServer, callQuery } from './support/helper'
import nock from 'nock'
import HitsMock from './__mock-data__/HitResolver/Hits.json'

@@ -11,3 +11,2 @@ import NoHitsES7Mock from './__mock-data__/HitResolver/NoHitsES7.json'

describe('should return as expected', () => {
const config: SearchkitConfig = {

@@ -49,3 +48,2 @@ host: 'http://localhost:9200',

it('Pagination results', async () => {
setupTestServer(config)

@@ -55,5 +53,3 @@

.post('/movies/_search')
.reply((uri, body) => {
return [200, HitsMock]
})
.reply((uri, body) => [200, HitsMock])

@@ -70,3 +66,3 @@ let response = await runQuery()

`)
expect(response.body.data.results.hits.items.length).toEqual(10)
expect(response.body.data.results.hits.items).toHaveLength(10)
expect(response.status).toEqual(200)

@@ -76,5 +72,3 @@

.post('/movies/_search')
.reply((uri, body) => {
return [200, HitsMock]
})
.reply((uri, body) => [200, HitsMock])

@@ -95,3 +89,2 @@ response = await runQuery({ from: 20, size: 10 })

it('No Results es7', async () => {
setupTestServer(config)

@@ -101,7 +94,5 @@

.post('/movies/_search')
.reply((uri, body) => {
return [200, NoHitsES7Mock]
})
.reply((uri, body) => [200, NoHitsES7Mock])
let response = await runQuery()
const response = await runQuery()
expect(response.body.data.results.hits.page).toMatchInlineSnapshot(`

@@ -116,3 +107,3 @@ Object {

`)
expect(response.body.data.results.hits.items.length).toEqual(0)
expect(response.body.data.results.hits.items).toHaveLength(0)
expect(response.body.data.results.summary.total).toEqual(0)

@@ -123,3 +114,2 @@ expect(response.status).toEqual(200)

it('No Results es6', async () => {
setupTestServer(config)

@@ -129,7 +119,5 @@

.post('/movies/_search')
.reply((uri, body) => {
return [200, NoHitsMock]
})
.reply((uri, body) => [200, NoHitsMock])
let response = await runQuery()
const response = await runQuery()
expect(response.body.data.results.hits.page).toMatchInlineSnapshot(`

@@ -145,3 +133,3 @@ Object {

expect(response.body.data.results.summary.total).toEqual(0)
expect(response.body.data.results.hits.items.length).toEqual(0)
expect(response.body.data.results.hits.items).toHaveLength(0)
expect(response.status).toEqual(200)

@@ -148,0 +136,0 @@ })

@@ -0,1 +1,2 @@

import nock from 'nock'
import { SearchkitConfig } from '../src/resolvers/ResultsResolver'

@@ -5,3 +6,2 @@ import { MultiMatchQuery } from '../src'

import { setupTestServer, callQuery } from './support/helper'
import nock from 'nock'
import HitsMock from './__mock-data__/HitResolver/Hits.json'

@@ -29,3 +29,3 @@

new RefinementSelectFacet({
id: 'writers',
identifier: 'writers',
field: 'writers.raw',

@@ -35,5 +35,5 @@ label: 'Writers',

}),
new RefinementSelectFacet({ id: 'actors', field: 'actors.raw', label: 'Actors' }),
new RefinementSelectFacet({ id: 'type', field: 'type.raw', label: 'Type' }),
new RefinementSelectFacet({ id: 'genres', field: 'genres.raw', label: 'Genres' })
new RefinementSelectFacet({ identifier: 'actors', field: 'actors.raw', label: 'Actors' }),
new RefinementSelectFacet({ identifier: 'type', field: 'type.raw', label: 'Type' }),
new RefinementSelectFacet({ identifier: 'genres', field: 'genres.raw', label: 'Genres' })
]

@@ -47,7 +47,7 @@ }

{
results(query: "", filters: [{ id: "writers", value: "Jeff Lindsay" }]) {
results(query: "", filters: [{ identifier: "writers", value: "Jeff Lindsay" }]) {
summary {
total
appliedFilters {
id
identifier
label

@@ -54,0 +54,0 @@ value

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc