aws-appsync-community icon indicating copy to clipboard operation
aws-appsync-community copied to clipboard

AppSync caching of a nested resolver on an array field

Open sebekz opened this issue 3 years ago • 0 comments

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

  • foos is [IdObject]
  • $context.source.foos is an array of {id: string} objects
  • nested resolver replaces it with an array of concrete domain objects retrieved from a service
  • foos becomes [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?

sebekz avatar Nov 28 '22 15:11 sebekz