如何在 android 中集成 Appsync api

How to integrate Appsync api in android

我给了一个亚马逊api进行整合。但是我不知道如何使用这个 api

 mutation createTrail {
   createTruckTrailer(input:{truckId: "077",trailer:["AB22D"]}){
    result
  }
}

使用 rxJava 或协程进行改造。

您获得的代码片段是 GraphQL 查询的示例,它可以发送到 GraphQL-enabled 端点,例如您获得的使用 AWS AppSync 托管的端点。 GraphQL 查询的结构不同于 REST api 调用;将其视为进行 REST 调用的结构化方式。请求被发送到您在上面的 POST HTTP 请求中粘贴的 ApiUrl,请求 body 看起来像:

{
    "query": "mutation createTrail {\n createTruckTrailer(input:{truckId: \"077\",trailer:[\"AB22D\"]}){\n result }\n }",
    "operationName": "createTrail",
    "variables": {}
}

但是,需要额外 headers 才能使用 IAM 进行身份验证。来自服务器的响应将包含结果 JSON。我强烈建议在这里花几分钟时间来熟悉一下 GraphQL:https://graphql.org/learn/

要从 Android 调用此 AppSync 端点,请查看 Amplify android 客户端,它解释了如何在此处开始(跳过第 4 步):https://aws-amplify.github.io/docs/android/start, and then setup your client to authenticate with IAM to your backend here: https://aws-amplify.github.io/docs/android/api#iam

一旦你的放大客户端完全设置好,你可以按照这里的步骤进行上面显示的 GraphQL 突变:https://aws-amplify.github.io/docs/android/api#import-sdk-and-config