aws-cdk-lib.aws_appsync.GraphqlApi

class GraphqlApi (construct)

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

Implements IConstruct, IDependable, IResource, IGraphqlApi

An AppSync GraphQL API.

Example

const api = new appsync.GraphqlApi(stack, 'EventBridgeApi', {
  name: 'EventBridgeApi',
  schema: appsync.SchemaFile.fromAsset(path.join(__dirname, 'appsync.eventbridge.graphql')),
});

const bus = new events.EventBus(stack, 'DestinationEventBus', {});

const dataSource = api.addEventBridgeDataSource('NoneDS', bus);

dataSource.createResolver('EventResolver', {
  typeName: 'Mutation',
  fieldName: 'emitEvent',
  requestMappingTemplate: appsync.MappingTemplate.fromFile('request.vtl'),
  responseMappingTemplate: appsync.MappingTemplate.fromFile('response.vtl'),
});

Initializer

new GraphqlApi(scope: Construct, id: string, props: GraphqlApiProps)

Parameters

  • scope Construct
  • id string
  • props GraphqlApiProps

Construct Props

NameTypeDescription
namestringthe name of the GraphQL API.
schemaISchemaGraphQL schema definition. Specify how you want to define your schema.
authorizationConfig?AuthorizationConfigOptional authorization configuration.
domainName?DomainOptionsThe domain name configuration for the GraphQL API.
logConfig?LogConfigLogging configuration for this api.
visibility?VisibilityA value indicating whether the API is accessible from anywhere (GLOBAL) or can only be access from a VPC (PRIVATE).
xrayEnabled?booleanA flag indicating whether or not X-Ray tracing is enabled for the GraphQL API.

name

Type: string

the name of the GraphQL API.


schema

Type: ISchema

GraphQL schema definition. Specify how you want to define your schema.

Schema.fromFile(filePath: string) allows schema definition through schema.graphql file


authorizationConfig?

Type: AuthorizationConfig (optional, default: API Key authorization)

Optional authorization configuration.


domainName?

Type: DomainOptions (optional, default: no domain name)

The domain name configuration for the GraphQL API.

The Route 53 hosted zone and CName DNS record must be configured in addition to this setting to enable custom domain URL


logConfig?

Type: LogConfig (optional, default: None)

Logging configuration for this api.


visibility?

Type: Visibility (optional, default: GLOBAL)

A value indicating whether the API is accessible from anywhere (GLOBAL) or can only be access from a VPC (PRIVATE).


xrayEnabled?

Type: boolean (optional, default: false)

A flag indicating whether or not X-Ray tracing is enabled for the GraphQL API.

Properties

NameTypeDescription
apiIdstringan unique AWS AppSync GraphQL API identifier i.e. 'lxz775lwdrgcndgz3nurvac7oa'.
appSyncDomainNamestringThe AppSyncDomainName of the associated custom domain.
arnstringthe ARN of the API.
envResourceEnvironmentThe environment this resource belongs to.
graphqlUrlstringthe URL of the endpoint created by AppSync.
logGroupILogGroupthe CloudWatch Log Group for this API.
modesAuthorizationType[]The Authorization Types for this GraphQL Api.
namestringthe name of the API.
nodeNodeThe tree node.
schemaISchemathe schema attached to this api.
stackStackThe stack in which this resource is defined.
apiKey?stringthe configured API key, if present.

apiId

Type: string

an unique AWS AppSync GraphQL API identifier i.e. 'lxz775lwdrgcndgz3nurvac7oa'.


appSyncDomainName

Type: string

The AppSyncDomainName of the associated custom domain.


arn

Type: string

the ARN of the API.


env

Type: ResourceEnvironment

The environment this resource belongs to.

For resources that are created and managed by the CDK (generally, those created by creating new class instances like Role, Bucket, etc.), this is always the same as the environment of the stack they belong to; however, for imported resources (those obtained from static methods like fromRoleArn, fromBucketName, etc.), that might be different than the stack they were imported into.


graphqlUrl

Type: string

the URL of the endpoint created by AppSync.


logGroup

Type: ILogGroup

the CloudWatch Log Group for this API.


modes

Type: AuthorizationType[]

The Authorization Types for this GraphQL Api.


name

Type: string

the name of the API.


node

Type: Node

The tree node.


schema

Type: ISchema

the schema attached to this api.


stack

Type: Stack

The stack in which this resource is defined.


apiKey?

Type: string (optional, default: no api key)

the configured API key, if present.

Methods

NameDescription
addDynamoDbDataSource(id, table, options?)add a new DynamoDB data source to this API.
addElasticsearchDataSource(id, domain, options?)⚠️add a new elasticsearch data source to this API.
addEventBridgeDataSource(id, eventBus, options?)Add an EventBridge data source to this api.
addHttpDataSource(id, endpoint, options?)add a new http data source to this API.
addLambdaDataSource(id, lambdaFunction, options?)add a new Lambda data source to this API.
addNoneDataSource(id, options?)add a new dummy data source to this API.
addOpenSearchDataSource(id, domain, options?)add a new OpenSearch data source to this API.
addRdsDataSource(id, serverlessCluster, secretStore, databaseName?, options?)add a new Rds data source to this API.
addSchemaDependency(construct)Add schema dependency to a given construct.
applyRemovalPolicy(policy)Apply the given removal policy to this resource.
createResolver(id, props)creates a new resolver for this datasource and API using the given properties.
grant(grantee, resources, ...actions)Adds an IAM policy statement associated with this GraphQLApi to an IAM principal's policy.
grantMutation(grantee, ...fields)Adds an IAM policy statement for Mutation access to this GraphQLApi to an IAM principal's policy.
grantQuery(grantee, ...fields)Adds an IAM policy statement for Query access to this GraphQLApi to an IAM principal's policy.
grantSubscription(grantee, ...fields)Adds an IAM policy statement for Subscription access to this GraphQLApi to an IAM principal's policy.
toString()Returns a string representation of this construct.
static fromGraphqlApiAttributes(scope, id, attrs)Import a GraphQL API through this function.

addDynamoDbDataSource(id, table, options?)

public addDynamoDbDataSource(id: string, table: ITable, options?: DataSourceOptions): DynamoDbDataSource

Parameters

  • id string — The data source's id.
  • table ITable — The DynamoDB table backing this data source.
  • options DataSourceOptions — The optional configuration for this data source.

Returns

  • DynamoDbDataSource

add a new DynamoDB data source to this API.


addElasticsearchDataSource(id, domain, options?)⚠️

public addElasticsearchDataSource(id: string, domain: IDomain, options?: DataSourceOptions): ElasticsearchDataSource

⚠️ Deprecated: - use addOpenSearchDataSource

Parameters

  • id string — The data source's id.
  • domain IDomain — The elasticsearch domain for this data source.
  • options DataSourceOptions — The optional configuration for this data source.

Returns

  • ElasticsearchDataSource

add a new elasticsearch data source to this API.


addEventBridgeDataSource(id, eventBus, options?)

public addEventBridgeDataSource(id: string, eventBus: IEventBus, options?: DataSourceOptions): EventBridgeDataSource

Parameters

  • id string — The data source's id.
  • eventBus IEventBus — The EventBridge EventBus on which to put events.
  • options DataSourceOptions — The optional configuration for this data source.

Returns

  • EventBridgeDataSource

Add an EventBridge data source to this api.


addHttpDataSource(id, endpoint, options?)

public addHttpDataSource(id: string, endpoint: string, options?: HttpDataSourceOptions): HttpDataSource

Parameters

  • id string — The data source's id.
  • endpoint string — The http endpoint.
  • options HttpDataSourceOptions — The optional configuration for this data source.

Returns

  • HttpDataSource

add a new http data source to this API.


addLambdaDataSource(id, lambdaFunction, options?)

public addLambdaDataSource(id: string, lambdaFunction: IFunction, options?: DataSourceOptions): LambdaDataSource

Parameters

  • id string — The data source's id.
  • lambdaFunction IFunction — The Lambda function to call to interact with this data source.
  • options DataSourceOptions — The optional configuration for this data source.

Returns

  • LambdaDataSource

add a new Lambda data source to this API.


addNoneDataSource(id, options?)

public addNoneDataSource(id: string, options?: DataSourceOptions): NoneDataSource

Parameters

  • id string — The data source's id.
  • options DataSourceOptions — The optional configuration for this data source.

Returns

  • NoneDataSource

add a new dummy data source to this API.

Useful for pipeline resolvers and for backend changes that don't require a data source.


addOpenSearchDataSource(id, domain, options?)

public addOpenSearchDataSource(id: string, domain: IDomain, options?: DataSourceOptions): OpenSearchDataSource

Parameters

  • id string — The data source's id.
  • domain IDomain — The OpenSearch domain for this data source.
  • options DataSourceOptions — The optional configuration for this data source.

Returns

  • OpenSearchDataSource

add a new OpenSearch data source to this API.


addRdsDataSource(id, serverlessCluster, secretStore, databaseName?, options?)

public addRdsDataSource(id: string, serverlessCluster: IServerlessCluster, secretStore: ISecret, databaseName?: string, options?: DataSourceOptions): RdsDataSource

Parameters

  • id string — The data source's id.
  • serverlessCluster IServerlessCluster — The serverless cluster to interact with this data source.
  • secretStore ISecret — The secret store that contains the username and password for the serverless cluster.
  • databaseName string — The optional name of the database to use within the cluster.
  • options DataSourceOptions — The optional configuration for this data source.

Returns

  • RdsDataSource

add a new Rds data source to this API.


addSchemaDependency(construct)

public addSchemaDependency(construct: CfnResource): boolean

Parameters

  • construct CfnResource — the dependee.

Returns

  • boolean

Add schema dependency to a given construct.


applyRemovalPolicy(policy)

public applyRemovalPolicy(policy: RemovalPolicy): void

Parameters

  • policy RemovalPolicy

Apply the given removal policy to this resource.

The Removal Policy controls what happens to this resource when it stops being managed by CloudFormation, either because you've removed it from the CDK application or because you've made a change that requires the resource to be replaced.

The resource can be deleted (RemovalPolicy.DESTROY), or left in your AWS account for data recovery and cleanup later (RemovalPolicy.RETAIN).


createResolver(id, props)

public createResolver(id: string, props: ExtendedResolverProps): Resolver

Parameters

  • id string
  • props ExtendedResolverProps

Returns

  • Resolver

creates a new resolver for this datasource and API using the given properties.


grant(grantee, resources, ...actions)

public grant(grantee: IGrantable, resources: IamResource, ...actions: string[]): Grant

Parameters

  • grantee IGrantable — The principal.
  • resources IamResource — The set of resources to allow (i.e. ...:[region]:[accountId]:apis/GraphQLId/...).
  • actions string — The actions that should be granted to the principal (i.e. appsync:graphql ).

Returns

  • Grant

Adds an IAM policy statement associated with this GraphQLApi to an IAM principal's policy.


grantMutation(grantee, ...fields)

public grantMutation(grantee: IGrantable, ...fields: string[]): Grant

Parameters

  • grantee IGrantable — The principal.
  • fields string — The fields to grant access to that are Mutations (leave blank for all).

Returns

  • Grant

Adds an IAM policy statement for Mutation access to this GraphQLApi to an IAM principal's policy.


grantQuery(grantee, ...fields)

public grantQuery(grantee: IGrantable, ...fields: string[]): Grant

Parameters

  • grantee IGrantable — The principal.
  • fields string — The fields to grant access to that are Queries (leave blank for all).

Returns

  • Grant

Adds an IAM policy statement for Query access to this GraphQLApi to an IAM principal's policy.


grantSubscription(grantee, ...fields)

public grantSubscription(grantee: IGrantable, ...fields: string[]): Grant

Parameters

  • grantee IGrantable — The principal.
  • fields string — The fields to grant access to that are Subscriptions (leave blank for all).

Returns

  • Grant

Adds an IAM policy statement for Subscription access to this GraphQLApi to an IAM principal's policy.


toString()

public toString(): string

Returns

  • string

Returns a string representation of this construct.


static fromGraphqlApiAttributes(scope, id, attrs)

public static fromGraphqlApiAttributes(scope: Construct, id: string, attrs: GraphqlApiAttributes): IGraphqlApi

Parameters

  • scope Construct — scope.
  • id string — id.
  • attrs GraphqlApiAttributes — GraphQL API Attributes of an API.

Returns

  • IGraphqlApi

Import a GraphQL API through this function.