class Code
Language | Type name |
---|---|
![]() | Amazon.CDK.AWS.AppSync.Code |
![]() | github.com/aws/aws-cdk-go/awscdk/v2/awsappsync#Code |
![]() | software.amazon.awscdk.services.appsync.Code |
![]() | aws_cdk.aws_appsync.Code |
![]() | aws-cdk-lib » aws_appsync » Code |
Implemented by
Asset
, Inline
Represents source code for an AppSync Function or Resolver.
Example
declare const api: appsync.GraphqlApi;
const myJsFunction = new appsync.AppsyncFunction(this, 'function', {
name: 'my_js_function',
api,
dataSource: api.addNoneDataSource('none'),
code: appsync.Code.fromAsset('directory/function_code.js'),
runtime: appsync.FunctionRuntime.JS_1_0_0,
});
new appsync.Resolver(this, 'PipelineResolver', {
api,
typeName: 'typeName',
fieldName: 'fieldName',
code: appsync.Code.fromInline(`
// The before step
export function request(...args) {
console.log(args);
return {}
}
// The after step
export function response(ctx) {
return ctx.prev.result
}
`),
runtime: appsync.FunctionRuntime.JS_1_0_0,
pipelineConfig: [myJsFunction],
});
Initializer
new Code()
Methods
Name | Description |
---|---|
bind(scope) | Bind source code to an AppSync Function or resolver. |
static from | Loads the function code from a local disk path. |
static from | Inline code for AppSync function. |
bind(scope)
public bind(scope: Construct): CodeConfig
Parameters
- scope
Construct
Returns
Bind source code to an AppSync Function or resolver.
static fromAsset(path, options?)
public static fromAsset(path: string, options?: AssetOptions): AssetCode
Parameters
- path
string
— The path to the source code file. - options
Asset
Options
Returns
Loads the function code from a local disk path.
static fromInline(code)
public static fromInline(code: string): InlineCode
Parameters
- code
string
— The actual handler code (the resulting zip file cannot exceed 4MB).
Returns
Inline code for AppSync function.