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?
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.
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.
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.
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.
(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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With