【问题标题】:Field resolver in Appsync using the same query output as argumentAppsync 中的字段解析器使用与参数相同的查询输出
【发布时间】:2020-11-19 18:28:08
【问题描述】:

GraphQL 架构:

type Query {
      getCustomer(customerId:Int!):Customer
}
type Customer {
      customerId : Int
      customerName : String
      emailId: String
      orderId: Int
      orderDetails(limit:Int):[OrderDetails]
}
type OrderDetails {
      orderId: Int
      productId: Int
      quantityOrdered: Int
      totalCost: Int
}

GraphQL 查询:

query getCustomer {
   getCustomer(customerId:100){
      customerName
      orderId
      orderDetails(limit:1){
          quantityOrdered
      }
   }
}

在这种情况下。 Customer 表只有 4 列:customerId、customerName、emailId、orderId 但如果在查询中询问,我需要点击 OrderDetails 表。所以我为 orderDetails 编写了一个字段解析器,这个 orderDetails 将从 customer 数据中获取输入

orderDetails Resolver的请求映射模板

{
    "version": "2017-02-28",
    "operation": "GetItem",
    "key": {
        "orderId": $util.dynamodb.toDynamoDBJson($ctx.args.orderId),
    }
}

for better understanding of my issue check this image

如何将同一查询中的这个 orderId 用作字段解析器(OrderDetails 表)的输入

【问题讨论】:

    标签: graphql aws-appsync resolver


    【解决方案1】:

    您可以在解析器中使用 $ctx.source.orderId 获取 orderDetails。

    【讨论】:

      猜你喜欢
      • 2019-10-03
      • 2021-04-04
      • 2020-02-12
      • 2019-02-04
      • 2022-12-14
      • 2019-09-24
      • 2019-04-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多