class GraphqlApi (construct)
Language | Type name |
---|---|
![]() | Amazon.CDK.AWS.AppSync.GraphqlApi |
![]() | software.amazon.awscdk.services.appsync.GraphqlApi |
![]() | aws_cdk.aws_appsync.GraphqlApi |
![]() | @aws-cdk/aws-appsync ยป GraphqlApi |
Implements
IConstruct
, IConstruct
, IDependable
, IResource
, IGraphql
An AppSync GraphQL API.
Example
const api = new appsync.GraphqlApi(this, 'Api', {
name: 'demo',
});
const demo = new appsync.ObjectType('Demo', {
definition: {
id: appsync.GraphqlType.string({ isRequired: true }),
version: appsync.GraphqlType.string({ isRequired: true }),
},
});
api.addType(demo);
Initializer
new GraphqlApi(scope: Construct, id: string, props: GraphqlApiProps)
Parameters
- scope
Construct
- id
string
- props
Graphql
Api Props
Construct Props
Name | Type | Description |
---|---|---|
name | string | the name of the GraphQL API. |
authorization | Authorization | Optional authorization configuration. |
domain | Domain | The domain name configuration for the GraphQL API. |
log | Log | Logging configuration for this api. |
schema? | Schema | GraphQL schema definition. Specify how you want to define your schema. |
xray | boolean | A flag indicating whether or not X-Ray tracing is enabled for the GraphQL API. |
name
Type:
string
the name of the GraphQL API.
authorizationConfig?
Type:
Authorization
(optional, default: API Key authorization)
Optional authorization configuration.
domainName?
Type:
Domain
(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:
Log
(optional, default: None)
Logging configuration for this api.
schema?
Type:
Schema
(optional, default: schema will be generated code-first (i.e. addType, addObjectType, etc.))
GraphQL schema definition. Specify how you want to define your schema.
Schema.fromFile(filePath: string) allows schema definition through schema.graphql file
xrayEnabled?
Type:
boolean
(optional, default: false)
A flag indicating whether or not X-Ray tracing is enabled for the GraphQL API.
Properties
Name | Type | Description |
---|---|---|
api | string | an unique AWS AppSync GraphQL API identifier i.e. 'lxz775lwdrgcndgz3nurvac7oa'. |
arn | string | the ARN of the API. |
env | Resource | The environment this resource belongs to. |
graphql | string | the URL of the endpoint created by AppSync. |
modes | Authorization [] | The Authorization Types for this GraphQL Api. |
name | string | the name of the API. |
node | Construct | The construct tree node associated with this construct. |
schema | Schema | the schema attached to this api. |
stack | Stack | The stack in which this resource is defined. |
api | string | the configured API key, if present. |
apiId
Type:
string
an unique AWS AppSync GraphQL API identifier i.e. 'lxz775lwdrgcndgz3nurvac7oa'.
arn
Type:
string
the ARN of the API.
env
Type:
Resource
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.
modes
Type:
Authorization
[]
The Authorization Types for this GraphQL Api.
name
Type:
string
the name of the API.
node
Type:
Construct
The construct tree node associated with this construct.
schema
Type:
Schema
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
Name | Description |
---|---|
add | add a new DynamoDB data source to this API. |
add | add a new elasticsearch data source to this API. |
add | add a new http data source to this API. |
add | add a new Lambda data source to this API. |
add | Add a mutation field to the schema's Mutation. CDK will create an Object Type called 'Mutation'. For example,. |
add | add a new dummy data source to this API. |
add | add a new OpenSearch data source to this API. |
add | Add a query field to the schema's Query. CDK will create an Object Type called 'Query'. For example,. |
add | add a new Rds data source to this API. |
add | Add schema dependency to a given construct. |
add | Add a subscription field to the schema's Subscription. CDK will create an Object Type called 'Subscription'. For example,. |
add | Escape hatch to append to Schema as desired. |
add | Add type to the schema. |
apply | Apply the given removal policy to this resource. |
create | 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. |
grant | Adds an IAM policy statement for Mutation access to this GraphQLApi to an IAM principal's policy. |
grant | Adds an IAM policy statement for Query access to this GraphQLApi to an IAM principal's policy. |
grant | Adds an IAM policy statement for Subscription access to this GraphQLApi to an IAM principal's policy. |
to | Returns a string representation of this construct. |
static from | 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
Data
โ The optional configuration for this data source.Source Options
Returns
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
Data
โ The optional configuration for this data source.Source Options
Returns
add a new elasticsearch 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
Http
โ The optional configuration for this data source.Data Source Options
Returns
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
Data
โ The optional configuration for this data source.Source Options
Returns
add a new Lambda data source to this API.
addMutation(fieldName, field)
public addMutation(fieldName: string, field: ResolvableField): ObjectType
Parameters
- fieldName
string
โ the name of the Mutation. - field
Resolvable
โ the resolvable field to for this Mutation.Field
Returns
Add a mutation field to the schema's Mutation. CDK will create an Object Type called 'Mutation'. For example,.
type Mutation { fieldName: Field.returnType }
addNoneDataSource(id, options?)
public addNoneDataSource(id: string, options?: DataSourceOptions): NoneDataSource
Parameters
- id
string
โ The data source's id. - options
Data
โ The optional configuration for this data source.Source Options
Returns
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
Data
โ The optional configuration for this data source.Source Options
Returns
add a new OpenSearch data source to this API.
addQuery(fieldName, field)
public addQuery(fieldName: string, field: ResolvableField): ObjectType
Parameters
- fieldName
string
โ the name of the query. - field
Resolvable
โ the resolvable field to for this query.Field
Returns
Add a query field to the schema's Query. CDK will create an Object Type called 'Query'. For example,.
type Query { fieldName: Field.returnType }
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
IServerless
โ The serverless cluster to interact with this data source.Cluster - 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
Data
โ The optional configuration for this data source.Source Options
Returns
add a new Rds data source to this API.
addSchemaDependency(construct)
public addSchemaDependency(construct: CfnResource): boolean
Parameters
- construct
Cfn
โ the dependee.Resource
Returns
boolean
Add schema dependency to a given construct.
addSubscription(fieldName, field)
public addSubscription(fieldName: string, field: ResolvableField): ObjectType
Parameters
- fieldName
string
โ the name of the Subscription. - field
Resolvable
โ the resolvable field to for this Subscription.Field
Returns
Add a subscription field to the schema's Subscription. CDK will create an Object Type called 'Subscription'. For example,.
type Subscription { fieldName: Field.returnType }
addToSchema(addition, delimiter?)
public addToSchema(addition: string, delimiter?: string): void
Parameters
- addition
string
โ the addition to add to schema. - delimiter
string
โ the delimiter between schema and addition.
Escape hatch to append to Schema as desired.
Will always result in a newline.
addType(type)
public addType(type: IIntermediateType): IIntermediateType
Parameters
- type
IIntermediate
โ the intermediate type to add to the schema.Type
Returns
Add type to the schema.
applyRemovalPolicy(policy)
public applyRemovalPolicy(policy: RemovalPolicy): void
Parameters
- policy
Removal
Policy
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(props)
public createResolver(props: ExtendedResolverProps): Resolver
Parameters
- props
Extended
Resolver Props
Returns
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
Iam
โ The set of resources to allow (i.e. ...:[region]:[accountId]:apis/GraphQLId/...).Resource - actions
string
โ The actions that should be granted to the principal (i.e. appsync:graphql ).
Returns
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
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
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
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
Graphql
โ GraphQL API Attributes of an API.Api Attributes
Returns
Import a GraphQL API through this function.