Skip to content

Commit

Permalink
feat(core): Add Facet queries to Shop API (#1016)
Browse files Browse the repository at this point in the history
Closes #1013
  • Loading branch information
Izayda authored Aug 3, 2021
1 parent b787acb commit d6a049c
Show file tree
Hide file tree
Showing 8 changed files with 5,440 additions and 5,936 deletions.
37 changes: 37 additions & 0 deletions packages/common/src/generated-shop-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ export type Query = {
eligibleShippingMethods: Array<ShippingMethodQuote>;
/** Returns a list of payment methods and their eligibility based on the current active Order */
eligiblePaymentMethods: Array<PaymentMethodQuote>;
/** A list of Facets available to the shop */
facets: FacetList;
/** Returns a Facet by its id */
facet?: Maybe<Facet>;
/** Returns information about the current authenticated User */
me?: Maybe<CurrentUser>;
/** Returns the possible next states that the activeOrder can transition to */
Expand Down Expand Up @@ -76,6 +80,16 @@ export type QueryCollectionArgs = {
};


export type QueryFacetsArgs = {
options?: Maybe<FacetListOptions>;
};


export type QueryFacetArgs = {
id: Scalars['ID'];
};


export type QueryOrderArgs = {
id: Scalars['ID'];
};
Expand Down Expand Up @@ -2764,6 +2778,13 @@ export type CollectionListOptions = {
filter?: Maybe<CollectionFilterParameter>;
};

export type FacetListOptions = {
skip?: Maybe<Scalars['Int']>;
take?: Maybe<Scalars['Int']>;
sort?: Maybe<FacetSortParameter>;
filter?: Maybe<FacetFilterParameter>;
};

export type OrderListOptions = {
skip?: Maybe<Scalars['Int']>;
take?: Maybe<Scalars['Int']>;
Expand Down Expand Up @@ -2924,6 +2945,22 @@ export type CollectionSortParameter = {
description?: Maybe<SortOrder>;
};

export type FacetFilterParameter = {
createdAt?: Maybe<DateOperators>;
updatedAt?: Maybe<DateOperators>;
languageCode?: Maybe<StringOperators>;
name?: Maybe<StringOperators>;
code?: Maybe<StringOperators>;
};

export type FacetSortParameter = {
id?: Maybe<SortOrder>;
createdAt?: Maybe<SortOrder>;
updatedAt?: Maybe<SortOrder>;
name?: Maybe<SortOrder>;
code?: Maybe<SortOrder>;
};

export type ProductFilterParameter = {
createdAt?: Maybe<DateOperators>;
updatedAt?: Maybe<DateOperators>;
Expand Down
13 changes: 11 additions & 2 deletions packages/core/e2e/facet.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {
ASSIGN_PRODUCT_TO_CHANNEL,
CREATE_CHANNEL,
CREATE_FACET,
GET_FACET_LIST,
GET_FACET_LIST, GET_FACET_LIST_SIMPLE,
GET_PRODUCT_WITH_VARIANTS,
UPDATE_FACET,
UPDATE_PRODUCT,
Expand All @@ -43,7 +43,7 @@ import { assertThrowsWithMessage } from './utils/assert-throws-with-message';
// tslint:disable:no-non-null-assertion

describe('Facet resolver', () => {
const { server, adminClient } = createTestEnvironment(testConfig);
const { server, adminClient, shopClient } = createTestEnvironment(testConfig);

let brandFacet: FacetWithValues.Fragment;
let speakerTypeFacet: FacetWithValues.Fragment;
Expand Down Expand Up @@ -85,6 +85,7 @@ describe('Facet resolver', () => {
input: {
id: speakerTypeFacet.id,
translations: [{ languageCode: LanguageCode.en, name: 'Speaker Category' }],
isPrivate: true
},
});

Expand Down Expand Up @@ -157,6 +158,14 @@ describe('Facet resolver', () => {
speakerTypeFacet = items[1];
});

it('facets by shop-api', async () => {
const result = await shopClient.query<GetFacetList.Query>(GET_FACET_LIST_SIMPLE);

const { items } = result.facets;
expect(items.length).toBe(1);
expect(items[0].name).toBe('category');
});

it('facet', async () => {
const result = await adminClient.query<GetFacetWithValues.Query, GetFacetWithValues.Variables>(
GET_FACET_WITH_VALUES,
Expand Down
Loading

0 comments on commit d6a049c

Please sign in to comment.