Skip to content

Commit

Permalink
feat(core): Add asset focal point data to SearchResult type
Browse files Browse the repository at this point in the history
Relates to #93

BREAKING CHANGE: The `search` query's `SearchResult` type has had two properties deprecated: `productPreview` and `productVariantPreview`. They are replaced by `productAsset.preview` and `productVariantAsset.preview respectively`. The deprecated properties still work but will be removed from a future release.
  • Loading branch information
michaelbromley committed Feb 13, 2020
1 parent 3a352c5 commit f717fb3
Show file tree
Hide file tree
Showing 18 changed files with 318 additions and 42 deletions.
9 changes: 9 additions & 0 deletions packages/common/src/generated-shop-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2044,9 +2044,11 @@ export type SearchResult = {
productId: Scalars['ID'];
productName: Scalars['String'];
productPreview: Scalars['String'];
productAsset?: Maybe<SearchResultAsset>;
productVariantId: Scalars['ID'];
productVariantName: Scalars['String'];
productVariantPreview: Scalars['String'];
productVariantAsset?: Maybe<SearchResultAsset>;
price: SearchResultPrice;
priceWithTax: SearchResultPrice;
currencyCode: CurrencyCode;
Expand All @@ -2059,6 +2061,13 @@ export type SearchResult = {
score: Scalars['Float'];
};

export type SearchResultAsset = {
__typename?: 'SearchResultAsset';
id: Scalars['ID'];
preview: Scalars['String'];
focalPoint?: Maybe<Coordinate>;
};

/** The price of a search result product, either as a range or as a single price */
export type SearchResultPrice = PriceRange | SinglePrice;

Expand Down
9 changes: 9 additions & 0 deletions packages/common/src/generated-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3114,9 +3114,11 @@ export type SearchResult = {
productId: Scalars['ID'],
productName: Scalars['String'],
productPreview: Scalars['String'],
productAsset?: Maybe<SearchResultAsset>,
productVariantId: Scalars['ID'],
productVariantName: Scalars['String'],
productVariantPreview: Scalars['String'],
productVariantAsset?: Maybe<SearchResultAsset>,
price: SearchResultPrice,
priceWithTax: SearchResultPrice,
currencyCode: CurrencyCode,
Expand All @@ -3129,6 +3131,13 @@ export type SearchResult = {
score: Scalars['Float'],
};

export type SearchResultAsset = {
__typename?: 'SearchResultAsset',
id: Scalars['ID'],
preview: Scalars['String'],
focalPoint?: Maybe<Coordinate>,
};

/** The price of a search result product, either as a range or as a single price */
export type SearchResultPrice = PriceRange | SinglePrice;

Expand Down
16 changes: 1 addition & 15 deletions packages/core/e2e/asset.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { omit } from '@vendure/common/lib/omit';
import { pick } from '@vendure/common/lib/pick';
import { createTestEnvironment } from '@vendure/testing';
import gql from 'graphql-tag';
import path from 'path';
Expand All @@ -15,7 +14,7 @@ import {
SortOrder,
UpdateAsset,
} from './graphql/generated-e2e-admin-types';
import { GET_ASSET_LIST } from './graphql/shared-definitions';
import { GET_ASSET_LIST, UPDATE_ASSET } from './graphql/shared-definitions';

describe('Asset resolver', () => {
const { server, adminClient } = createTestEnvironment(testConfig);
Expand Down Expand Up @@ -213,16 +212,3 @@ export const CREATE_ASSETS = gql`
}
${ASSET_FRAGMENT}
`;

export const UPDATE_ASSET = gql`
mutation UpdateAsset($input: UpdateAssetInput!) {
updateAsset(input: $input) {
...Asset
focalPoint {
x
y
}
}
}
${ASSET_FRAGMENT}
`;
68 changes: 68 additions & 0 deletions packages/core/e2e/default-search-plugin.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* tslint:disable:no-non-null-assertion */
import { pick } from '@vendure/common/lib/pick';
import { DefaultSearchPlugin, mergeConfig } from '@vendure/core';
import { facetValueCollectionFilter } from '@vendure/core/dist/config/collection/default-collection-filters';
Expand All @@ -19,9 +20,11 @@ import {
LanguageCode,
RemoveProductsFromChannel,
SearchFacetValues,
SearchGetAssets,
SearchGetPrices,
SearchInput,
SortOrder,
UpdateAsset,
UpdateCollection,
UpdateProduct,
UpdateProductVariants,
Expand All @@ -36,6 +39,7 @@ import {
DELETE_PRODUCT,
DELETE_PRODUCT_VARIANT,
REMOVE_PRODUCT_FROM_CHANNEL,
UPDATE_ASSET,
UPDATE_COLLECTION,
UPDATE_PRODUCT,
UPDATE_PRODUCT_VARIANTS,
Expand Down Expand Up @@ -570,6 +574,41 @@ describe('Default search plugin', () => {
]);
});

it('updates index when asset focalPoint is changed', async () => {
function doSearch() {
return adminClient.query<SearchGetAssets.Query, SearchGetAssets.Variables>(
SEARCH_GET_ASSETS,
{
input: {
term: 'laptop',
take: 1,
},
},
);
}
const { search: search1 } = await doSearch();

expect(search1.items[0].productAsset!.id).toBe('T_1');
expect(search1.items[0].productAsset!.focalPoint).toBeNull();

await adminClient.query<UpdateAsset.Mutation, UpdateAsset.Variables>(UPDATE_ASSET, {
input: {
id: 'T_1',
focalPoint: {
x: 0.42,
y: 0.42,
},
},
});

await awaitRunningJobs(adminClient);

const { search: search2 } = await doSearch();

expect(search2.items[0].productAsset!.id).toBe('T_1');
expect(search2.items[0].productAsset!.focalPoint).toEqual({ x: 0.42, y: 0.42 });
});

it('returns enabled field when not grouped', async () => {
const result = await doAdminSearchQuery({ groupByProduct: false, take: 3 });
expect(result.search.items.map(pick(['productVariantId', 'enabled']))).toEqual([
Expand Down Expand Up @@ -719,6 +758,35 @@ export const SEARCH_GET_FACET_VALUES = gql`
}
`;

export const SEARCH_GET_ASSETS = gql`
query SearchGetAssets($input: SearchInput!) {
search(input: $input) {
totalItems
items {
productId
productName
productVariantName
productAsset {
id
preview
focalPoint {
x
y
}
}
productVariantAsset {
id
preview
focalPoint {
x
y
}
}
}
}
}
`;

export const SEARCH_GET_PRICES = gql`
query SearchGetPrices($input: SearchInput!) {
search(input: $input) {
Expand Down
100 changes: 83 additions & 17 deletions packages/core/e2e/graphql/generated-e2e-admin-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3005,9 +3005,11 @@ export type SearchResult = {
productId: Scalars['ID'];
productName: Scalars['String'];
productPreview: Scalars['String'];
productAsset?: Maybe<SearchResultAsset>;
productVariantId: Scalars['ID'];
productVariantName: Scalars['String'];
productVariantPreview: Scalars['String'];
productVariantAsset?: Maybe<SearchResultAsset>;
price: SearchResultPrice;
priceWithTax: SearchResultPrice;
currencyCode: CurrencyCode;
Expand All @@ -3020,6 +3022,13 @@ export type SearchResult = {
score: Scalars['Float'];
};

export type SearchResultAsset = {
__typename?: 'SearchResultAsset';
id: Scalars['ID'];
preview: Scalars['String'];
focalPoint?: Maybe<Coordinate>;
};

/** The price of a search result product, either as a range or as a single price */
export type SearchResultPrice = PriceRange | SinglePrice;

Expand Down Expand Up @@ -3512,16 +3521,6 @@ export type CreateAssetsMutation = { __typename?: 'Mutation' } & {
>;
};

export type UpdateAssetMutationVariables = {
input: UpdateAssetInput;
};

export type UpdateAssetMutation = { __typename?: 'Mutation' } & {
updateAsset: { __typename?: 'Asset' } & {
focalPoint: Maybe<{ __typename?: 'Coordinate' } & Pick<Coordinate, 'x' | 'y'>>;
} & AssetFragment;
};

export type CanCreateCustomerMutationVariables = {
input: CreateCustomerInput;
};
Expand Down Expand Up @@ -3848,6 +3847,42 @@ export type SearchFacetValuesQuery = { __typename?: 'Query' } & {
};
};

export type SearchGetAssetsQueryVariables = {
input: SearchInput;
};

export type SearchGetAssetsQuery = { __typename?: 'Query' } & {
search: { __typename?: 'SearchResponse' } & Pick<SearchResponse, 'totalItems'> & {
items: Array<
{ __typename?: 'SearchResult' } & Pick<
SearchResult,
'productId' | 'productName' | 'productVariantName'
> & {
productAsset: Maybe<
{ __typename?: 'SearchResultAsset' } & Pick<
SearchResultAsset,
'id' | 'preview'
> & {
focalPoint: Maybe<
{ __typename?: 'Coordinate' } & Pick<Coordinate, 'x' | 'y'>
>;
}
>;
productVariantAsset: Maybe<
{ __typename?: 'SearchResultAsset' } & Pick<
SearchResultAsset,
'id' | 'preview'
> & {
focalPoint: Maybe<
{ __typename?: 'Coordinate' } & Pick<Coordinate, 'x' | 'y'>
>;
}
>;
}
>;
};
};

export type SearchGetPricesQueryVariables = {
input: SearchInput;
};
Expand Down Expand Up @@ -4562,6 +4597,16 @@ export type RemoveProductsFromChannelMutation = { __typename?: 'Mutation' } & {
removeProductsFromChannel: Array<{ __typename?: 'Product' } & ProductWithVariantsFragment>;
};

export type UpdateAssetMutationVariables = {
input: UpdateAssetInput;
};

export type UpdateAssetMutation = { __typename?: 'Mutation' } & {
updateAsset: { __typename?: 'Asset' } & {
focalPoint: Maybe<{ __typename?: 'Coordinate' } & Pick<Coordinate, 'x' | 'y'>>;
} & AssetFragment;
};

export type UpdateOptionGroupMutationVariables = {
input: UpdateProductOptionGroupInput;
};
Expand Down Expand Up @@ -5332,13 +5377,6 @@ export namespace CreateAssets {
>;
}

export namespace UpdateAsset {
export type Variables = UpdateAssetMutationVariables;
export type Mutation = UpdateAssetMutation;
export type UpdateAsset = AssetFragment;
export type FocalPoint = NonNullable<UpdateAssetMutation['updateAsset']['focalPoint']>;
}

export namespace CanCreateCustomer {
export type Variables = CanCreateCustomerMutationVariables;
export type Mutation = CanCreateCustomerMutation;
Expand Down Expand Up @@ -5559,6 +5597,27 @@ export namespace SearchFacetValues {
export type FacetValue = (NonNullable<SearchFacetValuesQuery['search']['facetValues'][0]>)['facetValue'];
}

export namespace SearchGetAssets {
export type Variables = SearchGetAssetsQueryVariables;
export type Query = SearchGetAssetsQuery;
export type Search = SearchGetAssetsQuery['search'];
export type Items = NonNullable<SearchGetAssetsQuery['search']['items'][0]>;
export type ProductAsset = NonNullable<
(NonNullable<SearchGetAssetsQuery['search']['items'][0]>)['productAsset']
>;
export type FocalPoint = NonNullable<
(NonNullable<(NonNullable<SearchGetAssetsQuery['search']['items'][0]>)['productAsset']>)['focalPoint']
>;
export type ProductVariantAsset = NonNullable<
(NonNullable<SearchGetAssetsQuery['search']['items'][0]>)['productVariantAsset']
>;
export type _FocalPoint = NonNullable<
(NonNullable<
(NonNullable<SearchGetAssetsQuery['search']['items'][0]>)['productVariantAsset']
>)['focalPoint']
>;
}

export namespace SearchGetPrices {
export type Variables = SearchGetPricesQueryVariables;
export type Query = SearchGetPricesQuery;
Expand Down Expand Up @@ -6037,6 +6096,13 @@ export namespace RemoveProductsFromChannel {
export type RemoveProductsFromChannel = ProductWithVariantsFragment;
}

export namespace UpdateAsset {
export type Variables = UpdateAssetMutationVariables;
export type Mutation = UpdateAssetMutation;
export type UpdateAsset = AssetFragment;
export type FocalPoint = NonNullable<UpdateAssetMutation['updateAsset']['focalPoint']>;
}

export namespace UpdateOptionGroup {
export type Variables = UpdateOptionGroupMutationVariables;
export type Mutation = UpdateOptionGroupMutation;
Expand Down
9 changes: 9 additions & 0 deletions packages/core/e2e/graphql/generated-e2e-shop-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2044,9 +2044,11 @@ export type SearchResult = {
productId: Scalars['ID'];
productName: Scalars['String'];
productPreview: Scalars['String'];
productAsset?: Maybe<SearchResultAsset>;
productVariantId: Scalars['ID'];
productVariantName: Scalars['String'];
productVariantPreview: Scalars['String'];
productVariantAsset?: Maybe<SearchResultAsset>;
price: SearchResultPrice;
priceWithTax: SearchResultPrice;
currencyCode: CurrencyCode;
Expand All @@ -2059,6 +2061,13 @@ export type SearchResult = {
score: Scalars['Float'];
};

export type SearchResultAsset = {
__typename?: 'SearchResultAsset';
id: Scalars['ID'];
preview: Scalars['String'];
focalPoint?: Maybe<Coordinate>;
};

/** The price of a search result product, either as a range or as a single price */
export type SearchResultPrice = PriceRange | SinglePrice;

Expand Down
12 changes: 12 additions & 0 deletions packages/core/e2e/graphql/shared-definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,3 +337,15 @@ export const REMOVE_PRODUCT_FROM_CHANNEL = gql`
}
${PRODUCT_WITH_VARIANTS_FRAGMENT}
`;
export const UPDATE_ASSET = gql`
mutation UpdateAsset($input: UpdateAssetInput!) {
updateAsset(input: $input) {
...Asset
focalPoint {
x
y
}
}
}
${ASSET_FRAGMENT}
`;
Loading

0 comments on commit f717fb3

Please sign in to comment.