GraphQL fileCreate return src?!

Vinnydude
Excursionist
13 1 1

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
                            }
                          }
                        }
                      }
                    }
0 Likes
Vinnydude
Excursionist
13 1 1

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
                                        }
                                    }
                                }
                            }
                        }
                    }
0 Likes
mariannef
New Member
2 0 2

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

0 Likes