Created
January 25, 2022 13:57
-
-
Save leegilmorecode/dd2fc95f0897c73c44351cc49622da4c to your computer and use it in GitHub Desktop.
Example of a mutation resolver which evicts the entry from the AppSync cache
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // updateBlog mutation with cache invalidation | |
| blogTableDataSource.createResolver({ | |
| typeName: "Mutation", | |
| fieldName: "updateBlog", | |
| // this is an example of a vtl template generated with the helper methods | |
| requestMappingTemplate: appsync.MappingTemplate.dynamoDbPutItem( | |
| appsync.PrimaryKey.partition("id").is("input.id"), | |
| appsync.Values.projecting("input") | |
| ), | |
| // this is an example of an inline vtl response template (you can also pull in from a file) | |
| responseMappingTemplate: appsync.MappingTemplate.fromString(` | |
| #set($cachingKeys = {}) | |
| $util.qr($cachingKeys.put("context.arguments.id", $context.arguments.input.id)) | |
| $extensions.evictFromApiCache("Query", "getBlogNoDax", $cachingKeys) | |
| $util.toJson($context.result) | |
| `), | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment