New Shopify Certification now available: Liquid Storefronts for Theme Developers

Admin GraphQL API - Files API - need for an MediaImage.url field

callmepape
Shopify Partner
1 0 0

Hi, this is a request for a feature in the upcoming GraphQL API version

 

While creating files with the Files API,

 

> if the file is of type GenericFile, we can get the CDN url directly in the response like this :

 

 

 

 

mutation fileCreate($files: [FileCreateInput!]!) {
  fileCreate(files: $files) {
    files {
      ... on GenericFile {
          url
      } 
    }
    userErrors {
      field
      message
    }
  }
}

 

 

 

 

> however if the file is of type MediaImage, it is impossible to get the CDN url in the response

 

 

 

 

mutation fileCreate($files: [FileCreateInput!]!) {
  fileCreate(files: $files) {
    files {
      createdAt
      fileErrors {
        code
        details
        message
      }
      fileStatus
      ... on MediaImage {
              id
              status
              image {
                  url
              }
      }
    }
    userErrors {
      field
      message
    }
  }
}

 

 

 

 

A Image.url field is currently in the works in the unstable version of the API (to replace deprecated Image.src), but in the response to the fileCreate request we get image = null (since status is not READY yet), so it does not bring the solution to getting the CDN url

 

Today, the only way to get the CDN url is to pass a second query to the node, once the file is uploaded and status READY :

 

 

 

 

{
  node(id: "gid://shopify/MediaImage/XXXX") {
    __typename
    ... on MediaImage {
      image {
        url
      }
    }
  }
}

 

 

 

 

That is what an MediaImage.url feed should added in the MediaImage object, as it has been done in the GenericFile object.

 

Thanks in advance

Replies 0 (0)