Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: filter out variant media from product media query #6165

Merged
merged 8 commits into from
Apr 3, 2020

Conversation

willopez
Copy link
Member

@willopez willopez commented Mar 30, 2020

Impact: minor
Type: bugfix

Issue

The top level product media resolver was returning media from variants. This causes all media in child variants and options to be rendered on the parent top level product.

Solution

Filter out variant media from product media resolved.

Breaking changes

NONE

query product($productId: ID!, $shopId: ID!, $shouldIncludeVariantMedia: Boolean) {
  product(productId: $productId, shopId: $shopId, shouldIncludeVariantMedia: $shouldIncludeVariantMedia) {
    media(shouldIncludeVariantMedia: $shouldIncludeVariantMedia {
    _id
    URLs {
      small
    }
  }
  }
}

Variables:

{
  "productId": "myProductId",
  "shopId": "myShopId",
  "shouldIncludeVariantMedia": false
}

Testing

  1. Execute product media query above and verify that only media for the top level product is returned.

@aldeed
Copy link
Contributor

aldeed commented Apr 1, 2020

@willopez I think this was an intentional design decision, but I don't remember for sure. IDK which way people expect, but there might be people relying on this behavior so this could be considered a breaking change. @spencern or @zenweasel what do you think?

@mikemurray
Copy link
Member

@willopez, @aldeed is correct. It "was" intentional, though not properly displayed in the Admin UI.

The media bubbles up to the top. So If I upload an image at the Option level, then the parent Variant inherits the option media, and the top-level Product then inherits all the Variant and Option media.

This is so you can organize the top-level product images if you want, and so you don't have to upload images to every single level. You could just upload only option media, and leave the other levels blank.

This made sense when the products were displayed on the storefront from the products collection. Now that we get the info from the Catalog, we can still have that functionality there, while doing something different with Products.


I can see @willopez intent here because...

When displaying the product images, the bubble-up effect is useful. When uploading images in the Admin UI, having child media in the uploader, especially at the product level, is overwhelming.

Perhaps adding a param the getProductMedia called like shouldIncludeVariantMedia could be an option to keep the old functionality while allowing the new.

Otherwise, we can always filter out the media in the UI and display a better user interface for managing direct media dependencies, while also allowing the organization of all product media at the top-level.

@willopez
Copy link
Member Author

willopez commented Apr 1, 2020

Adding a param shouldIncludeVariantMedia seems good to me.

@spencern
Copy link
Contributor

spencern commented Apr 1, 2020

Sounds good to me 👍

@brent-hoover
Copy link
Collaborator

@aldeed We don't currently rely on this behavior because we don't use Product Media at all but I think for building an admin screen it would be good to have the flexibility that the shouldIncludeVariantMedia parameter would provide

@aldeed
Copy link
Contributor

aldeed commented Apr 2, 2020

@willopez shouldIncludeVariantMedia sounds good to me as long as it defaults to true when not set so that current behavior doesn't break. I think it should be an argument on the Product.media field rather than on the query, so that you can use it anywhere that a Product type is returned.

query product($productId: ID!, $shopId: ID!) {
  product(productId: $productId, shopId: $shopId) {
    media(shouldIncludeVariantMedia: false) {
      _id
      URLs {
        small
      }
    }
  }
}

@willopez
Copy link
Member Author

willopez commented Apr 2, 2020

@mikemurray @aldeed @spencern shouldIncludeVariantMedia argument added.

Signed-off-by: Will Lopez <[email protected]>
aldeed
aldeed previously requested changes Apr 2, 2020
Copy link
Contributor

@aldeed aldeed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few comments

src/core-services/product/schemas/product.graphql Outdated Show resolved Hide resolved
src/core-services/product/utils/getProductMedia.js Outdated Show resolved Hide resolved
src/core-services/product/schemas/product.graphql Outdated Show resolved Hide resolved
Copy link
Member

@mikemurray mikemurray left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@mikemurray mikemurray requested a review from aldeed April 3, 2020 17:12
@mikemurray mikemurray dismissed aldeed’s stale review April 3, 2020 17:13

The requested changes have been made

@mikemurray mikemurray merged commit 9f958fc into trunk Apr 3, 2020
@mikemurray mikemurray deleted the willopez-product-media-fixes branch April 3, 2020 17:14
@kieckhafer kieckhafer mentioned this pull request Apr 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants