GraphQL 变异操作失败。 NonRetryableException{message=OkHttp 客户端请求失败。, Cause=null, recoverySuggestion=不可恢复的错误}

问题描述 投票:0回答:1

Graphql 突变操作在 Android 中失败,但在 AppSync 控制台中有效

错误:

GraphQL 变异操作失败 E/amplify:flutter:api( 4899): NonRetryableException{message=OkHttp 客户端请求失败。, Cause=null, recoverySuggestion=不可恢复的错误} E/amplify:flutter:api(4899):位于 com.amplifyframework.api.aws.AppSyncGraphQLOperation$OkHttpCallback.onResponse(AppSyncGraphQLOperation.java:145) E/amplify:flutter:api(4899): 在 okhttp3.internal.connection.RealCall$AsyncCall.run(RealCall.kt:519) E /放大:flutter:api(4899):在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) E /放大:flutter:api(4899):在java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:641) E/amplify:flutter:api(4899):在java.lang.Thread.run(Thread.java:920) W/AtomicResult(mutate)(4899):尝试在初始回复后发送成功值 I/flutter(4899):ApiException(消息:OkHttp客户端请求失败。,recoverySuggestion:不可恢复的错误,underlyingException:null)

代码:


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());
}

架构:

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
} ```
flutter graphql aws-amplify aws-appsync
1个回答
0
投票

问题与默认授权模式有关,在您的情况下是 API,要解决此问题,您必须首先更新 Amplify API,然后将这些更改推送到 Amplify。

从根/Amplify 文件夹打开终端,然后

amplify update api
官方文档)并完成后
amplify push

其他一些方法 - 通过在终端上编写此命令来升级所有 AWS 库/包并将 Amplify 更新到新版本

amplify upgrade
(如果有任何更新可用)

© www.soinside.com 2019 - 2024. All rights reserved.