From 742523bac721e9c67404ee3e6f6bf22e1006f1d7 Mon Sep 17 00:00:00 2001 From: dominik-zeglen Date: Thu, 19 Sep 2019 12:13:48 +0200 Subject: [PATCH] Fix variant create query --- .../ProductVariantCreateDialog/index.ts | 0 src/products/mutations.ts | 22 ++----------------- src/products/queries.ts | 10 +++++++++ src/products/types/ProductDetails.ts | 14 ++++++++++++ src/products/types/VariantCreate.ts | 10 ++------- src/types/globalTypes.ts | 11 ++++++++++ 6 files changed, 39 insertions(+), 28 deletions(-) create mode 100644 src/products/components/ProductVariantCreateDialog/index.ts diff --git a/src/products/components/ProductVariantCreateDialog/index.ts b/src/products/components/ProductVariantCreateDialog/index.ts new file mode 100644 index 000000000..e69de29bb diff --git a/src/products/mutations.ts b/src/products/mutations.ts index ef7024d69..563c09f84 100644 --- a/src/products/mutations.ts +++ b/src/products/mutations.ts @@ -319,26 +319,8 @@ export const TypedVariantUpdateMutation = TypedMutation< export const variantCreateMutation = gql` ${fragmentVariant} - mutation VariantCreate( - $attributes: [AttributeValueInput]! - $costPrice: Decimal - $priceOverride: Decimal - $product: ID! - $sku: String - $quantity: Int - $trackInventory: Boolean! - ) { - productVariantCreate( - input: { - attributes: $attributes - costPrice: $costPrice - priceOverride: $priceOverride - product: $product - sku: $sku - quantity: $quantity - trackInventory: $trackInventory - } - ) { + mutation VariantCreate($input: ProductVariantCreateInput!) { + productVariantCreate(input: $input) { errors { field message diff --git a/src/products/queries.ts b/src/products/queries.ts index fa60db7cb..efbdb9489 100644 --- a/src/products/queries.ts +++ b/src/products/queries.ts @@ -260,6 +260,16 @@ const productDetailsQuery = gql` query ProductDetails($id: ID!) { product(id: $id) { ...Product + productType { + variantAttributes { + id + name + values { + id + name + } + } + } } } `; diff --git a/src/products/types/ProductDetails.ts b/src/products/types/ProductDetails.ts index 5094afd59..803e66d8d 100644 --- a/src/products/types/ProductDetails.ts +++ b/src/products/types/ProductDetails.ts @@ -139,11 +139,25 @@ export interface ProductDetails_product_variants { stockQuantity: number; } +export interface ProductDetails_product_productType_variantAttributes_values { + __typename: "AttributeValue"; + id: string; + name: string | null; +} + +export interface ProductDetails_product_productType_variantAttributes { + __typename: "Attribute"; + id: string; + name: string | null; + values: (ProductDetails_product_productType_variantAttributes_values | null)[] | null; +} + export interface ProductDetails_product_productType { __typename: "ProductType"; id: string; name: string; hasVariants: boolean; + variantAttributes: (ProductDetails_product_productType_variantAttributes | null)[] | null; } export interface ProductDetails_product { diff --git a/src/products/types/VariantCreate.ts b/src/products/types/VariantCreate.ts index 4dcfdd5d1..b1d2783b1 100644 --- a/src/products/types/VariantCreate.ts +++ b/src/products/types/VariantCreate.ts @@ -2,7 +2,7 @@ /* eslint-disable */ // This file was automatically generated and should not be edited. -import { AttributeValueInput } from "./../../types/globalTypes"; +import { ProductVariantCreateInput } from "./../../types/globalTypes"; // ==================================================== // GraphQL mutation operation: VariantCreate @@ -122,11 +122,5 @@ export interface VariantCreate { } export interface VariantCreateVariables { - attributes: (AttributeValueInput | null)[]; - costPrice?: any | null; - priceOverride?: any | null; - product: string; - sku?: string | null; - quantity?: number | null; - trackInventory: boolean; + input: ProductVariantCreateInput; } diff --git a/src/types/globalTypes.ts b/src/types/globalTypes.ts index 1e8cfaf3a..5dff42bb4 100644 --- a/src/types/globalTypes.ts +++ b/src/types/globalTypes.ts @@ -614,6 +614,17 @@ export interface ProductTypeInput { taxCode?: string | null; } +export interface ProductVariantCreateInput { + attributes: (AttributeValueInput | null)[]; + costPrice?: any | null; + priceOverride?: any | null; + sku?: string | null; + quantity?: number | null; + trackInventory?: boolean | null; + weight?: any | null; + product: string; +} + export interface ProductVariantInput { attributes?: (AttributeValueInput | null)[] | null; costPrice?: any | null;