https://graphql.github.io/learn/
GraphQL is a query language for your API, and a server-side runtime for executing queries by using a type system you define for your data
Use raw http request to upload files.
Sorry to reopen the thread, but then do you recommend not using GraphQL to handle file uploads? How would you handle uploading a file that has data as a description attached?
Example:
Upload a file and a text that describes what the file is for.
Would you upload the file with a HTTP RAW request and the description of the file as a GraphQL request? Or would you upload file and text as RAW? Thank you!
apollo-server support upload file and there are JS implementation Client support using GraphQL to upload file.
https://github.com/jaydenseric/graphql-multipart-request-spec
https://github.com/jaydenseric/apollo-upload-client
I wish apollo-android support this feature.
Exactly! @sav007 I believe you are dismissing these requests to eagerly, Apollo itself supports file uploads: https://blog.apollographql.com/file-uploads-with-apollo-server-2-0-5db2f3f60675 We just need to get the Android lib in parity.
Pr welcome 馃檪
Someone already linked their implementation in another issue which was abruptly closed: https://github.com/apollographql/apollo-android/issues/640#issuecomment-435693636
It was closed before example. I reopened it. No one is against the feature just not a priority for implementation for anyone
I would love to see this implemented.
Hello
I have to send file with message please suggest right code
I hope this serves as something, success!
try {
val fileToUpload = File(path)
val requestBody = MultipartBody.Builder().setType(MultipartBody.FORM).also {
addFormDataPart("operations", "{\"query\": \"mutation x(\$id: Int!, \$file: Upload!) { x( id: \$id, file: \$file ) { id, path } }\", \"variables\": { \"id\": 1,\"file\": null } }")
addFormDataPart("map", "{ \"0\": [\"variables.file\"] }")
addFormDataPart(
"0",
fileToUpload.name,
RequestBody.create(MediaType.parse("image/jpg"), fileToUpload)
)
}
val request = Request.Builder()
.url(serverURL)
.post(requestBody)
.build()
okHttpClient.newCall(request).enqueue(object : Callback {
override fun onFailure(call: Call, e: IOException) {
e.printStackTrace()
}
@Throws(IOException::class)
override fun onResponse(call: Call, response: Response) {
if (response.isSuccessful) {
println("OK")
} else {
println(response.body())
}
}
})
} catch (ex: Exception) {
ex.printStackTrace()
}
Most helpful comment
I would love to see this implemented.