GraphQL mutate operation failed. NonRetryableException{message=OkHttp client request failed., cause=null, recoverySuggestion=Irrecoverable error}

GraphQL mutate operation failed. NonRetryableException{message=OkHttp client request failed., cause=null, recoverySuggestion=Irrecoverable error}


2

Graphql mutation operation fails in android but works in AppSync console

Error:

GraphQL mutate operation failed
E/amplify:flutter:api( 4899): NonRetryableException{message=OkHttp client request failed., cause=null, recoverySuggestion=Irrecoverable error}
E/amplify:flutter:api( 4899): at com.amplifyframework.api.aws.AppSyncGraphQLOperation$OkHttpCallback.onResponse(AppSyncGraphQLOperation.java:145)
E/amplify:flutter:api( 4899): at okhttp3.internal.connection.RealCall$AsyncCall.run(RealCall.kt:519)
E/amplify:flutter:api( 4899): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
E/amplify:flutter:api( 4899): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
E/amplify:flutter:api( 4899): at java.lang.Thread.run(Thread.java:920)
W/AtomicResult(mutate)( 4899): Attempted to send success value after initial reply
I/flutter ( 4899): ApiException(message: OkHttp client request failed., recoverySuggestion: Irrecoverable error, underlyingException: null)

code:


Product product = Product(
    name: 'Product1',
    description: "description",
    price: 20,
    type: ProductType.fruit,
    postType: PostType.sell,
    userID: user.userId);

try {
  final req = ModelMutations.create(product);
  var res = await Amplify.API.mutate(request: req).response;
  print(res.data);
} catch (e) {
  print(e.toString());
}

Schema:

type User @model @auth(rules:[{allow:owner,operations:[create,update]}]){
id: ID!
name: String!
email: String!
product: [Product] @hasmany(indexName:"byUser",fields:["id"])
}

type Product @model @auth(rules:[{allow:owner,operations:[create,delete]}]) {
id: ID!
name: String!
description: String!
price: Int!
type: ProductType! @Index(name:"byProductType")
postType: PostType! @Index(name:"byPostType")
userID: ID! @Index(name:"byUser")
}

enum PostType{
sell
buy
}

enum ProductType{
vegetable
fruit
spice
other
} ```

1

  • Did you find any solution? I have the same issue.

    – Dhanuka Perera

    Oct 18, 2022 at 12:40

1 Answer
1


0

Issue is regarding default authorization mode which is API in your case, To Fix this issue you have to first update your Amplify API then Push those changes to Amplify.

Open terminal from your root/Amplify folder and then amplify update api (Official docs) and after completing it amplify push

Some other ways – Upgrade all the AWS Library/Packages & Update Amplify to new version by writing this command on terminal amplify upgrade (if any update is available)



Leave a Reply

Your email address will not be published. Required fields are marked *