Why isn't GraphQL fileCreate mutation returning image URL?

Topic summary

A developer encountered an issue where the GraphQL fileCreate mutation was returning null for the image URL instead of the expected transformedSrc value needed to update WYSIWYG content during a site import.

Initial Workaround:

  • Query the uploaded file separately using its filename to retrieve the URL
  • This requires running a second GraphQL query after the file creation

Recommended Solution:

  • Use the id returned by fileCreate to query the node directly
  • This approach is simpler and more reliable than filename-based queries
  • The node query allows fetching all image properties including transformedSrc, originalSrc, dimensions, and alt text

Key Technical Detail:
The solution involves using the global ID (gid) from the fileCreate response (e.g., data.fileCreate.files[0].id) in a subsequent node query to retrieve complete image metadata.

The discussion reached resolution with multiple working approaches shared by participants.

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

I’m in the process of creating an importer for an old site and part of what I need to import includes some wysiwyg areas which include images.

I am as far as using the mutation fileCreate to upload the file, this is all working.

However, I can’t seem to get back the new url that I need to replace in my content!

image is just returning null.

Any ideas what I’m doing wrong here?

mutation fileCreate($files: [FileCreateInput!]!) {
                      fileCreate(files: $files) {
                        files {
                          ... on MediaImage {
                            id
                            image {
                              transformedSrc
                            }
                          }
                        }
                      }
                    }

I’ve cracked it!

Rather than relying on the fileCreate to pass me anything meaningful back, I already have the filename of the file I’m creating.

So if I run a second graphQL and query the filename, I can get the file and url!!!

{
                        files(query: "filename:'.$filename.'", first: 1) {
                            edges {
                                node {
                                    createdAt
                                    ... on MediaImage {
                                        id
                                        image {
                                            transformedSrc
                                        }
                                    }
                                }
                            }
                        }
                    }

Thanks for posting this solution!

If anyone’s passing through here wondering how to pass that $filename as a variable since the query expects a string, here’s a useful thread.

Simpler solution that might not of been available when the original was posts is to take the id returned by fileCreate then query for the node directly

https://shopify.dev/api/admin-graphql/2021-10/queries/node

4 Likes

That sounds like a far more reliable method. I’ll definitely keep that in mind if I need to right another importer. Thank you!

For anyone who also has a client and is in a rush, just use this query and replace node’s id with gid you got from fileCreate’s response (data.fileCreate.files[0].id).

query {
    node(id: "gid://shopify/MediaImage/54823383826760") {
      id,
    	... on MediaImage {
        id,
        image {
          altText,
          id,
          originalSrc,
          transformedSrc,
          width,
          height,
        }
      }
    }
  }