Skip to content

Commit

Permalink
fix(core): Fix ONLY_FULL_GROUP_BY error when searching with MySQL
Browse files Browse the repository at this point in the history
Fixes #1236
  • Loading branch information
michaelbromley committed Nov 23, 2021
1 parent 160f457 commit 94fa4db
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
17 changes: 17 additions & 0 deletions packages/core/e2e/default-search-plugin.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,23 @@ describe('Default search plugin', () => {
]);
});

// https://github.com/vendure-ecommerce/vendure/issues/1236
it('returns correct facetValues when not grouped by product, with search term', async () => {
const result = await shopClient.query<SearchFacetValues.Query, SearchFacetValues.Variables>(
SEARCH_GET_FACET_VALUES,
{
input: {
groupByProduct: false,
term: 'laptop',
},
},
);
expect(result.search.facetValues).toEqual([
{ count: 4, facetValue: { id: 'T_1', name: 'electronics' } },
{ count: 4, facetValue: { id: 'T_2', name: 'computers' } },
]);
});

it('omits facetValues of private facets', async () => {
const { createFacet } = await adminClient.query<CreateFacet.Mutation, CreateFacet.Variables>(
CREATE_FACET,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class MysqlSearchStrategy implements SearchStrategy {
.select(['MIN(productId)', 'MIN(productVariantId)'])
.addSelect('GROUP_CONCAT(facetValueIds)', 'facetValues');

this.applyTermAndFilters(ctx, facetValuesQb, input);
this.applyTermAndFilters(ctx, facetValuesQb, { ...input, groupByProduct: true });
if (!input.groupByProduct) {
facetValuesQb.groupBy('productVariantId');
}
Expand Down

0 comments on commit 94fa4db

Please sign in to comment.