@@ -4,9 +4,11 @@ import { IAppsyncFunction } from './appsync-function';
44import { CfnResolver } from './appsync.generated' ;
55import { CachingConfig } from './caching-config' ;
66import { BASE_CACHING_KEYS } from './caching-key' ;
7+ import { Code } from './code' ;
78import { BaseDataSource } from './data-source' ;
89import { IGraphqlApi } from './graphqlapi-base' ;
910import { MappingTemplate } from './mapping-template' ;
11+ import { FunctionRuntime } from './runtime' ;
1012
1113/**
1214 * Basic properties for an AppSync resolver
@@ -51,6 +53,19 @@ export interface BaseResolverProps {
5153 * @default - No max batch size
5254 */
5355 readonly maxBatchSize ?: number ;
56+
57+ /**
58+ * The functions runtime
59+ *
60+ * @default - no function runtime, VTL mapping templates used
61+ */
62+ readonly runtime ?: FunctionRuntime ;
63+ /**
64+ * The function code
65+ *
66+ * @default - no code is used
67+ */
68+ readonly code ?: Code ;
5469}
5570
5671/**
@@ -93,6 +108,15 @@ export class Resolver extends Construct {
93108 { functions : props . pipelineConfig . map ( ( func ) => func . functionId ) }
94109 : undefined ;
95110
111+ // If runtime is specified, code must also be
112+ if ( props . runtime && ! props . code ) {
113+ throw new Error ( 'Code is required when specifying a runtime' ) ;
114+ }
115+
116+ if ( props . code && ( props . requestMappingTemplate || props . responseMappingTemplate ) ) {
117+ throw new Error ( 'Mapping templates cannot be used alongside code' ) ;
118+ }
119+
96120 if ( pipelineConfig && props . dataSource ) {
97121 throw new Error ( `Pipeline Resolver cannot have data source. Received: ${ props . dataSource . name } ` ) ;
98122 }
@@ -108,12 +132,16 @@ export class Resolver extends Construct {
108132 }
109133 }
110134
135+ const code = props . code ?. bind ( this ) ;
111136 this . resolver = new CfnResolver ( this , 'Resource' , {
112137 apiId : props . api . apiId ,
113138 typeName : props . typeName ,
114139 fieldName : props . fieldName ,
115140 dataSourceName : props . dataSource ? props . dataSource . name : undefined ,
116141 kind : pipelineConfig ? 'PIPELINE' : 'UNIT' ,
142+ runtime : props . runtime ?. toProperties ( ) ,
143+ codeS3Location : code ?. s3Location ,
144+ code : code ?. inlineCode ,
117145 pipelineConfig : pipelineConfig ,
118146 requestMappingTemplate : props . requestMappingTemplate ? props . requestMappingTemplate . renderTemplate ( ) : undefined ,
119147 responseMappingTemplate : props . responseMappingTemplate ? props . responseMappingTemplate . renderTemplate ( ) : undefined ,
0 commit comments