Product Media Filters

Hey,

At the moment on the media connection its not possible to filter by media type e.g. Image / Video etc, this means we have to retrieve more nodes than we need to get these items and then filter them ourselves productVariant - GraphQL Admin

Thanks for the info. Understood that filtering by media type isn’t supported yet. Could you let us know if there are plans to add this feature in the future?

Hi @JordanFinners and @Hamza_Zahid,

I can confirm at this time that the productVariant.media connector does not have the ability to filter the connector results directly.

I’ll definitely be submitting some feedback on your behalf that you’d like to see this added in the future, though we are unable to provide any estimated timeframes or confirm if it will be added. I’d recommend keeping an eye on our Shopify.dev changelog for any potential updates in the future.

In the meantime, as a workaround, I may recommend using the files query specifically, which you can filter by media_type and product_id.

Thanks for the confirmation and for submitting the feedback, really appreciate it.
The workaround using the files query with media_type and product_id sounds good we’ll explore that approach for now.
We’ll also keep an eye on the changelog for any updates.

1 Like

Hey @Kellan-Shopify is the files ordered in the same way? If I’m looking to get featured media for the variant I need to get the first item because there isn’t a option for this at the variant level

Hey @JordanFinners,

So the files query automatically sorts the results by the file object’s GUID.

You can specify what value to sort by, with the sortKey argument, though there is a limited amount of values that can be used to sort, specifically: CREATED_AT, FILENAME, ID, ORIGINAL_UPLOAD_SIZE, RELEVANCE, AND UPDATED_AT.

So nothing that would order by the featured file by default, though you can possibly workaround this using fields like the filename, and naming the files when you upload them based on how you want to sort them in the queries, for example:

Product Variant has the following files:

  • 1_variant_image.jpg (featured file)
  • 2_variant_image.jpg
  • 3_variant_image.jpg

This way you can sort by filename and it will return the featured file first.


Another alternative workaround would be naming the files with a prefix or suffix adding featured like so:

  • variant_image_1.jpg
  • variant_image_2.jpg
  • featured_variant_image_3.jpg

Then you can query all the images on the product, requesting only the image ID and the Filename.

Then you can parse the results in your app code, selecting only the image with the featured string in the filename.

Then you can query that specific file ID with a file query, to get more of the data from that one file.

This workaround would require 2 API calls, but it helps return less data overall, since in the first call you’re only requesting the id and filename for all file objects in the query, and then you’re requesting more detailed data from a single file object int he second call.