Skip to content

aws-appsync: javascript resolver support #22921

@mtliendo

Description

@mtliendo

Describe the feature

Based on this RFC, it would nice to explore what a CDK supported candidate would look like.

Use Case

I'd like the experimental L2 construct to support the JS runtime for AppSync resolvers

Proposed Solution

the datasource.createResolver() method should accept a code argument, a specified runtime, and make the mappingTemplates optional.

From this:

const appsyncFunction = new appsync.AppsyncFunction(this, 'function', {
  name: 'appsync_function',
  api,
  dataSource: api.addNoneDataSource('none'),
  requestMappingTemplate: appsync.MappingTemplate.fromFile('request.vtl'),
  responseMappingTemplate: appsync.MappingTemplate.fromFile('response.vtl'),
});

const pipelineResolver = new appsync.Resolver(this, 'pipeline', {
  api,
  dataSource: api.addNoneDataSource('none'),
  typeName: 'Query',
  fieldName: 'getDemos',
  requestMappingTemplate: appsync.MappingTemplate.fromFile('beforeRequest.vtl'),
  pipelineConfig: [appsyncFunction],
  responseMappingTemplate: appsync.MappingTemplate.fromFile('afterResponse.vtl'),
});

To this:

const appsyncFunction = new appsync.AppsyncFunction(this, 'function', {
  name: 'appsync_function',
  api, 
  dataSource: api.addNoneDataSource('none'),
  runtime:  appsync.Runtime.APPSYNC_JS,
  code: appsync.Code.fromAsset(path.join(__dirname, 'fn1.js'))
});

const pipelineResolver = new appsync.Resolver(this, 'pipeline', {
  api,
  dataSource: api.addNoneDataSource('none'),
  typeName: 'Query',
  fieldName: 'getDemos',
  code: appsync.Code.fromAsset(path.join(__dirname, 'pipelineMappings.js'))
  pipelineConfig: [appsyncFunction],
});

Other Information

No response

Acknowledgements

  • I may be able to implement this feature request
  • This feature might incur a breaking change

CDK version used

2.50.0

Environment details (OS name and version, etc.)

macOS

Metadata

Metadata

Assignees

No one assigned

    Labels

    @aws-cdk/aws-appsyncRelated to AWS AppSynceffort/mediumMedium work item – several days of effortfeature-requestA feature should be added or improved.p2

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions