0

GraphQL Schema:

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:

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

In this scenario. Customer table has only 4 columns : customerId, customerName, emailId, orderId but I need to hit an OrderDetails table if that is asked in the query. So I have written a Field Resolver for orderDetails and this orderDetails will take input from the customer data

Request Mapping Template of 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

How do I use this orderId from the same query as a input for the field resolver (OrderDetails table) ?

1 Answers1

0

You can use $ctx.source.orderId in your resolver for orderDetails.

Myz
  • 818
  • 1
  • 8
  • 21