I need to upload an image from iOS Client to NestJS server
Here is the munation
createSellerProfile(seller: SellerInput, userId: ID!, uploads: Upload): Seller
iOS Client’s .graphql file:
mutation createSellerProfile($seller: SellerInput, $userId: ID!, $uploads: Upload) {
createSellerProfile (seller: $seller, userId: $userId, uploads: $uploads) {
id
firstName
lastName
}
}
And this is the client’s code
let avaimg = avatarImage.jpegData(compressionQuality: 0.1)
let file = GraphQLFile(fieldName: "avatar", originalName: "avatar", mimeType: "image/jpeg", data: avaimg)
let sellerData = SellerInput(firstName: "phuong", lastName: "nguyen", description: "Hello, this is Phuong. I am freelance web developer")
Network.shared.apollo.upload(operation: CreateSellerProfileMutation(seller: sellerData,
userId: "4d146299-a219-4bde-9874-bed936dda129", uploads: "avatar"), files: [file]) {
res in
switch (res) {
case .success(let graphQLResult):
print("success")
case .failure(let error):
print("error: \(error)")
}
}
But on my NestJS server, I only receive a single string “avatar” for my uploads field instead of file content. Please help me out, thank you.