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

Update GraphQL queries #567

Merged
merged 6 commits into from
Jan 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions apollo.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ module.exports = {
client: {
service: {
name: "saleor",
url: "http://localhost:8000/graphql/"
}
}
url: "http://localhost:8000/graphql/",
includes: ["./**/*.js", "./**/*.ts"],
excludes: ["**/__tests__/**/*"],
},
},
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@
"node": ">=10.0.0 <11"
},
"scripts": {
"test": "jest --config .jest/config.json",
"test": "jest --runInBand --config .jest/config.json",
"start": "cross-env NODE_ENV=develop webpack-dev-server --history-api-fallback --watch --port 3000 --mode development --hotOnly",
"start:worker": "npm run start -- --service-worker",
"build": "webpack -p",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ export const ProductVariantPicker: React.FC<IProps> = ({
const productVariantAttributeId = productVariantAttribute.attribute.id;

if (
productVariantAttribute.value &&
productVariantAttribute.values[0] &&
productVariantsAttributesSelectedValues[productVariantAttributeId] &&
productVariantAttribute.value.id ===
productVariantAttribute.values[0]!.id ===
productVariantsAttributesSelectedValues[productVariantAttributeId]!
.id
) {
Expand Down
126 changes: 72 additions & 54 deletions src/@next/components/organisms/ProductVariantPicker/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,14 @@ export const productVariants: ProductDetails_product_variants[] = [
name: "Material",
__typename: "Attribute",
},
value: {
id: "QXR0cmlidXRlVmFsdWU6ODI=",
name: "cotton",
value: "cotton",
__typename: "AttributeValue",
},
values: [
{
id: "QXR0cmlidXRlVmFsdWU6ODI=",
name: "cotton",
value: "cotton",
__typename: "AttributeValue",
},
],
__typename: "SelectedAttribute",
},
{
Expand All @@ -63,12 +65,14 @@ export const productVariants: ProductDetails_product_variants[] = [
name: "Color",
__typename: "Attribute",
},
value: {
id: "QXR0cmlidXRlVmFsdWU6ODM=",
name: "yellow",
value: "yellow",
__typename: "AttributeValue",
},
values: [
{
id: "QXR0cmlidXRlVmFsdWU6ODM=",
name: "yellow",
value: "yellow",
__typename: "AttributeValue",
},
],
__typename: "SelectedAttribute",
},
{
Expand All @@ -77,12 +81,14 @@ export const productVariants: ProductDetails_product_variants[] = [
name: "Size",
__typename: "Attribute",
},
value: {
id: "QXR0cmlidXRlVmFsdWU6NDc=",
name: "1l",
value: "1l",
__typename: "AttributeValue",
},
values: [
{
id: "QXR0cmlidXRlVmFsdWU6NDc=",
name: "1l",
value: "1l",
__typename: "AttributeValue",
},
],
__typename: "SelectedAttribute",
},
],
Expand Down Expand Up @@ -135,12 +141,14 @@ export const productVariants: ProductDetails_product_variants[] = [
name: "Material",
__typename: "Attribute",
},
value: {
id: "QXR0cmlidXRlVmFsdWU6ODY=",
name: "wool",
value: "wool",
__typename: "AttributeValue",
},
values: [
{
id: "QXR0cmlidXRlVmFsdWU6ODY=",
name: "wool",
value: "wool",
__typename: "AttributeValue",
},
],
__typename: "SelectedAttribute",
},
{
Expand All @@ -149,12 +157,14 @@ export const productVariants: ProductDetails_product_variants[] = [
name: "Color",
__typename: "Attribute",
},
value: {
id: "QXR0cmlidXRlVmFsdWU6ODQ=",
name: "red",
value: "red",
__typename: "AttributeValue",
},
values: [
{
id: "QXR0cmlidXRlVmFsdWU6ODQ=",
name: "red",
value: "red",
__typename: "AttributeValue",
},
],
__typename: "SelectedAttribute",
},
{
Expand All @@ -163,12 +173,14 @@ export const productVariants: ProductDetails_product_variants[] = [
name: "Size",
__typename: "Attribute",
},
value: {
id: "QXR0cmlidXRlVmFsdWU6NDg=",
name: "2l",
value: "2l",
__typename: "AttributeValue",
},
values: [
{
id: "QXR0cmlidXRlVmFsdWU6NDg=",
name: "2l",
value: "2l",
__typename: "AttributeValue",
},
],
__typename: "SelectedAttribute",
},
],
Expand Down Expand Up @@ -221,12 +233,14 @@ export const productVariants: ProductDetails_product_variants[] = [
name: "Material",
__typename: "Attribute",
},
value: {
id: "QXR0cmlidXRlVmFsdWU6ODY=",
name: "wool",
value: "wool",
__typename: "AttributeValue",
},
values: [
{
id: "QXR0cmlidXRlVmFsdWU6ODY=",
name: "wool",
value: "wool",
__typename: "AttributeValue",
},
],
__typename: "SelectedAttribute",
},
{
Expand All @@ -235,12 +249,14 @@ export const productVariants: ProductDetails_product_variants[] = [
name: "Color",
__typename: "Attribute",
},
value: {
id: "QXR0cmlidXRlVmFsdWU6ODU=",
name: "turquoise",
value: "turquoise",
__typename: "AttributeValue",
},
values: [
{
id: "QXR0cmlidXRlVmFsdWU6ODU=",
name: "turquoise",
value: "turquoise",
__typename: "AttributeValue",
},
],
__typename: "SelectedAttribute",
},
{
Expand All @@ -249,12 +265,14 @@ export const productVariants: ProductDetails_product_variants[] = [
name: "Size",
__typename: "Attribute",
},
value: {
id: "QXR0cmlidXRlVmFsdWU6NDY=",
name: "500ml",
value: "500ml",
__typename: "AttributeValue",
},
values: [
{
id: "QXR0cmlidXRlVmFsdWU6NDY=",
name: "500ml",
value: "500ml",
__typename: "AttributeValue",
},
],
__typename: "SelectedAttribute",
},
],
Expand Down
6 changes: 3 additions & 3 deletions src/@next/hooks/useProductVariantsAttributes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ export const useProductVariantsAttributes = (
if (variantsAttributeExists) {
const variantsAttributeValueExists = variantsAttributes[
productVariantAttributeId
].values.includes(productVariantAttribute.value!);
].values.includes(productVariantAttribute.values[0]!);

if (!variantsAttributeValueExists) {
variantsAttributes[productVariantAttributeId].values.push(
productVariantAttribute.value!
productVariantAttribute.values[0]!
);
}
} else {
variantsAttributes[productVariantAttributeId] = {
attribute: productVariantAttribute.attribute,
values: [productVariantAttribute.value!],
values: [productVariantAttribute.values[0]!],
};
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const useSelectableProductVariantsAttributeValues = (
return (
productVariantAttribute.attribute.id ===
selectedValueAttributeId &&
productVariantAttribute.value ===
productVariantAttribute.values[0] ===
productVariantsAttributesSelectedValues[
selectedValueAttributeId
]
Expand Down
6 changes: 3 additions & 3 deletions src/@next/types/IProductVariantsAttributes.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import { ISelectOption } from "@types";
import {
ProductDetails_product_variants_attributes_attribute,
ProductDetails_product_variants_attributes_value,
ProductDetails_product_variants_attributes_values,
} from "../../@sdk/queries/types/ProductDetails";

export interface IProductVariantsAttribute {
attribute: ProductDetails_product_variants_attributes_attribute;
values: ProductDetails_product_variants_attributes_value[];
values: ProductDetails_product_variants_attributes_values[];
}

export interface IProductVariantsAttributes {
[key: string]: IProductVariantsAttribute;
}

export interface IProductVariantsAttributesSelectedValues {
[key: string]: ProductDetails_product_variants_attributes_value | null;
[key: string]: ProductDetails_product_variants_attributes_values | null;
}

export interface IProductVariantsAttributesOptionValue extends ISelectOption {
Expand Down
2 changes: 1 addition & 1 deletion src/@sdk/fragments/products.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const productVariantFragment = gql`
id
name
}
value {
values {
id
name
value: name
Expand Down
6 changes: 3 additions & 3 deletions src/@sdk/fragments/types/ProductVariantFields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export interface ProductVariantFields_attributes_attribute {
name: string | null;
}

export interface ProductVariantFields_attributes_value {
export interface ProductVariantFields_attributes_values {
__typename: "AttributeValue";
/**
* The ID of the object.
Expand All @@ -145,9 +145,9 @@ export interface ProductVariantFields_attributes {
*/
attribute: ProductVariantFields_attributes_attribute;
/**
* The value or the first value of an attribute.
* Values of an attribute.
*/
value: ProductVariantFields_attributes_value | null;
values: (ProductVariantFields_attributes_values | null)[];
}

export interface ProductVariantFields {
Expand Down
2 changes: 1 addition & 1 deletion src/@sdk/queries/attributes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import gql from "graphql-tag";

export const attributes = gql`
query Attributes($id: ID!) {
attributes(inCategory: $id, first: 100) {
attributes(filter: { inCategory: $id }, first: 100) {
edges {
node {
id
Expand Down
25 changes: 3 additions & 22 deletions src/@sdk/queries/products.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export const productPricingFragment = gql`

export const productListDetails = gql`
${basicProductFragment}
${productPricingFragment}
query ProductList(
$id: ID!
$attributes: [AttributeInput]
Expand All @@ -55,20 +56,7 @@ export const productListDetails = gql`
edges {
node {
...BasicProductFields
price {
amount
currency
localized
}
pricing {
priceRange {
start {
gross {
localized
}
}
}
}
...ProductPricingField
category {
id
name
Expand Down Expand Up @@ -115,11 +103,6 @@ export const productDetails = gql`
id
url
}
basePrice {
amount
currency
localized
}
attributes {
...SelectedAttributeFields
}
Expand All @@ -128,9 +111,7 @@ export const productDetails = gql`
}
seoDescription
seoTitle
availability {
available
}
isAvailable
}
}
`;
Loading