# BaseDataSource

Abstract AppSync datasource implementation.

Do not use directly but use subclasses for concrete datasources

Extends: [Construct](/cdk/api/v2/docs/constructs.Construct.html) › BaseDataSource
Implements: [IConstruct](/cdk/api/v2/docs/constructs.IConstruct.html), [IDependable](/cdk/api/v2/docs/constructs.IDependable.html)
Superclass of: [BackedDataSource](/cdk/api/v2/docs/aws-cdk-lib.aws_appsync.BackedDataSource.html), [DynamoDbDataSource](/cdk/api/v2/docs/aws-cdk-lib.aws_appsync.DynamoDbDataSource.html), [ElasticsearchDataSource](/cdk/api/v2/docs/aws-cdk-lib.aws_appsync.ElasticsearchDataSource.html), EventBridgeDataSource, HttpDataSource, LambdaDataSource, NoneDataSource, OpenSearchDataSource, RdsDataSource

- Source: [`aws-appsync/lib/data-source.ts`](https://github.com/aws/aws-cdk/blob/v2.277.0/packages/aws-cdk-lib/aws-appsync/lib/data-source.ts#L138)
- Type last changed: v2.60.0 · 12 Jan 2023

## Example

TypeScript:

```ts
declare const api: appsync.GraphqlApi;
declare const appsyncFunction: appsync.AppsyncFunction;

const pipelineResolver = new appsync.Resolver(this, 'pipeline', {
  api,
  dataSource: api.addNoneDataSource('none'),
  typeName: 'typeName',
  fieldName: 'fieldName',
  requestMappingTemplate: appsync.MappingTemplate.fromFile('beforeRequest.vtl'),
  pipelineConfig: [appsyncFunction],
  responseMappingTemplate: appsync.MappingTemplate.fromFile('afterResponse.vtl'),
});
```

Python:

```python
# api: appsync.GraphqlApi
# appsync_function: appsync.AppsyncFunction

pipeline_resolver = appsync.Resolver(self, "pipeline",
    api=api,
    data_source=api.add_none_data_source("none"),
    type_name="typeName",
    field_name="fieldName",
    request_mapping_template=appsync.MappingTemplate.from_file("beforeRequest.vtl"),
    pipeline_config=[appsync_function],
    response_mapping_template=appsync.MappingTemplate.from_file("afterResponse.vtl")
)
```

Java:

```java
GraphqlApi api;
AppsyncFunction appsyncFunction;

Resolver pipelineResolver = Resolver.Builder.create(this, "pipeline")
        .api(api)
        .dataSource(api.addNoneDataSource("none"))
        .typeName("typeName")
        .fieldName("fieldName")
        .requestMappingTemplate(MappingTemplate.fromFile("beforeRequest.vtl"))
        .pipelineConfig(List.of(appsyncFunction))
        .responseMappingTemplate(MappingTemplate.fromFile("afterResponse.vtl"))
        .build();
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
GraphqlApi api;
AppsyncFunction appsyncFunction;

var pipelineResolver = new Resolver(this, "pipeline", new ResolverProps {
    Api = api,
    DataSource = api.AddNoneDataSource("none"),
    TypeName = "typeName",
    FieldName = "fieldName",
    RequestMappingTemplate = MappingTemplate.FromFile("beforeRequest.vtl"),
    PipelineConfig = new [] { appsyncFunction },
    ResponseMappingTemplate = MappingTemplate.FromFile("afterResponse.vtl")
});
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
var api GraphqlApi
var appsyncFunction AppsyncFunction

pipelineResolver := appsync.NewResolver(this, jsii.String("pipeline"), &ResolverProps{
	Api: Api,
	DataSource: api.AddNoneDataSource(jsii.String("none")),
	TypeName: jsii.String("typeName"),
	FieldName: jsii.String("fieldName"),
	RequestMappingTemplate: appsync.MappingTemplate_FromFile(jsii.String("beforeRequest.vtl")),
	PipelineConfig: []IFunctionConfigurationRef{
		appsyncFunction,
	},
	ResponseMappingTemplate: appsync.MappingTemplate_*FromFile(jsii.String("afterResponse.vtl")),
})
```

## Initializer

TypeScript:

```ts
new BaseDataSource(scope: Construct, id: string, props: BackedDataSourceProps, extended: ExtendedDataSourceProps)
```

Python:

```python
BaseDataSource(scope: Construct, id: str, props: BackedDataSourceProps, extended: ExtendedDataSourceProps)
```

Java:

```java
new BaseDataSource(Construct scope, String id, BackedDataSourceProps props, ExtendedDataSourceProps extended)
```

C# / .NET:

```csharp
new BaseDataSource(Construct scope, string id, BackedDataSourceProps props, ExtendedDataSourceProps extended)
```

Golang:

```go
NewBaseDataSource(Scope Construct, Id *string, Props BackedDataSourceProps, Extended ExtendedDataSourceProps)
```

## Construct Props

- `api`: [IGraphQLApiRef](/cdk/api/v2/docs/aws-cdk-lib.interfaces.aws_appsync.IGraphQLApiRef.html) (required) — The API to attach this data source to.

- `description`: string = None — the description of the data source.

- `metricsConfig`: [DataSourceMetricsConfig](/cdk/api/v2/docs/aws-cdk-lib.aws_appsync.DataSourceMetricsConfig.html) — Whether to enable enhanced metrics of the data source Value will be ignored, if `enhancedMetricsConfig.dataSourceLevelMetricsBehavior` on AppSync GraphqlApi construct is set to `FULL_REQUEST_DATA_SOURCE_METRICS`.

  **Default:** no metrics configuration

- `name`: string — The name of the data source.

  **Default:** id of data source

- `serviceRole`: [IRole](/cdk/api/v2/docs/aws-cdk-lib.aws_iam.IRole.html) — The IAM service role to be assumed by AppSync to interact with the data source.

  **Default:** Create a new role

## Construct Props

- `dynamoDbConfig`: [IResolvable](/cdk/api/v2/docs/aws-cdk-lib.IResolvable.html) | [CfnDataSource.DynamoDBConfigProperty](/cdk/api/v2/docs/aws-cdk-lib.aws_appsync.CfnDataSource.DynamoDBConfigProperty.html) — configuration for DynamoDB Datasource.

  **Default:** No config

- `elasticsearchConfig`: [IResolvable](/cdk/api/v2/docs/aws-cdk-lib.IResolvable.html) | [CfnDataSource.ElasticsearchConfigProperty](/cdk/api/v2/docs/aws-cdk-lib.aws_appsync.CfnDataSource.ElasticsearchConfigProperty.html) — - use `openSearchConfig`

  **Default:** No config

- `eventBridgeConfig`: [IResolvable](/cdk/api/v2/docs/aws-cdk-lib.IResolvable.html) | [CfnDataSource.EventBridgeConfigProperty](/cdk/api/v2/docs/aws-cdk-lib.aws_appsync.CfnDataSource.EventBridgeConfigProperty.html) — configuration for EventBridge Datasource.

  **Default:** No config

- `httpConfig`: [IResolvable](/cdk/api/v2/docs/aws-cdk-lib.IResolvable.html) | [CfnDataSource.HttpConfigProperty](/cdk/api/v2/docs/aws-cdk-lib.aws_appsync.CfnDataSource.HttpConfigProperty.html) — configuration for HTTP Datasource.

  **Default:** No config

- `lambdaConfig`: [IResolvable](/cdk/api/v2/docs/aws-cdk-lib.IResolvable.html) | [CfnDataSource.LambdaConfigProperty](/cdk/api/v2/docs/aws-cdk-lib.aws_appsync.CfnDataSource.LambdaConfigProperty.html) — configuration for Lambda Datasource.

  **Default:** No config

- `openSearchServiceConfig`: [IResolvable](/cdk/api/v2/docs/aws-cdk-lib.IResolvable.html) | [CfnDataSource.OpenSearchServiceConfigProperty](/cdk/api/v2/docs/aws-cdk-lib.aws_appsync.CfnDataSource.OpenSearchServiceConfigProperty.html) — configuration for OpenSearch data source.

  **Default:** No config

- `relationalDatabaseConfig`: [IResolvable](/cdk/api/v2/docs/aws-cdk-lib.IResolvable.html) | [CfnDataSource.RelationalDatabaseConfigProperty](/cdk/api/v2/docs/aws-cdk-lib.aws_appsync.CfnDataSource.RelationalDatabaseConfigProperty.html) — configuration for RDS Datasource.

  **Default:** No config

- `type`: string (required) — the type of the AppSync datasource.

## Properties

- `ds`: [CfnDataSource](/cdk/api/v2/docs/aws-cdk-lib.aws_appsync.CfnDataSource.html) — the underlying CFN data source resource.

- `name`: string — the name of the data source.

- `node`: [Node](/cdk/api/v2/docs/constructs.Node.html) — The tree node.

## Methods

- `createFunction(id: string, props: BaseAppsyncFunctionProps): AppsyncFunction` — creates a new appsync function for this datasource and API using the given properties.

- `createResolver(id: string, props: BaseResolverProps): Resolver` — creates a new resolver for this datasource and API using the given properties.

- `isConstruct(x: any): boolean` (static) — Checks if `x` is a construct.

  Use this method instead of `instanceof` to properly detect `Construct`
  instances, even when the construct library is symlinked.

  Explanation: in JavaScript, multiple copies of the `constructs` library on
  disk are seen as independent, completely different libraries. As a
  consequence, the class `Construct` in each copy of the `constructs` library
  is seen as a different class, and an instance of one class will not test as
  `instanceof` the other class. `npm install` will not create installations
  like this, but users may manually symlink construct libraries together or
  use a monorepo tool: in those cases, multiple copies of the `constructs`
  library can be accidentally installed, and `instanceof` will behave
  unpredictably. It is safest to avoid using `instanceof`, and using
  this type-testing method instead.

  **Parameters**

  - `x` — Any object.

  **Returns:** true if `x` is an object created from a class which extends `Construct`.

- `toString(): string` — Returns a string representation of this construct.

- `with(...mixins: IMixin[]): IConstruct` — Applies one or more mixins to this construct.

  Mixins are applied in order. The list of constructs is captured at the
  start of the call, so constructs added by a mixin will not be visited.
  Use multiple `with()` calls if subsequent mixins should apply to added
  constructs.

  **Parameters**

  - `mixins` — The mixins to apply.

  **Returns:** This construct for chaining
