Skip to content
This repository has been archived by the owner on Jul 14, 2022. It is now read-only.

Commit

Permalink
Merge pull request #879 from mirumee/refactor/collection-products-query
Browse files Browse the repository at this point in the history
Update collection products query
  • Loading branch information
dominik-zeglen authored Aug 31, 2020
2 parents 2c0e37f + f713349 commit 5d0c0c1
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 80 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ All notable, unreleased changes to this project will be documented in this file.
- Fix product list data overfetching - #855 by @dominik-zeglen
- Add Adyen payment gateway - #845 by @orzechdev
- Fix crash on null price range - #875 by @orzechdev
- Update collection products query - #879 by @orzechdev

## 2.10.4

Expand Down
4 changes: 2 additions & 2 deletions src/views/Collection/Page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { getDBIdFromGraphqlId, maybe } from "../../core/utils";

import { FilterSidebar } from "../../@next/components/organisms/FilterSidebar";
import { Collection_collection } from "./gqlTypes/Collection";
import { CollectionProducts_products } from "./gqlTypes/CollectionProducts";
import { CollectionProducts_collection_products } from "./gqlTypes/CollectionProducts";

interface SortItem {
label: string;
Expand All @@ -29,7 +29,7 @@ interface PageProps {
displayLoader: boolean;
filters: IFilters;
hasNextPage: boolean;
products: CollectionProducts_products;
products: CollectionProducts_collection_products;
sortOptions: SortOptions;
clearFilters: () => void;
onLoadMore: () => void;
Expand Down
20 changes: 11 additions & 9 deletions src/views/Collection/View.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -168,18 +168,18 @@ export const View: React.FC<ViewProps> = ({ match }) => {
(prev, next) => ({
...prev,
products: {
...prev.products,
...prev.collection.products,
edges: [
...prev.products.edges,
...next.products.edges,
...prev.collection.products.edges,
...next.collection.products.edges,
],
pageInfo: next.products.pageInfo,
pageInfo: next.collection.products.pageInfo,
},
}),
{
after:
collectionProductsData.data.products.pageInfo
.endCursor,
collectionProductsData.data.collection.products
.pageInfo.endCursor,
}
);
if (canDisplayFilters) {
Expand All @@ -201,14 +201,16 @@ export const View: React.FC<ViewProps> = ({ match }) => {
displayLoader={collectionData.loading}
hasNextPage={maybe(
() =>
collectionProductsData.data.products.pageInfo
.hasNextPage,
collectionProductsData.data.collection.products
.pageInfo.hasNextPage,
false
)}
sortOptions={sortOptions}
activeSortOption={filters.sortBy}
filters={filters}
products={collectionProductsData.data.products}
products={
collectionProductsData.data.collection.products
}
onAttributeFiltersChange={onFiltersChange}
onLoadMore={handleLoadMore}
activeFilters={
Expand Down
102 changes: 57 additions & 45 deletions src/views/Collection/gqlTypes/CollectionProducts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { AttributeInput, ProductOrder } from "./../../../../gqlTypes/globalTypes
// GraphQL query operation: CollectionProducts
// ====================================================

export interface CollectionProducts_products_edges_node_thumbnail {
export interface CollectionProducts_collection_products_edges_node_thumbnail {
__typename: "Image";
/**
* The URL of the image.
Expand All @@ -20,15 +20,15 @@ export interface CollectionProducts_products_edges_node_thumbnail {
alt: string | null;
}

export interface CollectionProducts_products_edges_node_thumbnail2x {
export interface CollectionProducts_collection_products_edges_node_thumbnail2x {
__typename: "Image";
/**
* The URL of the image.
*/
url: string;
}

export interface CollectionProducts_products_edges_node_pricing_priceRangeUndiscounted_start_gross {
export interface CollectionProducts_collection_products_edges_node_pricing_priceRangeUndiscounted_start_gross {
__typename: "Money";
/**
* Amount of money.
Expand All @@ -40,7 +40,7 @@ export interface CollectionProducts_products_edges_node_pricing_priceRangeUndisc
currency: string;
}

export interface CollectionProducts_products_edges_node_pricing_priceRangeUndiscounted_start_net {
export interface CollectionProducts_collection_products_edges_node_pricing_priceRangeUndiscounted_start_net {
__typename: "Money";
/**
* Amount of money.
Expand All @@ -52,19 +52,19 @@ export interface CollectionProducts_products_edges_node_pricing_priceRangeUndisc
currency: string;
}

export interface CollectionProducts_products_edges_node_pricing_priceRangeUndiscounted_start {
export interface CollectionProducts_collection_products_edges_node_pricing_priceRangeUndiscounted_start {
__typename: "TaxedMoney";
/**
* Amount of money including taxes.
*/
gross: CollectionProducts_products_edges_node_pricing_priceRangeUndiscounted_start_gross;
gross: CollectionProducts_collection_products_edges_node_pricing_priceRangeUndiscounted_start_gross;
/**
* Amount of money without taxes.
*/
net: CollectionProducts_products_edges_node_pricing_priceRangeUndiscounted_start_net;
net: CollectionProducts_collection_products_edges_node_pricing_priceRangeUndiscounted_start_net;
}

export interface CollectionProducts_products_edges_node_pricing_priceRangeUndiscounted_stop_gross {
export interface CollectionProducts_collection_products_edges_node_pricing_priceRangeUndiscounted_stop_gross {
__typename: "Money";
/**
* Amount of money.
Expand All @@ -76,7 +76,7 @@ export interface CollectionProducts_products_edges_node_pricing_priceRangeUndisc
currency: string;
}

export interface CollectionProducts_products_edges_node_pricing_priceRangeUndiscounted_stop_net {
export interface CollectionProducts_collection_products_edges_node_pricing_priceRangeUndiscounted_stop_net {
__typename: "Money";
/**
* Amount of money.
Expand All @@ -88,31 +88,31 @@ export interface CollectionProducts_products_edges_node_pricing_priceRangeUndisc
currency: string;
}

export interface CollectionProducts_products_edges_node_pricing_priceRangeUndiscounted_stop {
export interface CollectionProducts_collection_products_edges_node_pricing_priceRangeUndiscounted_stop {
__typename: "TaxedMoney";
/**
* Amount of money including taxes.
*/
gross: CollectionProducts_products_edges_node_pricing_priceRangeUndiscounted_stop_gross;
gross: CollectionProducts_collection_products_edges_node_pricing_priceRangeUndiscounted_stop_gross;
/**
* Amount of money without taxes.
*/
net: CollectionProducts_products_edges_node_pricing_priceRangeUndiscounted_stop_net;
net: CollectionProducts_collection_products_edges_node_pricing_priceRangeUndiscounted_stop_net;
}

export interface CollectionProducts_products_edges_node_pricing_priceRangeUndiscounted {
export interface CollectionProducts_collection_products_edges_node_pricing_priceRangeUndiscounted {
__typename: "TaxedMoneyRange";
/**
* Lower bound of a price range.
*/
start: CollectionProducts_products_edges_node_pricing_priceRangeUndiscounted_start | null;
start: CollectionProducts_collection_products_edges_node_pricing_priceRangeUndiscounted_start | null;
/**
* Upper bound of a price range.
*/
stop: CollectionProducts_products_edges_node_pricing_priceRangeUndiscounted_stop | null;
stop: CollectionProducts_collection_products_edges_node_pricing_priceRangeUndiscounted_stop | null;
}

export interface CollectionProducts_products_edges_node_pricing_priceRange_start_gross {
export interface CollectionProducts_collection_products_edges_node_pricing_priceRange_start_gross {
__typename: "Money";
/**
* Amount of money.
Expand All @@ -124,7 +124,7 @@ export interface CollectionProducts_products_edges_node_pricing_priceRange_start
currency: string;
}

export interface CollectionProducts_products_edges_node_pricing_priceRange_start_net {
export interface CollectionProducts_collection_products_edges_node_pricing_priceRange_start_net {
__typename: "Money";
/**
* Amount of money.
Expand All @@ -136,19 +136,19 @@ export interface CollectionProducts_products_edges_node_pricing_priceRange_start
currency: string;
}

export interface CollectionProducts_products_edges_node_pricing_priceRange_start {
export interface CollectionProducts_collection_products_edges_node_pricing_priceRange_start {
__typename: "TaxedMoney";
/**
* Amount of money including taxes.
*/
gross: CollectionProducts_products_edges_node_pricing_priceRange_start_gross;
gross: CollectionProducts_collection_products_edges_node_pricing_priceRange_start_gross;
/**
* Amount of money without taxes.
*/
net: CollectionProducts_products_edges_node_pricing_priceRange_start_net;
net: CollectionProducts_collection_products_edges_node_pricing_priceRange_start_net;
}

export interface CollectionProducts_products_edges_node_pricing_priceRange_stop_gross {
export interface CollectionProducts_collection_products_edges_node_pricing_priceRange_stop_gross {
__typename: "Money";
/**
* Amount of money.
Expand All @@ -160,7 +160,7 @@ export interface CollectionProducts_products_edges_node_pricing_priceRange_stop_
currency: string;
}

export interface CollectionProducts_products_edges_node_pricing_priceRange_stop_net {
export interface CollectionProducts_collection_products_edges_node_pricing_priceRange_stop_net {
__typename: "Money";
/**
* Amount of money.
Expand All @@ -172,31 +172,31 @@ export interface CollectionProducts_products_edges_node_pricing_priceRange_stop_
currency: string;
}

export interface CollectionProducts_products_edges_node_pricing_priceRange_stop {
export interface CollectionProducts_collection_products_edges_node_pricing_priceRange_stop {
__typename: "TaxedMoney";
/**
* Amount of money including taxes.
*/
gross: CollectionProducts_products_edges_node_pricing_priceRange_stop_gross;
gross: CollectionProducts_collection_products_edges_node_pricing_priceRange_stop_gross;
/**
* Amount of money without taxes.
*/
net: CollectionProducts_products_edges_node_pricing_priceRange_stop_net;
net: CollectionProducts_collection_products_edges_node_pricing_priceRange_stop_net;
}

export interface CollectionProducts_products_edges_node_pricing_priceRange {
export interface CollectionProducts_collection_products_edges_node_pricing_priceRange {
__typename: "TaxedMoneyRange";
/**
* Lower bound of a price range.
*/
start: CollectionProducts_products_edges_node_pricing_priceRange_start | null;
start: CollectionProducts_collection_products_edges_node_pricing_priceRange_start | null;
/**
* Upper bound of a price range.
*/
stop: CollectionProducts_products_edges_node_pricing_priceRange_stop | null;
stop: CollectionProducts_collection_products_edges_node_pricing_priceRange_stop | null;
}

export interface CollectionProducts_products_edges_node_pricing {
export interface CollectionProducts_collection_products_edges_node_pricing {
__typename: "ProductPricingInfo";
/**
* Whether it is in sale or not.
Expand All @@ -205,14 +205,14 @@ export interface CollectionProducts_products_edges_node_pricing {
/**
* The undiscounted price range of the product variants.
*/
priceRangeUndiscounted: CollectionProducts_products_edges_node_pricing_priceRangeUndiscounted | null;
priceRangeUndiscounted: CollectionProducts_collection_products_edges_node_pricing_priceRangeUndiscounted | null;
/**
* The discounted price range of the product variants.
*/
priceRange: CollectionProducts_products_edges_node_pricing_priceRange | null;
priceRange: CollectionProducts_collection_products_edges_node_pricing_priceRange | null;
}

export interface CollectionProducts_products_edges_node_category {
export interface CollectionProducts_collection_products_edges_node_category {
__typename: "Category";
/**
* The ID of the object.
Expand All @@ -221,7 +221,7 @@ export interface CollectionProducts_products_edges_node_category {
name: string;
}

export interface CollectionProducts_products_edges_node {
export interface CollectionProducts_collection_products_edges_node {
__typename: "Product";
/**
* The ID of the object.
Expand All @@ -231,27 +231,27 @@ export interface CollectionProducts_products_edges_node {
/**
* The main thumbnail for a product.
*/
thumbnail: CollectionProducts_products_edges_node_thumbnail | null;
thumbnail: CollectionProducts_collection_products_edges_node_thumbnail | null;
/**
* The main thumbnail for a product.
*/
thumbnail2x: CollectionProducts_products_edges_node_thumbnail2x | null;
thumbnail2x: CollectionProducts_collection_products_edges_node_thumbnail2x | null;
/**
* Lists the storefront product's pricing, the current price and discounts, only meant for displaying.
*/
pricing: CollectionProducts_products_edges_node_pricing | null;
category: CollectionProducts_products_edges_node_category | null;
pricing: CollectionProducts_collection_products_edges_node_pricing | null;
category: CollectionProducts_collection_products_edges_node_category | null;
}

export interface CollectionProducts_products_edges {
export interface CollectionProducts_collection_products_edges {
__typename: "ProductCountableEdge";
/**
* The item at the end of the edge.
*/
node: CollectionProducts_products_edges_node;
node: CollectionProducts_collection_products_edges_node;
}

export interface CollectionProducts_products_pageInfo {
export interface CollectionProducts_collection_products_pageInfo {
__typename: "PageInfo";
/**
* When paginating forwards, the cursor to continue.
Expand All @@ -271,24 +271,36 @@ export interface CollectionProducts_products_pageInfo {
startCursor: string | null;
}

export interface CollectionProducts_products {
export interface CollectionProducts_collection_products {
__typename: "ProductCountableConnection";
/**
* A total count of items in the collection.
*/
totalCount: number | null;
edges: CollectionProducts_products_edges[];
edges: CollectionProducts_collection_products_edges[];
/**
* Pagination data for this connection.
*/
pageInfo: CollectionProducts_products_pageInfo;
pageInfo: CollectionProducts_collection_products_pageInfo;
}

export interface CollectionProducts_collection {
__typename: "Collection";
/**
* The ID of the object.
*/
id: string;
/**
* List of products in this collection.
*/
products: CollectionProducts_collection_products | null;
}

export interface CollectionProducts {
/**
* List of the shop's products.
* Look up a collection by ID.
*/
products: CollectionProducts_products | null;
collection: CollectionProducts_collection | null;
}

export interface CollectionProductsVariables {
Expand Down
Loading

0 comments on commit 5d0c0c1

Please sign in to comment.