Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS Appsync $ctx vs $context in resolvers

I understand that context is what ever name you define in your Lambda functions but when it comes to Appsync resolvers I'm a bit confused. I've seen both $ctx and $context being used in AppSync resolvers including in AWS docs. Some of AWS's own code generation tools like AWS Amplify CLI create resolvers that use both in the same code! I can't find anything in the docs explaining this. What's going on here?

like image 240
user3376065 Avatar asked Mar 19 '19 14:03

user3376065


People also ask

What are AWS AppSync resolvers?

Data sources and resolvers are how AWS AppSync translates GraphQL requests and fetches information from your AWS resources. AWS AppSync has support for automatic provisioning and connections with certain data source types.

How do I test AppSync resolver?

Testing ResolversIn the AWS AppSync console, go to the Schema page, and choose an existing resolver on the right to edit it. Or, choose Attach to add a new resolver. At the top of the page, choose Select test context, choose Create new context, and then enter a name.

Does AWS AppSync use API gateway?

You can use AWS AppSync as a single interface to access and combine data from multiple microservices in your application, even if they're running in different environments such as containers in a VPC, behind a REST API on Amazon API Gateway, or behind a GraphQL API on another AWS AppSync endpoint.

Does AWS amplify use AppSync?

The Amplify CLI provides support for AppSync that make this process easy. Using the CLI, you can configure an AWS AppSync API, download required client side configuration files, and generate client side code within minutes by running a few simple commands on the command line.


Video Answer


1 Answers

(AWS AppSync dev here)

$ctx and $context in AWS AppSync refer to the same Resolver Context. We added $ctx as an alias for $context to reduce the number of characters users have to type ($ctx is 50% shorter than $context!!)

Choosing $context or $ctx is a personal preference. I prefer $ctx when I'm authoring AWS AppSync resolvers.

like image 51
Rohan Deshpande Avatar answered Oct 01 '22 03:10

Rohan Deshpande