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

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

Open
SchollSimon opened this issue Mar 8, 2022 · 2 comments
Labels
@aws-cdk/aws-appsync Related to AWS AppSync feature-request A feature should be added or improved. p1

Comments

@SchollSimon
Copy link

SchollSimon commented Mar 8, 2022

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);
  1. 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

@SchollSimon SchollSimon added guidance Question that needs advice or information. needs-triage This issue or PR still needs to be triaged. labels Mar 8, 2022
@peterwoodworth peterwoodworth added feature-request A feature should be added or improved. p1 @aws-cdk/aws-appsync Related to AWS AppSync and removed needs-triage This issue or PR still needs to be triaged. labels Mar 14, 2022
@peterwoodworth
Copy link
Contributor

Thanks for raising this issue, there is no clear way to do this.

Workaround reported here #13269 (comment)

@peterwoodworth peterwoodworth removed the guidance Question that needs advice or information. label Mar 14, 2022
@SchollSimon
Copy link
Author

Hi thanks for the fast response, do you have any plan or timeline to implement this?
It is a very basic and urgent feature of AWS AppSync for our company.

Best Regards

@otaviomacedo otaviomacedo removed their assignment Jun 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-appsync Related to AWS AppSync feature-request A feature should be added or improved. p1
Projects
None yet
Development

No branches or pull requests

5 participants