interface BaseResolverProps
Language | Type name |
---|---|
.NET | Amazon.CDK.AWS.AppSync.BaseResolverProps |
Java | software.amazon.awscdk.services.appsync.BaseResolverProps |
Python | aws_cdk.aws_appsync.BaseResolverProps |
TypeScript (source) | @aws-cdk/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({
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({
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
Name | Type | Description |
---|---|---|
field | string | name of the GraphQL field in the given type this resolver is attached to. |
type | string | name of the GraphQL type this resolver is attached to. |
caching | Caching | The caching configuration for this resolver. |
pipeline | IAppsync [] | configuration of the pipeline resolver. |
request | Mapping | The request mapping template for this resolver. |
response | Mapping | The response mapping template for this resolver. |
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:
Caching
(optional, default: No caching configuration)
The caching configuration for this resolver.
pipelineConfig?
Type:
IAppsync
[]
(optional, default: no pipeline resolver configuration
An empty array | undefined sets resolver to be of kind, unit)
configuration of the pipeline resolver.
requestMappingTemplate?
Type:
Mapping
(optional, default: No mapping template)
The request mapping template for this resolver.
responseMappingTemplate?
Type:
Mapping
(optional, default: No mapping template)
The response mapping template for this resolver.