Hi guys, is it possible to send a query with FormD...
# random
j
Hi guys, is it possible to send a query with FormData (image in my case) with graphql-request (https://github.com/graphcool/graphql-request) ?
t
I could be wrong, but I don't think you can. The way graphcool-framework handles files is that they are uploaded to a separate file handling API which stores the data somewhere (AWS, GCP, your local HDD, whatever) and then performs an API call that inserts info about the file, including a public link to it) into the
File
table and then returns the fields (
ID, URL
etc) from that insert as the result. You can then query the
File
type later to get the file URL and use it in your app.
j
Thank! Probably will upload file without graphQL and then just send a url to graphQL
t
That's exactly what you want to do. Handle the file upload on your server then mutate your graphql API
File
type:
Copy code
mutation saveFile($url: String!, $name: String!) {
  createFile(name: $name, url: $url) {
    id
    name
    url
  }
}
then use that URL to display and call
getFile
query when you want to display it again later
If your server isn't directly hooked into your GraphQL API, in your front end where you upload from, you could
await
the upload response which would return the URL and then run the
File mutation
from your front end.. but thats a fair bit grosser