aws-cdk-lib.aws_appsync.Code

class Code

LanguageType name
.NETAmazon.CDK.AWS.AppSync.Code
Gogithub.com/aws/aws-cdk-go/awscdk/v2/awsappsync#Code
Javasoftware.amazon.awscdk.services.appsync.Code
Pythonaws_cdk.aws_appsync.Code
TypeScript (source)aws-cdk-lib » aws_appsync » Code

Implemented by AssetCode, InlineCode

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

NameDescription
bind(scope)Bind source code to an AppSync Function or resolver.
static fromAsset(path, options?)Loads the function code from a local disk path.
static fromInline(code)Inline code for AppSync function.

bind(scope)

public bind(scope: Construct): CodeConfig

Parameters

  • scope Construct

Returns

  • CodeConfig

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 AssetOptions

Returns

  • AssetCode

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 (limited to 4KiB).

Returns

  • InlineCode

Inline code for AppSync function.