aws / aws/aws-cdk

@aws-cdk/aws-appsync-alpha: No way to enable caching for AWS AppSync and its ResolvableFields

Open
#19,284 2 comments 4 reactions 0 assignees View on GitHub
@aws-cdk/aws-appsync feature-request p2
Dominant language
TypeScript
Stars
12.9k
Forks
4.6k
Avg merge
2d 3h
Merged PRs (30d)
83

Description

### General Issue

CDK: AWS AppSync per resolver caching

### The Question

We are trying to enable per-resolver caching for some of AWS AppSync queries with cdk:

1. L2 Construct GraphqlApi -> `import { GraphqlApi } from '@aws-cdk/aws-appsync-alpha';` does not offer any possibility to add caching configuration. Workaround currently is to use `CfnApiCache`, which is a bit unintuitive.
Here a sample:
```
const api = new GraphqlApi(this, 'MyAPI', {
...getApiConfiguration(this.config),
});

const cache = new CfnApiCache(this, 'MyAPICache', {
apiCachingBehavior: 'PER_RESOLVER_CACHING',
apiId: api.apiId,
ttl: Duration.seconds(30).toSeconds(),
type: 'SMALL',
atRestEncryptionEnabled: true,
transitEncryptionEnabled: true,
});
cache.addDependsOn(api.node.defaultChild as CfnGraphQLApi);
```

2. A major issue without any workaround: L1 Construct -> `CfnResolver` and its corresponding L2 Construct `Resolver` offer a resolver caching configuration, but using them doesn't work as their queries are not concatenated into the schema. Working with ResolvableFields for adding queries to my GraphQlApi works, but ResolvableFields isn't a L2 Construct, it has no caching config neither i can access its underlying cloudformation resouce.

Here a sample on adding my query using ResolvableField construct:
```
api.addQuery(
'getDummy',
new ResolvableField({
returnType: GraphqlType.string(),
pipelineConfig: appSyncFunctions,
requestMappingTemplate: requestTemplateLocalResolver(),
responseMappingTemplate: responseTemplateLocalResolver(),
})
);
```
Like described, there is no way to define a caching config for that field.

Here my attempt to define a resolver:
```
api.createResolver({
typeName: 'Query',
fieldName: 'getDummy',
pipelineConfig: appSyncFunctions,
requestMappingTemplate: requestTemplateLocalResolver(),
responseMappingTemplate: responseTemplateLocalResolver(),
cachingConfig: {
ttl: Duration.days(1),
cachingKeys: ['$context.arguments.id'],
},
});
```
This resolver is not added to my graphql schema.

And finally having Resolver and ResolvableField at the same time to add operations to my GraphQlApi feels very complicated. Maybe i am missing something to define per-resolver caching behaviour with CDK, would be grateful to get any feedback soon.

Best Regards

### CDK CLI Version

2.15.0

### Framework Version

2.15.0

### Node.js Version

v16.13.1

### OS

Windows 10

### Language

Typescript

### Language Version

4.5.4

### Other information

_No response_

Contributor guide

Open the contributing guide

Research direction

Start by comparing GraphqlApi, ResolvableField, Resolver, CfnResolver, and CfnApiCache in the issue examples, focusing on how schema fields and resolver caching are represented. The work is done when CDK provides a coherent way to configure AppSync API caching and per-resolver caching for fields added through GraphqlApi and ResolvableField.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, typescript
Domain
api, cloud
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.