Stylianos Gakis
01/14/2022, 12:34 PM// graphqls
mutation UploadFile($file: Upload!){
uploadFile(file: $file) { //stuff }
}
uploadFile(file: Upload!): File!
type File { // stuff }
// kt
private suspend fun uploadFile(path: String, mimeType: String): Response<UploadFileMutation.Data> {
val uploadFileMutation = UploadFileMutation(
file = FileUpload(mimeType, path)
)
return apolloClient.mutation(uploadFileMutation).execute()
}
and it’d work. Mind you, we were calling this method once with a file that we did .path
on it, and once on a Uri
that we did .path
on it too. (so not all of our cases can be fixed with the
Now with the new documentation mentioning “okioSource” as someone who has never worked with okio it’s not obvious what I should do to not break this. Maybe worth a mention in the migration logs? At least a link to okio documentation on this?mbonnin
01/14/2022, 12:42 PMfile
on the JVM:
// or if you're on the JVM
val upload = DefaultUpload.Builder()
.content(file)
.build()
mbonnin
01/14/2022, 12:44 PMpath
but it feels a bit superfluous given that you can get a File from a path with File(path)
:
val upload = DefaultUpload.Builder()
.content(File(path))
.build()
Stylianos Gakis
01/14/2022, 12:56 PMmbonnin
01/14/2022, 12:59 PMmbonnin
01/14/2022, 1:00 PMmbonnin
01/14/2022, 1:01 PMfun FileUpload.Companion.create(mimetype: String, filePath: String): FileUpload {
val file = File(filePath)
return object : FileUpload(mimetype) {
override fun contentLength() = file.length()
override fun fileName() = file.name
override fun writeTo(sink: BufferedSink) {
sink.writeAll(file.source().buffer())
}
}
}
Stylianos Gakis
01/14/2022, 1:14 PMmbonnin
01/14/2022, 1:14 PM