0
votes

I am using Back4app backend for GraphQl and Apollo client for queries and mutations. Queries are fine, but i am unable to upload file to backend using perform mutation.

It says to perform mutation as FileInput , but I don’t know how to convert Uiimage to FileInput for writing to database. If I simply pass a string to FileInput, it is reaching database. But couldnot upload image.

Can someone give a suggestion

2

2 Answers

0
votes

You can upload a file to Parse using GraphQL by sending in a file with the FileType type, which has the upload property, which conforms to the Upload scaclar type.

A mutation for a class named Person, with a name (string), age (number) and photo (file), running on Parse 4.4 would look like this:

mutation createPerson{
  createPerson(input:{
    fields:{
      name: "Alex"
      age: 40
      photo: {
        upload: file
      }
    }
  }){
    person{
      id
    }
  }
}

Please notice that depending on the version of Parse that you are using, the syntax might be slightly different.

Also remember to pass the file as an upload as described here:

https://www.apollographql.com/docs/ios/mutations/#uploading-files

0
votes

The problem with that one Mutation you sent is that you try to set the image property as the $file, while you should set the upload like this:

mutation SingleFileUpload($file: Upload!,$filename: String!){
  createImages(input:{
    fields:{
      imagename: $filename
      image: {
          upload: $file
      }
    }
  }){
    images{
      imagename
      image{
        url
        name
      }
    }
  }
}

That should do the trick