What's your biggest current challenge? Have your say in Community Polls along the right column.
Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

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

Solved

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

huangcong12
Shopify Partner
12 0 2

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
        }
      }
    }`
  );
ImgCraft: AI Sharp & Resize - Rescuing Low-Quality Images | LitaCat: Page Watermark - Convey Your Voice
Accepted Solution (1)

ShopifyDevSup
Shopify Staff
1453 238 525

This is an accepted solution.

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-originalsourc... 

 

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. 

Developer Support @ Shopify
- Was this reply helpful? Click Like to let us know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

View solution in original post

Reply 1 (1)

ShopifyDevSup
Shopify Staff
1453 238 525

This is an accepted solution.

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-originalsourc... 

 

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. 

Developer Support @ Shopify
- Was this reply helpful? Click Like to let us know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog