Hi ! I got this error with mutation & query too. Do you know why ?


Thanks
Same issue here. Swift 4.2 Xcode 10
Same issue in 'mutation' and 'fetch' with xcode 10. Any one got solution ??
The following worked for me:
let mutationInput = CreateUserSettingsInput(id: username, pauseSync: false, lastSyncDate: Int(NSDate().timeIntervalSince1970))
let mutation = CreateUserSettingsMutation(input: mutationInput)
self.appSyncClient?.perform(mutation: mutation) { (result, error) in
...
}
It is because the wrong field in result is accessed.
result.data.yourfield is OK but result.data.somewrongfield will raise this error.
@jxltom is right, using the proper field fixed it for me. I believe the error message should be improved.
Unfortunately the error message is coming from Swift rather than from us. I know Swift has been working to make its error messages from generics a bit less opaque, but there's not a lot we can do about it.
I'm going to close this one out, but please feel free to open a new issue if you run into any further problems!
There is no (result, error), just a response object that can be mapped to result or error. The code below highlights the new syntax. The new response object is called (result). Notice that it replaces (result, error):
let mutationInput = CreateUserSettingsInput(id: username, pauseSync: false, lastSyncDate: Int(NSDate().timeIntervalSince1970))
let mutation = CreateUserSettingsMutation(input: mutationInput)
self.appSyncClient?.perform(mutation: mutation) { (result) in
do {
// success value
let success = try result.get()
print("success: \(success)")
// data errors
let dataErrors = success.errors
print("dataErrors: \(dataErrors)")
// data
let data = success.data
print("data: \(data)")
// your field
success.data?.yourField
// or
data?.yourField
} catch {
// mutation error
let error = result.mapError({ (error) -> Error in
return error
})
print("error: \(error)")
}
}
Yep - this is also a totally valid way to access the Result. Personally I prefer the switch way of accessing it as I find it a bit easier to read:
client.perform(mutation: mutation) { result in
switch result {
case .success(let graphQLResult):
// Deal with GraphQLResult and its data and/or errors properties here
case .failure(let error):
// deal with network errors here
}
}
Yep - this is also a totally valid way to access the
Result. Personally I prefer theswitchway of accessing it as I find it a bit easier to read:client.perform(mutation: mutation) { result in switch result { case .success(let graphQLResult): // Deal with GraphQLResult and its data and/or errors properties here case .failure(let error): // deal with network errors here } }
Thank you @designatednerd I learned something new today!
You can view the result enum for Swift in the docs as Swift > Result
/// A value that represents either a success or a failure, including an
/// associated value in each case.
public enum Result
/// A success, storing a `Success` value.
case success(Success)
/// A failure, storing a `Failure` value.
case failure(Failure)
Most helpful comment
Yep - this is also a totally valid way to access the
Result. Personally I prefer theswitchway of accessing it as I find it a bit easier to read: