Skip to content

Instantly share code, notes, and snippets.

@leegilmorecode
Created January 25, 2022 13:57
Show Gist options
  • Select an option

  • Save leegilmorecode/dd2fc95f0897c73c44351cc49622da4c to your computer and use it in GitHub Desktop.

Select an option

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
// 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