GraphqlQueryError: Field 'originalFileSize' doesn't exist on type 'MediaImage'

Topic summary

A developer encountered an error when querying the originalFileSize field on the MediaImage type using Shopify’s files API (version 2024-01). The query failed with: GraphqlQueryError: Field 'originalFileSize' doesn't exist on type 'MediaImage'.

Resolution provided:

  • The originalFileSize field does not exist directly on the MediaImage object
  • Instead, use the originalSource field, which contains both fileSize and url values
  • The correct query structure should be:
    files(query: "media_type:IMAGE", first: 3) {
      edges {
        node {
          ... on MediaImage {
            id
            originalSource {
              fileSize
              url
            }
          }
        }
      }
    }
    

Status: Issue resolved with corrected field reference. The documentation team will be notified about the discrepancy.

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

I’m currently using the files API (https://shopify.dev/docs/api/admin-graphql/2024-01/queries/files) to query image information. It works well, but when I follow the demo and add originalFileSize, it prompts: GraphqlQueryError: Field 'originalFileSize' doesn't exist on type 'MediaImage'. I really need this field, so I’ve been trying to resolve this issue but without success. The demo in the documentation shows how to query this field, but I haven’t been successful. Could it be a problem with my code, or is there an issue with the demo code in the documentation?

My api_version is “2024-01”, and my code is as follows:

const response = await admin.graphql(
    `#graphql
    query {
      files(${pageSize}, query:"${condition}" ${pageCondition} reverse:true) {
        edges {
          node {
            createdAt
            updatedAt
            alt
            ... on MediaImage {
              id
              originalFileSize
              image {
                originalSrc: url
                width
                height
              }
            }
          }
        }
        pageInfo {
          hasNextPage
          endCursor
          hasPreviousPage
          startCursor
        }
      }
    }`
  );

Hey @huangcong12 ,

Thanks for sharing your query. Just looking at our documentation here for the MediaImage object, the originalFileSize does not exist there.

There is however the originalSource field that includes the fileSize and url values. https://shopify.dev/docs/api/admin-graphql/2024-01/objects/MediaImage#field-mediaimage-originalsource

It should be this in the example:

{> files(query: “media_type:IMAGE”, first: 3) {> edges {> node {> … on MediaImage {> id> originalSource {> fileSize> url> }> image {> id> originalSrc: url> width> height> }> }> }> }> }> }

I’ll let our docs team know about this!

Hope that helps,

Kyle G.