0

I am very new to GraphQL, Appsync and Amplify. I am using AWS AppSync with Amplify to fetch records from a DynamoDB table via GraphQL queries. The front end is in ReactJS. Looking at some examples on the aws docs, it seems like I can fetch records back in JSON format, the same way it was stored in the table. I wanted to find some documentation or example on how to iterate through the recordset returned and perform some calculations on the data returned before it is sent back to the client. But I am not able to relate the documentation online to what I want to achieve.

For eg. if the json returned has 3 columns because there are only three columns in the backing DynamoDB table, but I would like to return a fourth column that is a computed value based on some external condition that works on the three columns returned from the graphql query's response. What kind of resolver will I need to use? I want to be able to send some parameters to this query as well so that based on the parameters sent in I can filter out the response and the client sees the data only after the custom business logic has been applied on it. Should I create an API that calls the GraphQL Api and then performs some logic within that API or use a DynamoDB resolver or a Lambda resolver or a GraphQL resolver? Amplify generates all the queries and mutations in the amplify project, so not sure where do I write these resolvers. I need all this logic to stay server side only. I am looking for a start point to investigate unless there is a working example available that will help me iterate thru the records returned by the GraphQL API on the server side and return data that has been customized and filtered.

Thanks for your help.

user20358
  • 14,182
  • 36
  • 114
  • 186

1 Answers1

0

You can manipulate your response in your resolver. If using VTL resolvers then look at $ctx.result and you can do anything the vtl supports with it. Another thing you can do, and is your best option if you need to do anything other than some basic string manipulation IMO, is use direct Lambda resolvers. This allows you to execute any arbitrary code you want in your resolver.

OneLiner
  • 571
  • 2
  • 6