2020-07-07 10:14:12 +00:00
|
|
|
import { pageInfoFragment } from "@saleor/fragments/pageInfo";
|
|
|
|
import {
|
|
|
|
fragmentMoney,
|
|
|
|
fragmentVariant,
|
|
|
|
productFragment,
|
|
|
|
productFragmentDetails,
|
|
|
|
productVariantAttributesFragment
|
|
|
|
} from "@saleor/fragments/products";
|
|
|
|
import { warehouseFragment } from "@saleor/fragments/warehouses";
|
2020-01-15 15:36:45 +00:00
|
|
|
import makeQuery from "@saleor/hooks/makeQuery";
|
2020-05-14 09:30:32 +00:00
|
|
|
import gql from "graphql-tag";
|
|
|
|
|
2020-07-07 10:14:12 +00:00
|
|
|
import { TypedQuery } from "../queries";
|
2020-07-30 09:54:16 +00:00
|
|
|
import { CountAllProducts } from "./types/CountAllProducts";
|
2020-05-14 09:30:32 +00:00
|
|
|
import {
|
|
|
|
CreateMultipleVariantsData,
|
|
|
|
CreateMultipleVariantsDataVariables
|
|
|
|
} from "./types/CreateMultipleVariantsData";
|
2020-07-07 10:14:12 +00:00
|
|
|
import {
|
|
|
|
GridAttributes,
|
|
|
|
GridAttributesVariables
|
|
|
|
} from "./types/GridAttributes";
|
2020-05-14 09:30:32 +00:00
|
|
|
import {
|
|
|
|
InitialProductFilterData,
|
|
|
|
InitialProductFilterDataVariables
|
|
|
|
} from "./types/InitialProductFilterData";
|
2019-06-19 14:40:52 +00:00
|
|
|
import {
|
|
|
|
ProductDetails,
|
|
|
|
ProductDetailsVariables
|
|
|
|
} from "./types/ProductDetails";
|
|
|
|
import {
|
|
|
|
ProductImageById,
|
|
|
|
ProductImageByIdVariables
|
|
|
|
} from "./types/ProductImageById";
|
|
|
|
import { ProductList, ProductListVariables } from "./types/ProductList";
|
|
|
|
import {
|
|
|
|
ProductVariantCreateData,
|
|
|
|
ProductVariantCreateDataVariables
|
|
|
|
} from "./types/ProductVariantCreateData";
|
|
|
|
import {
|
|
|
|
ProductVariantDetails,
|
|
|
|
ProductVariantDetailsVariables
|
|
|
|
} from "./types/ProductVariantDetails";
|
|
|
|
|
2020-01-15 15:36:45 +00:00
|
|
|
const initialProductFilterDataQuery = gql`
|
2020-01-16 13:49:06 +00:00
|
|
|
query InitialProductFilterData(
|
|
|
|
$categories: [ID!]
|
|
|
|
$collections: [ID!]
|
|
|
|
$productTypes: [ID!]
|
|
|
|
) {
|
2020-01-17 14:25:50 +00:00
|
|
|
attributes(first: 100, filter: { filterableInDashboard: true }) {
|
|
|
|
edges {
|
|
|
|
node {
|
|
|
|
id
|
|
|
|
name
|
|
|
|
slug
|
|
|
|
values {
|
|
|
|
id
|
|
|
|
name
|
|
|
|
slug
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-01-16 13:49:06 +00:00
|
|
|
categories(first: 100, filter: { ids: $categories }) {
|
|
|
|
edges {
|
|
|
|
node {
|
|
|
|
id
|
|
|
|
name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
collections(first: 100, filter: { ids: $collections }) {
|
2020-01-15 15:36:45 +00:00
|
|
|
edges {
|
|
|
|
node {
|
|
|
|
id
|
|
|
|
name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-01-16 13:49:06 +00:00
|
|
|
productTypes(first: 100, filter: { ids: $productTypes }) {
|
2020-01-15 15:36:45 +00:00
|
|
|
edges {
|
|
|
|
node {
|
|
|
|
id
|
|
|
|
name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
export const useInitialProductFilterDataQuery = makeQuery<
|
|
|
|
InitialProductFilterData,
|
|
|
|
InitialProductFilterDataVariables
|
|
|
|
>(initialProductFilterDataQuery);
|
|
|
|
|
2019-06-19 14:40:52 +00:00
|
|
|
const productListQuery = gql`
|
2020-06-17 08:31:33 +00:00
|
|
|
${fragmentMoney}
|
2019-06-19 14:40:52 +00:00
|
|
|
${productFragment}
|
|
|
|
query ProductList(
|
|
|
|
$first: Int
|
|
|
|
$after: String
|
|
|
|
$last: Int
|
|
|
|
$before: String
|
|
|
|
$filter: ProductFilterInput
|
2019-09-13 11:33:42 +00:00
|
|
|
$sort: ProductOrder
|
2019-06-19 14:40:52 +00:00
|
|
|
) {
|
|
|
|
products(
|
|
|
|
before: $before
|
|
|
|
after: $after
|
|
|
|
first: $first
|
|
|
|
last: $last
|
|
|
|
filter: $filter
|
2019-09-13 11:33:42 +00:00
|
|
|
sortBy: $sort
|
2019-06-19 14:40:52 +00:00
|
|
|
) {
|
|
|
|
edges {
|
|
|
|
node {
|
|
|
|
...ProductFragment
|
2019-08-13 09:04:52 +00:00
|
|
|
attributes {
|
|
|
|
attribute {
|
|
|
|
id
|
|
|
|
}
|
|
|
|
values {
|
|
|
|
id
|
|
|
|
name
|
|
|
|
}
|
|
|
|
}
|
2020-06-18 14:53:07 +00:00
|
|
|
pricing {
|
|
|
|
priceRangeUndiscounted {
|
|
|
|
start {
|
|
|
|
gross {
|
|
|
|
...Money
|
|
|
|
}
|
|
|
|
}
|
|
|
|
stop {
|
|
|
|
gross {
|
|
|
|
...Money
|
|
|
|
}
|
|
|
|
}
|
2020-06-12 12:39:51 +00:00
|
|
|
}
|
|
|
|
}
|
2019-06-19 14:40:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
pageInfo {
|
|
|
|
hasPreviousPage
|
|
|
|
hasNextPage
|
|
|
|
startCursor
|
|
|
|
endCursor
|
|
|
|
}
|
2020-07-30 09:54:16 +00:00
|
|
|
totalCount
|
2019-06-19 14:40:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
`;
|
2020-08-24 10:10:48 +00:00
|
|
|
export const useProductListQuery = makeQuery<ProductList, ProductListVariables>(
|
|
|
|
productListQuery
|
|
|
|
);
|
2019-06-19 14:40:52 +00:00
|
|
|
|
2020-07-30 09:54:16 +00:00
|
|
|
const countAllProductsQuery = gql`
|
|
|
|
query CountAllProducts {
|
|
|
|
products {
|
|
|
|
totalCount
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
export const useCountAllProducts = makeQuery<CountAllProducts, null>(
|
|
|
|
countAllProductsQuery
|
|
|
|
);
|
|
|
|
|
2019-06-19 14:40:52 +00:00
|
|
|
const productDetailsQuery = gql`
|
|
|
|
${productFragmentDetails}
|
|
|
|
query ProductDetails($id: ID!) {
|
|
|
|
product(id: $id) {
|
|
|
|
...Product
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`;
|
2020-08-24 09:50:55 +00:00
|
|
|
export const useProductDetails = makeQuery<
|
2019-06-19 14:40:52 +00:00
|
|
|
ProductDetails,
|
|
|
|
ProductDetailsVariables
|
|
|
|
>(productDetailsQuery);
|
|
|
|
|
|
|
|
const productVariantQuery = gql`
|
|
|
|
${fragmentVariant}
|
|
|
|
query ProductVariantDetails($id: ID!) {
|
|
|
|
productVariant(id: $id) {
|
|
|
|
...ProductVariant
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
export const TypedProductVariantQuery = TypedQuery<
|
|
|
|
ProductVariantDetails,
|
|
|
|
ProductVariantDetailsVariables
|
|
|
|
>(productVariantQuery);
|
|
|
|
|
|
|
|
const productVariantCreateQuery = gql`
|
|
|
|
query ProductVariantCreateData($id: ID!) {
|
|
|
|
product(id: $id) {
|
|
|
|
id
|
|
|
|
images {
|
|
|
|
id
|
|
|
|
sortOrder
|
|
|
|
url
|
|
|
|
}
|
|
|
|
name
|
|
|
|
productType {
|
|
|
|
id
|
|
|
|
variantAttributes {
|
|
|
|
id
|
|
|
|
slug
|
|
|
|
name
|
2019-08-09 11:14:35 +00:00
|
|
|
valueRequired
|
2019-06-19 14:40:52 +00:00
|
|
|
values {
|
|
|
|
id
|
|
|
|
name
|
|
|
|
slug
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
thumbnail {
|
|
|
|
url
|
|
|
|
}
|
|
|
|
variants {
|
|
|
|
id
|
|
|
|
name
|
|
|
|
sku
|
|
|
|
images {
|
|
|
|
id
|
|
|
|
url
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`;
|
2020-08-24 10:18:58 +00:00
|
|
|
export const useProductVariantCreateQuery = makeQuery<
|
2019-06-19 14:40:52 +00:00
|
|
|
ProductVariantCreateData,
|
|
|
|
ProductVariantCreateDataVariables
|
|
|
|
>(productVariantCreateQuery);
|
|
|
|
|
|
|
|
const productImageQuery = gql`
|
|
|
|
query ProductImageById($productId: ID!, $imageId: ID!) {
|
|
|
|
product(id: $productId) {
|
|
|
|
id
|
|
|
|
name
|
|
|
|
mainImage: imageById(id: $imageId) {
|
|
|
|
id
|
|
|
|
alt
|
|
|
|
url
|
|
|
|
}
|
|
|
|
images {
|
|
|
|
id
|
|
|
|
url(size: 48)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`;
|
2020-08-24 10:14:59 +00:00
|
|
|
export const useProductImageQuery = makeQuery<
|
2019-06-19 14:40:52 +00:00
|
|
|
ProductImageById,
|
|
|
|
ProductImageByIdVariables
|
|
|
|
>(productImageQuery);
|
2019-08-13 09:04:52 +00:00
|
|
|
|
|
|
|
const availableInGridAttributes = gql`
|
|
|
|
${pageInfoFragment}
|
2019-08-28 14:41:17 +00:00
|
|
|
query GridAttributes($first: Int!, $after: String, $ids: [ID!]!) {
|
|
|
|
availableInGrid: attributes(
|
2019-08-13 09:04:52 +00:00
|
|
|
first: $first
|
|
|
|
after: $after
|
2019-08-28 14:41:17 +00:00
|
|
|
filter: { availableInGrid: true, isVariantOnly: false }
|
2019-08-13 09:04:52 +00:00
|
|
|
) {
|
|
|
|
edges {
|
|
|
|
node {
|
|
|
|
id
|
|
|
|
name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pageInfo {
|
|
|
|
...PageInfoFragment
|
|
|
|
}
|
|
|
|
totalCount
|
|
|
|
}
|
2019-08-28 14:41:17 +00:00
|
|
|
|
|
|
|
grid: attributes(first: 25, filter: { ids: $ids }) {
|
|
|
|
edges {
|
|
|
|
node {
|
|
|
|
id
|
|
|
|
name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-08-13 09:04:52 +00:00
|
|
|
}
|
|
|
|
`;
|
2020-08-24 10:10:48 +00:00
|
|
|
export const useAvailableInGridAttributesQuery = makeQuery<
|
2020-07-07 10:14:12 +00:00
|
|
|
GridAttributes,
|
|
|
|
GridAttributesVariables
|
2019-08-13 09:04:52 +00:00
|
|
|
>(availableInGridAttributes);
|
2020-04-01 16:28:47 +00:00
|
|
|
|
|
|
|
const createMultipleVariantsData = gql`
|
|
|
|
${productVariantAttributesFragment}
|
2020-04-03 14:29:32 +00:00
|
|
|
${warehouseFragment}
|
2020-04-01 16:28:47 +00:00
|
|
|
query CreateMultipleVariantsData($id: ID!) {
|
|
|
|
product(id: $id) {
|
|
|
|
...ProductVariantAttributesFragment
|
|
|
|
}
|
2020-04-03 14:29:32 +00:00
|
|
|
warehouses(first: 20) {
|
|
|
|
edges {
|
|
|
|
node {
|
|
|
|
...WarehouseFragment
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-04-01 16:28:47 +00:00
|
|
|
}
|
|
|
|
`;
|
|
|
|
export const useCreateMultipleVariantsData = makeQuery<
|
|
|
|
CreateMultipleVariantsData,
|
|
|
|
CreateMultipleVariantsDataVariables
|
|
|
|
>(createMultipleVariantsData);
|