Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added support for cache keys from header mappings, (e.g. method.request.body) #72

Merged

Conversation

mgyarmathy
Copy link
Contributor

@mgyarmathy mgyarmathy commented Sep 1, 2020

HI @DianaIonita!

Similar to PR #65, I needed a way to configure API Gateway to cache responses from my GraphQL Lambda function using method.request.body as a cache key.

In order to prevent breaking changes, my solution was to branch off of the existing code if the cacheKeyParameter includes a value property, which indicates the cache key is from a mapped HTTP header. This new functionality also opens up the possibility of using other values like context.VARIABLE_NAME in mapping expressions as well.

I have updated the README and added additional tests to document this new functionality.

With the following configuration, I was able to achieve my desired configuration for a sample /graphql endpoint:

cats-graphql:
    handler: graphql/handler.handle
    events:
      - http:
          path: /graphql
          method: get
          caching:
            enabled: true
            cacheKeyParameters:
              - name: request.querystring.query
      - http:
          path: /graphql
          method: post
          integration: lambda
          caching:
            enabled: true
            cacheKeyParameters:
              - name: integration.request.header.bodyCacheHeader
                value: method.request.body

GET
image

POST
image

Copy link
Owner

@DianaIonita DianaIonita left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @mgyarmathy,

Thank you very much! I see now that in PR #65 the integration: lambda property on the endpoint was missing, which is why I couldn't get it to work. This code looks good and works just fine - I'll merge it in and create a release.

Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants