aws-cdk-lib.aws_appsync.BaseResolverProps

interface BaseResolverProps

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

Basic properties for an AppSync resolver.

Example

// Create username and password secret for DB Cluster
const secret = new rds.DatabaseSecret(this, 'AuroraSecret', {
  username: 'clusteradmin',
});

// The VPC to place the cluster in
const vpc = new ec2.Vpc(this, 'AuroraVpc');

// Create the serverless cluster, provide all values needed to customise the database.
const cluster = new rds.ServerlessCluster(this, 'AuroraCluster', {
  engine: rds.DatabaseClusterEngine.AURORA_MYSQL,
  vpc,
  credentials: { username: 'clusteradmin' },
  clusterIdentifier: 'db-endpoint-test',
  defaultDatabaseName: 'demos',
});

// Build a data source for AppSync to access the database.
declare const api: appsync.GraphqlApi;
const rdsDS = api.addRdsDataSource('rds', cluster, secret, 'demos');

// Set up a resolver for an RDS query.
rdsDS.createResolver('QueryGetDemosRdsResolver', {
  typeName: 'Query',
  fieldName: 'getDemosRds',
  requestMappingTemplate: appsync.MappingTemplate.fromString(`
  {
    "version": "2018-05-29",
    "statements": [
      "SELECT * FROM demos"
    ]
  }
  `),
  responseMappingTemplate: appsync.MappingTemplate.fromString(`
    $utils.toJson($utils.rds.toJsonObject($ctx.result)[0])
  `),
});

// Set up a resolver for an RDS mutation.
rdsDS.createResolver('MutationAddDemoRdsResolver', {
  typeName: 'Mutation',
  fieldName: 'addDemoRds',
  requestMappingTemplate: appsync.MappingTemplate.fromString(`
  {
    "version": "2018-05-29",
    "statements": [
      "INSERT INTO demos VALUES (:id, :version)",
      "SELECT * WHERE id = :id"
    ],
    "variableMap": {
      ":id": $util.toJson($util.autoId()),
      ":version": $util.toJson($ctx.args.version)
    }
  }
  `),
  responseMappingTemplate: appsync.MappingTemplate.fromString(`
    $utils.toJson($utils.rds.toJsonObject($ctx.result)[1][0])
  `),
});

Properties

NameTypeDescription
fieldNamestringname of the GraphQL field in the given type this resolver is attached to.
typeNamestringname of the GraphQL type this resolver is attached to.
cachingConfig?CachingConfigThe caching configuration for this resolver.
code?CodeThe function code.
maxBatchSize?numberThe maximum number of elements per batch, when using batch invoke.
pipelineConfig?IAppsyncFunction[]configuration of the pipeline resolver.
requestMappingTemplate?MappingTemplateThe request mapping template for this resolver.
responseMappingTemplate?MappingTemplateThe response mapping template for this resolver.
runtime?FunctionRuntimeThe functions runtime.

fieldName

Type: string

name of the GraphQL field in the given type this resolver is attached to.


typeName

Type: string

name of the GraphQL type this resolver is attached to.


cachingConfig?

Type: CachingConfig (optional, default: No caching configuration)

The caching configuration for this resolver.


code?

Type: Code (optional, default: no code is used)

The function code.


maxBatchSize?

Type: number (optional, default: No max batch size)

The maximum number of elements per batch, when using batch invoke.


pipelineConfig?

Type: IAppsyncFunction[] (optional, default: no pipeline resolver configuration An empty array | undefined sets resolver to be of kind, unit)

configuration of the pipeline resolver.


requestMappingTemplate?

Type: MappingTemplate (optional, default: No mapping template)

The request mapping template for this resolver.


responseMappingTemplate?

Type: MappingTemplate (optional, default: No mapping template)

The response mapping template for this resolver.


runtime?

Type: FunctionRuntime (optional, default: no function runtime, VTL mapping templates used)

The functions runtime.