Get URL of generic file from gid with GraphQL

Topic summary

A developer needed to retrieve the URL of a non-image file uploaded to Shopify using its GID (Global ID) through GraphQL. They queried the files endpoint with a GenericFile fragment to access file metadata including the URL field.

Initial Problem:

  • The GraphQL query returned file metadata (createdAt, updatedAt, id) but the url field was null
  • This occurred specifically for non-image file types

Resolution:

  • The issue was timing-related: the query was executed immediately after file upload
  • Waiting for the file upload to complete before querying resolved the problem
  • The URL field populates only after Shopify finishes processing the uploaded file

Status: Resolved - self-answered by the original poster.

Summarized with AI on October 31. AI used: claude-sonnet-4-5-20250929.

Hi community :waving_hand:

Does anyone know, how I can get the url of a file I uploaded to shopify via GraphQL?

I have the gid and managed to get some info with this mutation:

files(first: 1, query: "id:'${id}'") {
          edges {
            node {
              createdAt
              updatedAt
              alt
              ... on GenericFile {
                id
                url
              }
            }
          }
        }
      }

The answer looks like this:

{
  createdAt: '2025-03-02T10:27:45Z',
  updatedAt: '2025-03-02T10:27:45Z',
  alt: '',
  id: 'gid://shopify/GenericFile/123456789',
  url: null
}

Does anyone know a solution?
Important: I don’t upload images. I know that images get a value in the url field in the response. But other file types don’t.

Just found the solution myself. I did this query right after file uploading. I had to wait for the file to finish uploading. After that, the response comes with a url.