aws-appsync-community
aws-appsync-community copied to clipboard
AppSync caching of a nested resolver on an array field
Context
I am trying to set up AppSync caching for a nested resolver. The field itself is an array of objects.
- type: CoolFoos
kind: PIPELINE
field: foos
request: foos/Transform.flattenIds.request.vtl
functions:
- GetFoosNRFunction
caching:
keys:
- $context.source.foos
ttl: 300
In short
foosis[IdObject]$context.source.foosis an array of{id: string}objects- nested resolver replaces it with an array of concrete domain objects retrieved from a service
foosbecomes[Foo]
Problem
I could not find a way to set a unique caching key based on the values of $context.source.foos. What I've tried was:
$context.source.foos(array of objects)$context.source.foos.id(name of the enclosed object field)$context.source.ids(result of the BEFORE request mapping - all ids as single string)$context.source(complete source)
None of these worked. Responses are not being cached (no cache hits, each subsequent request hits the GetFoosNRFunction).
When I replaced keys with $context.identity.sub it worked, so it's obvious that the keys built from $context.source did not work.
Is this a supported use case? What am I missing?