2019-06-19 14:40:52 +00:00
|
|
|
import gql from "graphql-tag";
|
|
|
|
|
2019-08-13 09:04:52 +00:00
|
|
|
import { pageInfoFragment, TypedQuery } from "../queries";
|
|
|
|
import {
|
|
|
|
AvailableInGridAttributes,
|
|
|
|
AvailableInGridAttributesVariables
|
|
|
|
} from "./types/AvailableInGridAttributes";
|
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";
|
|
|
|
|
|
|
|
export const fragmentMoney = gql`
|
|
|
|
fragment Money on Money {
|
|
|
|
amount
|
|
|
|
currency
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
|
|
|
export const fragmentProductImage = gql`
|
|
|
|
fragment ProductImageFragment on ProductImage {
|
|
|
|
id
|
|
|
|
alt
|
|
|
|
sortOrder
|
|
|
|
url
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
|
|
|
export const productFragment = gql`
|
|
|
|
${fragmentMoney}
|
|
|
|
fragment ProductFragment on Product {
|
|
|
|
id
|
|
|
|
name
|
|
|
|
thumbnail {
|
|
|
|
url
|
|
|
|
}
|
|
|
|
isAvailable
|
|
|
|
basePrice {
|
|
|
|
...Money
|
|
|
|
}
|
|
|
|
productType {
|
|
|
|
id
|
|
|
|
name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
export const productFragmentDetails = gql`
|
|
|
|
${fragmentProductImage}
|
|
|
|
${fragmentMoney}
|
|
|
|
fragment Product on Product {
|
|
|
|
id
|
|
|
|
name
|
|
|
|
descriptionJson
|
|
|
|
seoTitle
|
|
|
|
seoDescription
|
|
|
|
category {
|
|
|
|
id
|
|
|
|
name
|
|
|
|
}
|
|
|
|
collections {
|
|
|
|
id
|
|
|
|
name
|
|
|
|
}
|
|
|
|
basePrice {
|
|
|
|
...Money
|
|
|
|
}
|
|
|
|
margin {
|
|
|
|
start
|
|
|
|
stop
|
|
|
|
}
|
|
|
|
purchaseCost {
|
|
|
|
start {
|
|
|
|
...Money
|
|
|
|
}
|
|
|
|
stop {
|
|
|
|
...Money
|
|
|
|
}
|
|
|
|
}
|
|
|
|
isAvailable
|
|
|
|
isPublished
|
|
|
|
chargeTaxes
|
|
|
|
publicationDate
|
|
|
|
attributes {
|
|
|
|
attribute {
|
|
|
|
id
|
|
|
|
slug
|
|
|
|
name
|
2019-08-09 11:14:35 +00:00
|
|
|
inputType
|
|
|
|
valueRequired
|
2019-06-19 14:40:52 +00:00
|
|
|
values {
|
2019-08-09 11:14:35 +00:00
|
|
|
id
|
2019-06-19 14:40:52 +00:00
|
|
|
name
|
|
|
|
slug
|
|
|
|
}
|
|
|
|
}
|
2019-08-09 11:14:35 +00:00
|
|
|
values {
|
2019-06-19 14:40:52 +00:00
|
|
|
id
|
|
|
|
name
|
|
|
|
slug
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pricing {
|
|
|
|
priceRange {
|
|
|
|
start {
|
|
|
|
net {
|
|
|
|
...Money
|
|
|
|
}
|
|
|
|
}
|
|
|
|
stop {
|
|
|
|
net {
|
|
|
|
...Money
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
images {
|
|
|
|
...ProductImageFragment
|
|
|
|
}
|
|
|
|
variants {
|
|
|
|
id
|
|
|
|
sku
|
|
|
|
name
|
|
|
|
priceOverride {
|
|
|
|
...Money
|
|
|
|
}
|
|
|
|
margin
|
|
|
|
quantity
|
|
|
|
quantityAllocated
|
|
|
|
stockQuantity
|
|
|
|
}
|
|
|
|
productType {
|
|
|
|
id
|
|
|
|
name
|
|
|
|
hasVariants
|
|
|
|
}
|
|
|
|
url
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
|
|
|
export const fragmentVariant = gql`
|
|
|
|
${fragmentMoney}
|
|
|
|
${fragmentProductImage}
|
|
|
|
fragment ProductVariant on ProductVariant {
|
|
|
|
id
|
|
|
|
attributes {
|
|
|
|
attribute {
|
|
|
|
id
|
|
|
|
name
|
|
|
|
slug
|
2019-08-09 11:14:35 +00:00
|
|
|
valueRequired
|
2019-06-19 14:40:52 +00:00
|
|
|
values {
|
|
|
|
id
|
|
|
|
name
|
|
|
|
slug
|
|
|
|
}
|
|
|
|
}
|
|
|
|
value {
|
|
|
|
id
|
|
|
|
name
|
|
|
|
slug
|
|
|
|
}
|
|
|
|
}
|
|
|
|
costPrice {
|
|
|
|
...Money
|
|
|
|
}
|
|
|
|
images {
|
|
|
|
id
|
|
|
|
url
|
|
|
|
}
|
|
|
|
name
|
|
|
|
priceOverride {
|
|
|
|
...Money
|
|
|
|
}
|
|
|
|
product {
|
|
|
|
id
|
|
|
|
images {
|
|
|
|
...ProductImageFragment
|
|
|
|
}
|
|
|
|
name
|
|
|
|
thumbnail {
|
|
|
|
url
|
|
|
|
}
|
|
|
|
variants {
|
|
|
|
id
|
|
|
|
name
|
|
|
|
sku
|
|
|
|
images {
|
|
|
|
id
|
|
|
|
url
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sku
|
|
|
|
quantity
|
|
|
|
quantityAllocated
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
|
|
|
const productListQuery = gql`
|
|
|
|
${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
|
|
|
|
}
|
|
|
|
}
|
2019-06-19 14:40:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
pageInfo {
|
|
|
|
hasPreviousPage
|
|
|
|
hasNextPage
|
|
|
|
startCursor
|
|
|
|
endCursor
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
export const TypedProductListQuery = TypedQuery<
|
|
|
|
ProductList,
|
|
|
|
ProductListVariables
|
|
|
|
>(productListQuery);
|
|
|
|
|
|
|
|
const productDetailsQuery = gql`
|
|
|
|
${productFragmentDetails}
|
|
|
|
query ProductDetails($id: ID!) {
|
|
|
|
product(id: $id) {
|
|
|
|
...Product
|
2019-09-19 10:13:48 +00:00
|
|
|
productType {
|
|
|
|
variantAttributes {
|
|
|
|
id
|
|
|
|
name
|
|
|
|
values {
|
|
|
|
id
|
|
|
|
name
|
2019-10-02 13:34:34 +00:00
|
|
|
slug
|
2019-09-19 10:13:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-06-19 14:40:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
export const TypedProductDetailsQuery = TypedQuery<
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
export const TypedProductVariantCreateQuery = TypedQuery<
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
export const TypedProductImageQuery = TypedQuery<
|
|
|
|
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
|
|
|
}
|
|
|
|
`;
|
|
|
|
export const AvailableInGridAttributesQuery = TypedQuery<
|
|
|
|
AvailableInGridAttributes,
|
|
|
|
AvailableInGridAttributesVariables
|
|
|
|
>(availableInGridAttributes);
|