BaseResolverProps

class aws_cdk.aws_appsync.BaseResolverProps(*, field_name, type_name, caching_config=None, pipeline_config=None, request_mapping_template=None, response_mapping_template=None)

Bases: object

(experimental) Basic properties for an AppSync resolver.

Parameters
  • field_name (str) – (experimental) name of the GraphQL field in the given type this resolver is attached to.

  • type_name (str) – (experimental) name of the GraphQL type this resolver is attached to.

  • caching_config (Optional[CachingConfig]) – (experimental) The caching configuration for this resolver. Default: - No caching configuration

  • pipeline_config (Optional[Sequence[IAppsyncFunction]]) – (experimental) configuration of the pipeline resolver. Default: - no pipeline resolver configuration An empty array | undefined sets resolver to be of kind, unit

  • request_mapping_template (Optional[MappingTemplate]) – (experimental) The request mapping template for this resolver. Default: - No mapping template

  • response_mapping_template (Optional[MappingTemplate]) – (experimental) The response mapping template for this resolver. Default: - No mapping template

Stability

experimental

ExampleMetadata

infused

Example:

# Build a data source for AppSync to access the database.
# api is of type GraphqlApi
# Create username and password secret for DB Cluster
secret = rds.DatabaseSecret(self, "AuroraSecret",
    username="clusteradmin"
)

# The VPC to place the cluster in
vpc = ec2.Vpc(self, "AuroraVpc")

# Create the serverless cluster, provide all values needed to customise the database.
cluster = rds.ServerlessCluster(self, "AuroraCluster",
    engine=rds.DatabaseClusterEngine.AURORA_MYSQL,
    vpc=vpc,
    credentials={"username": "clusteradmin"},
    cluster_identifier="db-endpoint-test",
    default_database_name="demos"
)
rds_dS = api.add_rds_data_source("rds", cluster, secret, "demos")

# Set up a resolver for an RDS query.
rds_dS.create_resolver(
    type_name="Query",
    field_name="getDemosRds",
    request_mapping_template=appsync.MappingTemplate.from_string("""
          {
            "version": "2018-05-29",
            "statements": [
              "SELECT * FROM demos"
            ]
          }
          """),
    response_mapping_template=appsync.MappingTemplate.from_string("""
            $utils.toJson($utils.rds.toJsonObject($ctx.result)[0])
          """)
)

# Set up a resolver for an RDS mutation.
rds_dS.create_resolver(
    type_name="Mutation",
    field_name="addDemoRds",
    request_mapping_template=appsync.MappingTemplate.from_string("""
          {
            "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)
            }
          }
          """),
    response_mapping_template=appsync.MappingTemplate.from_string("""
            $utils.toJson($utils.rds.toJsonObject($ctx.result)[1][0])
          """)
)

Attributes

caching_config

(experimental) The caching configuration for this resolver.

Default
  • No caching configuration

Stability

experimental

Return type

Optional[CachingConfig]

field_name

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

Stability

experimental

Return type

str

pipeline_config

(experimental) configuration of the pipeline resolver.

Default

  • no pipeline resolver configuration

An empty array | undefined sets resolver to be of kind, unit

Stability

experimental

Return type

Optional[List[IAppsyncFunction]]

request_mapping_template

(experimental) The request mapping template for this resolver.

Default
  • No mapping template

Stability

experimental

Return type

Optional[MappingTemplate]

response_mapping_template

(experimental) The response mapping template for this resolver.

Default
  • No mapping template

Stability

experimental

Return type

Optional[MappingTemplate]

type_name

(experimental) name of the GraphQL type this resolver is attached to.

Stability

experimental

Return type

str