Can't get different file types in metafield list of files using the Admin API

Topic summary

A user encountered a bug when querying a product metafield containing a list of mixed file types (MediaImage and GenericFile) via Shopify’s Admin API (2023-01 version).

The Problem:

  • The metafield contained 4 files: 2 GenericFiles and 2 MediaImages
  • The GraphQL query only returned files matching the type of the first item in the list
  • Files of the other type appeared as null in the response
  • Changing the file order confirmed the issue: whichever type came first determined which files were returned

Resolution:

  • Shopify staff member richard-penner confirmed this was a bug and escalated it to the team for investigation
  • User cemgurbey later confirmed the bug has been fixed

The issue involved the references field on a list.file_reference metafield type not properly handling mixed media types in a single query.

Summarized with AI on November 21. AI used: claude-sonnet-4-5-20250929.

I am trying this query on the Admin API (2023-01)

{
  product(id: "gid://shopify/Product/7677457531050") {
    id
    handle
    title
    metafield(namespace: "tech_drawings", key: "cad3d") {
      namespace
      key
      type
      references(first:10) {
        nodes {
          __typename
          ... on MediaImage {
            id
            image {
              url
            }
          }
          ... on GenericFile {
            id
            url
          }
        }
      }
    }
  }
}

but I am not getting the results I expect.

product.metafields.tech_drawings.cad3d is a list of files. The product has 4 attachments in the metafield, 2 are of type GenericFile and 2 are MediaImage. I can only get back one file type, the files of the other type are null.

The type I get back is always whatever type is first in the list.

For example, if the attached files are in the order

  1. PrintButtonDisabled.png
  2. tinyimg.doilooklikeiknowwhatapngis
  3. thisIsACADfile.txt
  4. tinyimg.png

the result of the query is:

{
	"data": {
		"product": {
			"id": "gid:\/\/shopify\/Product\/7677457531050",
			"handle": "productbuilder",
			"title": "ProductBuilder",
			"metafield": {
				"namespace": "tech_drawings",
				"key": "cad3d",
				"type": "list.file_reference",
				"references": {
					"nodes": [
						{
							"__typename": "MediaImage",
							"id": "gid:\/\/shopify\/MediaImage\/28522171531434",
							"image": {
								"url": "https:\/\/cdn.shopify.com\/s\/files\/1\/0600\/8383\/0954\/files\/PrintButtonDisabled.png?v=1678460680"
							}
						},
						null,
						null,
						{
							"__typename": "MediaImage",
							"id": "gid:\/\/shopify\/MediaImage\/28540311929002",
							"image": {
								"url": "https:\/\/cdn.shopify.com\/s\/files\/1\/0600\/8383\/0954\/files\/tinyimg.png?v=1678798239"
							}
						}
					]
				}
			}
		}
	},
	"extensions": {
		"cost": {
			"requestedQueryCost": 24,
			"actualQueryCost": 7,
			"throttleStatus": {
				"maximumAvailable": 1000.0,
				"currentlyAvailable": 993,
				"restoreRate": 50.0
			}
		}
	}
}

If I change the order of the files to

  1. thisIsACADfile.txt
  2. PrintButtonDisabled.png
  3. tinyimg.doilooklikeiknowwhatapngis
  4. tinyimg.png

I get this:

{
	"data": {
		"product": {
			"id": "gid:\/\/shopify\/Product\/7677457531050",
			"handle": "productbuilder",
			"title": "ProductBuilder",
			"metafield": {
				"namespace": "tech_drawings",
				"key": "cad3d",
				"type": "list.file_reference",
				"references": {
					"nodes": [
						{
							"__typename": "GenericFile",
							"id": "gid:\/\/shopify\/GenericFile\/28540547104938",
							"url": "https:\/\/cdn.shopify.com\/s\/files\/1\/0600\/8383\/0954\/files\/thisIsACADfile.txt?v=1678800901"
						},
						null,
						{
							"__typename": "GenericFile",
							"id": "gid:\/\/shopify\/GenericFile\/28540311961770",
							"url": "https:\/\/cdn.shopify.com\/s\/files\/1\/0600\/8383\/0954\/files\/tinyimg.doilooklikeiknowwhatapngis?v=1678798239"
						},
						null
					]
				}
			}
		}
	},
	"extensions": {
		"cost": {
			"requestedQueryCost": 24,
			"actualQueryCost": 5,
			"throttleStatus": {
				"maximumAvailable": 1000.0,
				"currentlyAvailable": 995,
				"restoreRate": 50.0
			}
		}
	}
}

I do get the expected results (all 4 attachments appear correctly) using the Shopify GraphiQL app Storefront API. Is there a way to get the same result with the Admin API?

Hi @IHaveNoAnswers – it looks like you’ve found a bug here. I’ve asked the team to investigate, and we’ll follow up here when a fix has rolled out.

1 Like

@IHaveNoAnswers , bug fixed! Thanks for letting us know.

2 Likes