Skip to content

Commit

Permalink
Breakdown feed queries into smaller ones (#1630)
Browse files Browse the repository at this point in the history
* Breakdown feed queries into smaller ones

* Create dull-squids-tan.md

* Products query

* Products query

* Products query

* Products query

* Products query

---------

Co-authored-by: Paweł Chyła <[email protected]>
  • Loading branch information
andrzejewsky and poulch authored Oct 21, 2024
1 parent 6133deb commit 945a27b
Show file tree
Hide file tree
Showing 18 changed files with 484 additions and 67 deletions.
5 changes: 5 additions & 0 deletions .changeset/dull-squids-tan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"products-feed": patch
---

Now, a single query for fetching variants was splitted into smaller ones to decrease the API overload.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
fragment BasicProductData on ProductVariant {
id
name
sku
product {
id
}
weight {
unit
value
}
pricing {
priceUndiscounted {
gross {
currency
amount
}
}
price {
gross {
currency
amount
}
}
}
quantityAvailable
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
fragment ProductAttributes on ProductVariant {
id
attributes {
attribute {
id
}
values {
value
name
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
fragment RelatedProducts on Product {
id
name
slug
description
seoDescription
productType {
isShippingRequired
}
media {
id
alt
url(size: $imageSize)
type
}
variants {
id
media{
id
alt
url(size: $imageSize)
type
}
}
attributes{
attribute{
id
}
values{
value
name
}
}
thumbnail(size: $imageSize) {
url
}
category {
id
name
googleCategoryId: metafield(key: "google_category_id")
}

}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
query FetchProductDataForFeed($first:Int!, $after: String, $channel: String!, $imageSize: Int = 1024){
query FetchBasicProductData($first:Int!, $after: String, $channel: String!){
productVariants(first:$first, after: $after, channel: $channel){
pageInfo{
hasNextPage
endCursor
}
edges{
node{
...GoogleFeedProductVariant
node {
...BasicProductData
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
query FetchProductAttributesData($first:Int!, $after: String, $channel: String!){
productVariants(first:$first, after: $after, channel: $channel){
pageInfo{
hasNextPage
endCursor
}
edges{
node {
...ProductAttributes
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
query FetchRelatedProductsData($ids: [ID!], $imageSize: Int = 1024){
products(filter: { ids: $ids }, first: 100){
edges {
node {
...RelatedProducts
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { GoogleFeedProductVariantFragment } from "../../../generated/graphql";
import { ProductVariant } from "../google-feed/fetch-product-data";

export const exampleVariantData: GoogleFeedProductVariantFragment = {
export const exampleVariantData: ProductVariant = {
id: "UHJvZHVjdFZhcmlhbnQ6MzYx", // cspell:disable-line
name: "M",
sku: "218223580",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { describe, expect, it } from "vitest";
import { GoogleFeedProductVariantFragment } from "../../../generated/graphql";

import { attributeArrayToValueString, getMappedAttributes } from "./attribute-mapping";
import { ProductVariant } from "./fetch-product-data";

const productBase: GoogleFeedProductVariantFragment["product"] = {
const productBase: ProductVariant["product"] = {
name: "Product",
__typename: "Product",
id: "product-id",
Expand Down Expand Up @@ -47,7 +48,7 @@ const productBase: GoogleFeedProductVariantFragment["product"] = {
],
};

const priceBase: GoogleFeedProductVariantFragment["pricing"] = {
const priceBase: ProductVariant["pricing"] = {
__typename: "VariantPricingInfo",
price: {
__typename: "TaxedMoney",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import { GoogleFeedProductVariantFragment } from "../../../generated/graphql";
import { RootConfig } from "../app-configuration/app-config";
import { ProductVariant } from "./fetch-product-data";

interface GetMappedAttributesArgs {
variant: GoogleFeedProductVariantFragment;
variant: ProductVariant;
attributeMapping?: RootConfig["attributeMapping"];
}

export const attributeArrayToValueString = (
attributes?: GoogleFeedProductVariantFragment["attributes"],
) => {
export const attributeArrayToValueString = (attributes?: ProductVariant["attributes"]) => {
if (!attributes?.length) {
return;
}
Expand Down
Loading

0 comments on commit 945a27b

Please sign in to comment.