apollographql / apollo-ios

📱  A strongly-typed, caching GraphQL client for iOS, written in Swift.
https://www.apollographql.com/docs/ios/
MIT License
3.88k stars 725 forks source link

Apollo GraphQL Multiple files not uploading #2383

Open yashFP opened 2 years ago

yashFP commented 2 years ago

Bug report

Apollo GraphQL Multiple files not uploading

Write your query or mutation here

mutation createDailyLogs($input: dailyLogsData!) { createDailyLogs(input: $input) {

status
message
data {
    id_daily_log,
  }
}

}


dailyLogsData Inputs : type dailyLogsData { id_job_schedule: String id_daily_log: String note: String date: String files: [Upload]

}


Implementation : let img = (UIImage(named: "image")?.pngData())! let file1 = GraphQLFile(fieldName: "files", originalName: "files1.png", mimeType: "image/png", data: img) let file2 = GraphQLFile(fieldName: "files", originalName: "files2.png", mimeType: "image/png", data: img)

    let objDailyLogsData = dailyLogsData(idJobSchedule: "123", note: "test", date: "07/20/2022", files: ["0","1"],weather: ", shareCustomerPortal: false, jobNo: "123")
            let uploadData = CreateDailyLogsMutation(input: objDailyLogsData)

    Network.shared.apollo.upload(operation: uploadData, files: [file1,file2])

    Not working this

Versions

Please fill in the versions you're currently using:

calvincestari commented 2 years ago

Hi @yashFP, as a start I'd suggest updating to the latest version which is 0.52.0. What else have you tried to resolve the issue?

yashFP commented 2 years ago

@calvincestari still got error

Error :

Received a 400 error. Data returned as a String was: {"errors":[{"message":"Variable \"$input\" got invalid value \"0\" at \"input.files[0]\"; Upload value invalid.","locations":[{"line":1,"column":26}],"extensions":{"code":"BAD_USER_INPUT","exception":{"stacktrace":["GraphQLError: Variable \"$input\" got invalid value \"0\" at \"input.files[0]\"; Upload value invalid."," at /app/node_modules/graphql/execution/values.js:116:15"," at coerceInputValueImpl (/app/node_modules/graphql/utilities/coerceInputValue.js:131:9)"," at /app/node_modules/graphql/utilities/coerceInputValue.js:70:14"," at Array.map ()"," at safeArrayFrom (/app/node_modules/graphql/jsutils/safeArrayFrom.js:36:23)"," at coerceInputValueImpl (/app/node_modules/graphql/utilities/coerceInputValue.js:68:50)"," at coerceInputValueImpl (/app/node_modules/graphql/utilities/coerceInputValue.js:105:34)"," at coerceInputValueImpl (/app/node_modules/graphql/utilities/coerceInputValue.js:54:14)"," at coerceInputValue (/app/node_modules/graphql/utilities/coerceInputValue.js:37:10)"," at _loop (/app/node_modules/graphql/execution/values.js:109:69)"," at coerceVariableValues (/app/node_modules/graphql/execution/values.js:121:16)"," at getVariableValues (/app/node_modules/graphql/execution/values.js:50:19)"," at buildExecutionContext (/app/node_modules/graphql/execution/execute.js:203:61)"," at executeImpl (/app/node_modules/graphql/execution/execute.js:101:20)"," at Object.execute (/app/node_modules/graphql/execution/execute.js:60:35)"," at /app/node_modules/apollo-server-core/src/requestPipeline.ts:571:22"]}}}]}

HardikKardani commented 2 years ago

i am also facing same issue @yashFP

AnthonyMDev commented 2 years ago

Sorry we haven't gotten back to this one in a while. Firstly, we generally don't recommend doing file uploads via GraphQL. While our client does technically support it, the file upload spec is not fully fleshed out and has issues with a large number of edge cases. You can do file uploads with any other upload mechanism and just send the file names or ids via your GraphQL mutations.

If you are still struggling with this issue, it would be helpful to have a log of the entire HTTP request you are sending. The error logs shown look like the request may be malformed.

dannyhertz commented 1 year ago

Are you still seeing this issue @HardikKardani? We are still struggling to add multiple files when we cannot make them top level parameters to a mutation. Aka we need them nested within an input type.