-
Notifications
You must be signed in to change notification settings - Fork 731
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Problem uploading a file with GraphQLFile #695
Comments
This is related to #681 (missing documentation). If you take a look at the expected string in the multi-part form data and the docs for the multi-part upload spec you can see the type of query you'd want to have is something like this: mutation ($file: Upload!) {
singleUpload(file: $file) {
id
}
} That |
Thanks a lot for your help, Ellen... I hope the example arrive soon, I still don't have success sending GraphQLFile to a GraphQL on a rails server... |
Is the issue you're having on the server side? If so, can we close this issue out? If not, can you be more specific about what's going wrong? |
To be honest, I'm not sure if is server side issue... I'm doing: I then create an extension Then in this line, I get this error I'm totally lost! |
You should not need to create that typealias yourself - can you post the generated code for |
Sure! Thanks a lot, Ellen! Cheers! public final class UploadFileMutation: GraphQLMutation { public let operationName = "UploadFile" public var file: Upload public init(file: Upload) { public var variables: GraphQLMap? { public struct Data: GraphQLSelectionSet {
} |
Hi! This is my mutation
This is my swift method: @discardableResult
func addImage(id: String,
image: Data,
source: String?,
copyright: String,
completion: @escaping (Swift.Result<ImageFragment, SupertrendsClientError>) -> Void) -> Cancellable {
let name = UUID().uuidString
let file = GraphQLFile(fieldName: name, originalName: name, mimeType: "image/jpeg", data: image)
let imageInput = ImageInput(copyright: copyright, source: source, upload: name, url: nil)
let query = AddImageMutation(id: id, image: imageInput)
return performUpload(query: query, files: [file], resultMap: { $0.addImage?.fragments.imageFragment }, completion: completion)
}
I have also added a type alias for my |
@kimdv Thanks a lot friend! I'll try that! One question the performUpload you've talked about just execute te mutation within Apollo? Thanks!!!!!!!! |
private func performUpload<Query: GraphQLMutation, Res>(query: Query,
files: [GraphQLFile],
resultMap: @escaping (Query.Data) -> Res?,
completion: @escaping (Swift.Result<Res, SupertrendsClientError>) -> Void) -> Cancellable {
return networkTransport.upload(operation: query, files: files) { result in
switch result {
case .success(let data):
if let object = try? Query.Data.init(jsonObject: data.body),
let model = resultMap(object) {
completion(.success(model))
} else {
completion(.failure(SupertrendsClientError.unknown))
}
case .failure(let error):
completion(.failure(SupertrendsClientError.unknown))
}
}
} Here it is |
And related to this. @designatednerd the reason I first had added the upload method to I think we should make is similar somehow |
@kimdv Thanks a lot my friend, I'll try that now, I really appreciate your help! |
@kdvtrifork Can you give me a little help with that? 2019-08-07T12:55:07.405171+00:00 app[web.1]: UploadFile ////
let configuration = URLSessionConfiguration.default Thanks a lot brother! |
I don't understand the question? The mutation and file creation looks good. |
@kimdv On the server, instead of multipart / form-data, the server is getting: |
The implication is based on this specification Does the server also follow that? |
@kdvtrifork I believe so, when I'm using Altair GraphQL, I'm able to perform uploads... if let imageData = image.jpegData(compressionQuality: 0.7) {
|
Looks like Altair is using the I would talk to your backend person about the spec - all of the examples there use |
Hi Ellen... The awkward thing is that the CURL example from specifications work with our backend... curl http://madari-staging.herokuapp.com/graphql Thanks again! |
The "back-end guy" checking in here to help my co-work @Cleversou1983 on this issue. The spec shows a Comparing the server log between the cURL shows:
Request from iOS shows:
|
So im not sure what is the problem here but there is something strange if the request... Again, the above CURL should work publicly if it helps us debug. I thing the server is ok... hope it help guys, thanks! |
OK so I see a couple possibilities here:
|
OK - well, I figured at least one thing out that I'll be fixing - it looks like the @kimdv I could use your help on another bit - looking at what comes out of using |
@designatednerd There is something a line 37. But I also thing that |
Yeah I've been working on testing with yoga's upload engine and it would reject anything that didn't have a section explicitly named Working on a PR. |
hmm okay! |
For everyone here: #707 should help significantly with a lot of these issues. |
Significant changes shipping with |
I need to upload image with following mutation in swift 5.0 mutation updateUserProfile ($userId:ID!,$userImage:Upload,$userDetail:UserInput!){ Can you please let me know how can I send a image data in $file |
@DeekshaApptunix You should use GraphQLFile, like this: In your mutation, pass as the file parameter, the name of the parameter, for example: |
@Cleversou1983 If I am sending data like you suggested then I am also getting error if let imageData = userImgVew.image?.jpegData(compressionQuality: 0.7) { Error : "createReadStream is not a function" |
|
I need to upload in this mutation if let logoData = btnCommunity.currentImage?.jpegData(compressionQuality: 0.8) , let coverData = coverImage.image?.jpegData(compressionQuality: 0.8) { let uploadData = CreateCommunityMutation(communityDetail:communityDetail, invitedusers: invitedUser, file: "(file)", communityLogo: "(logo)") Here is my mutation for the same mutation createCommunity($communityDetail:CommunityInput!,$invitedusers:[ID],$file:Upload,$communityLogo:Upload){ I am getting following error createReadStream is not a function |
@DeekshaApptunix let's try to concentrate your problems in issue #938 please. Thank you! |
Currently I have a mutation like this:
mutation uploadFile($file:Upload!) {
}
extension UploadFileMutation {
public typealias Upload = GraphQLFile
}
I've made an extension, so the compiler doesn't complain about the type
When I try use GraphQLFile as parameter
Cannot convert value of type 'UploadFileMutation.Upload' (aka 'GraphQLFile') to expected dictionary value type 'Optional'
I couldn't upload with HTTPTransportNetwork as well.. Could someone give some hints?
Thanks!
The text was updated successfully, but these errors were encountered: