Recently the fileCreate GraphQL endpoint was released. It allows to upload files on the store that will end up under “Settings” > “Files”.
My goal is to get the file url in order to use it in a product description once the upload is done.
The only way to get a file url is through the file.preview.image attribute on the file, nonetheless when I insert the file, the file.preview.image returned is null.
My GraphQL body is the following:
query = f""" mutation {{
fileCreate(files: [{{
originalSource: "{dropbox_url}"
contentType: IMAGE
alt: "PLOP"
}}]) {{
files {{
alt
createdAt
fileStatus
preview {{
status
image {{
altText
height
id
originalSrc
transformedSrc
width
}}
}}
}}
userErrors
{{
code
field
message
}}
}}
}}
"""
After some time if I read the files from the shop (through GraphQL), then the preview is returned correctly. My guess is that the preview is computed and take some time so the fileCreate returns an empty image at first.
Because the File does not have and id, I cannot simply wait a little bit and retrieve the image url. I would need to loop through all the files and match the file I just inserted with the right file using the created date timestamp (sub optimal).
Is this expected ?
Do you see another way to get the file url ?