From 431dba2c94122e75e3342301ceb3d93592335606 Mon Sep 17 00:00:00 2001 From: Mike Murray Date: Wed, 3 Apr 2019 16:27:21 -0700 Subject: [PATCH] refactor: move media resolvers to CatalogProductVariant resolver Signed-off-by: Mike Murray --- .../no-meteor/resolvers/CatalogProduct/index.js | 16 +--------------- .../resolvers/CatalogProductVariant/index.js | 5 ++++- 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/imports/plugins/core/catalog/server/no-meteor/resolvers/CatalogProduct/index.js b/imports/plugins/core/catalog/server/no-meteor/resolvers/CatalogProduct/index.js index 83d8c0143f1..ed9672ed4fb 100644 --- a/imports/plugins/core/catalog/server/no-meteor/resolvers/CatalogProduct/index.js +++ b/imports/plugins/core/catalog/server/no-meteor/resolvers/CatalogProduct/index.js @@ -13,19 +13,5 @@ export default { tagIds, tags, media: (node, args, context) => node.media && node.media.map((mediaItem) => xformCatalogProductMedia(mediaItem, context)), - primaryImage: (node, args, context) => xformCatalogProductMedia(node.primaryImage, context), - variants: (node, args, context) => node.variants && node.variants.map((variant) => { - variant.media = variant.media && variant.media.map((mediaItem) => xformCatalogProductMedia(mediaItem, context)); - variant.primaryImage = xformCatalogProductMedia(variant.primaryImage, context); - - if (variant.options) { - variant.options = variant.options.map((option) => { - option.media = option.media && option.media.map((mediaItem) => xformCatalogProductMedia(mediaItem, context)); - option.primaryImage = xformCatalogProductMedia(option.primaryImage, context); - return option; - }); - } - - return variant; - }) + primaryImage: (node, args, context) => xformCatalogProductMedia(node.primaryImage, context) }; diff --git a/imports/plugins/core/catalog/server/no-meteor/resolvers/CatalogProductVariant/index.js b/imports/plugins/core/catalog/server/no-meteor/resolvers/CatalogProductVariant/index.js index f613fdd3a33..1af844a80b9 100644 --- a/imports/plugins/core/catalog/server/no-meteor/resolvers/CatalogProductVariant/index.js +++ b/imports/plugins/core/catalog/server/no-meteor/resolvers/CatalogProductVariant/index.js @@ -1,10 +1,13 @@ import { encodeCatalogProductVariantOpaqueId } from "@reactioncommerce/reaction-graphql-xforms/catalogProductVariant"; import { encodeProductOpaqueId, xformPricingArray } from "@reactioncommerce/reaction-graphql-xforms/product"; import { resolveShopFromShopId } from "@reactioncommerce/reaction-graphql-utils"; +import { xformCatalogProductMedia } from "@reactioncommerce/reaction-graphql-xforms/catalogProduct"; export default { _id: (node) => encodeCatalogProductVariantOpaqueId(node._id), variantId: (node) => encodeProductOpaqueId(node.variantId), shop: resolveShopFromShopId, - pricing: (node) => xformPricingArray(node.pricing) + pricing: (node) => xformPricingArray(node.pricing), + media: (node, args, context) => node.media && node.media.map((mediaItem) => xformCatalogProductMedia(mediaItem, context)), + primaryImage: (node, args, context) => xformCatalogProductMedia(node.primaryImage, context) };