@@ -4,9 +4,11 @@ import { IAppsyncFunction } from './appsync-function';
4
4
import { CfnResolver } from './appsync.generated' ;
5
5
import { CachingConfig } from './caching-config' ;
6
6
import { BASE_CACHING_KEYS } from './caching-key' ;
7
+ import { Code } from './code' ;
7
8
import { BaseDataSource } from './data-source' ;
8
9
import { IGraphqlApi } from './graphqlapi-base' ;
9
10
import { MappingTemplate } from './mapping-template' ;
11
+ import { FunctionRuntime } from './runtime' ;
10
12
11
13
/**
12
14
* Basic properties for an AppSync resolver
@@ -51,6 +53,19 @@ export interface BaseResolverProps {
51
53
* @default - No max batch size
52
54
*/
53
55
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 ;
54
69
}
55
70
56
71
/**
@@ -93,6 +108,15 @@ export class Resolver extends Construct {
93
108
{ functions : props . pipelineConfig . map ( ( func ) => func . functionId ) }
94
109
: undefined ;
95
110
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
+
96
120
if ( pipelineConfig && props . dataSource ) {
97
121
throw new Error ( `Pipeline Resolver cannot have data source. Received: ${ props . dataSource . name } ` ) ;
98
122
}
@@ -108,12 +132,16 @@ export class Resolver extends Construct {
108
132
}
109
133
}
110
134
135
+ const code = props . code ?. bind ( this ) ;
111
136
this . resolver = new CfnResolver ( this , 'Resource' , {
112
137
apiId : props . api . apiId ,
113
138
typeName : props . typeName ,
114
139
fieldName : props . fieldName ,
115
140
dataSourceName : props . dataSource ? props . dataSource . name : undefined ,
116
141
kind : pipelineConfig ? 'PIPELINE' : 'UNIT' ,
142
+ runtime : props . runtime ?. toProperties ( ) ,
143
+ codeS3Location : code ?. s3Location ,
144
+ code : code ?. inlineCode ,
117
145
pipelineConfig : pipelineConfig ,
118
146
requestMappingTemplate : props . requestMappingTemplate ? props . requestMappingTemplate . renderTemplate ( ) : undefined ,
119
147
responseMappingTemplate : props . responseMappingTemplate ? props . responseMappingTemplate . renderTemplate ( ) : undefined ,
0 commit comments