AppSyncApi
The AppSyncApi
construct is a higher level CDK construct that makes it easy to create an AppSync GraphQL API. It provides a simple way to define the data sources and the resolvers in your API. And allows you to configure the specific Lambda functions if necessary. See the examples for more details.
Using this construct requires two additional dependencies. Make sure you install graphql
and @graphql-tools/merge
for schema merging
Examples
Using the minimal config
import { AppSyncApi } from "sst/constructs";
new AppSyncApi(stack, "GraphqlApi", {
schema: "graphql/schema.graphql",
dataSources: {
notesDS: "src/notes.main",
},
resolvers: {
"Query listNotes": "notesDS",
"Query getNoteById": "notesDS",
"Mutation createNote": "notesDS",
"Mutation updateNote": "notesDS",
"Mutation deleteNote": "notesDS",
},
});
Note that, the resolver key can have extra spaces in between, they are just ignored.
Data source: Function
Auto-creating Lambda data sources
If the data sources are not configured, a Lambda data source is automatically created for each resolver.
new AppSyncApi(stack, "GraphqlApi", {
schema: "graphql/schema.graphql",
resolvers: {
"Query listNotes": "src/list.main",
"Query getNoteById": "src/get.main",
"Mutation createNote": "src/create.main",
"Mutation updateNote": "src/update.main",
"Mutation deleteNote": "src/delete.main",
},
});
Specifying function props for all the data sources
You can set some function props and have them apply to all the Lambda data sources.
new AppSyncApi(stack, "GraphqlApi", {
schema: "graphql/schema.graphql",
defaults: {
function: {
timeout: 20,
environment: { tableName: "NOTES_TABLE" },
},
},
dataSources: {
notesDS: "src/notes.main",
},
resolvers: {
"Query listNotes": "notesDS",
"Mutation createNote": "notesDS",
},
});
Note that, you can set the defaultFunctionProps
while configuring the function per data source. The function one will just override the defaultFunctionProps
.
new AppSyncApi(stack, "GraphqlApi", {
schema: "graphql/schema.graphql",
defaults: {
function: {
timeout: 20,
},
},
dataSources: {
notesDS: {
function: {
handler: "src/notes.main",
timeout: 10,
},
},
},
resolvers: {
"Query listNotes": "notesDS",
"Mutation createNote": "notesDS",
},
});
So in the above example, the notesDS
data source doesn't use the timeout
that is set in the defaultFunctionProps
. It'll instead use the one that is defined in the function definition (10 seconds
).
Similarly, the defaultFunctionProps
also applies when the Lambda data sources are auto-created.
new AppSyncApi(stack, "GraphqlApi", {
schema: "graphql/schema.graphql",
defaults: {
function: {
timeout: 20,
},
},
resolvers: {
"Query listNotes": {
function: {
handler: "src/list.main",
timeout: 10,
},
},
"Mutation createNote": "src/create.main",
},
});
Attaching permissions for the entire API
Allow the entire API to access S3.
const api = new AppSyncApi(stack, "GraphqlApi", {
schema: "graphql/schema.graphql",
resolvers: {
"Query listNotes": "src/list.main",
"Query getNoteById": "src/get.main",
"Mutation createNote": "src/create.main",
"Mutation updateNote": "src/update.main",
"Mutation deleteNote": "src/delete.main",
},
});
api.attachPermissions(["s3"]);
Attaching permissions for a specific route
Allow one of the data sources to access S3.
const api = new AppSyncApi(stack, "GraphqlApi", {
schema: "graphql/schema.graphql",
dataSources: {
notesDS: "src/notes.main",
billingDS: "src/billing.main",
},
});
api.attachPermissionsToDataSource("billingDS", ["s3"]);
Attaching permissions for an auto-created data source
Allow one of the resolvers to access S3.
const api = new AppSyncApi(stack, "GraphqlApi", {
schema: "graphql/schema.graphql",
resolvers: {
"Query listNotes": "src/list.main",
"Mutation createNote": "src/create.main",
},
});
api.attachPermissionsToDataSource("Query listNotes", ["s3"]);
Using multiple data sources
new AppSyncApi(stack, "GraphqlApi", {
schema: "graphql/schema.graphql",
dataSources: {
notesDS: "src/notes.main",
billingDS: "src/billing.main",
},
resolvers: {
"Query listNotes": "notesDS",
"Mutation createNote": "notesDS",
"Mutation charge": "billingDS",
},
});
Getting the function for a data source
const api = new AppSyncApi(stack, "GraphqlApi", {
schema: "graphql/schema.graphql",
dataSources: {
notesDS: "src/notes.main",
billingDS: "src/billing.main",
},
});
const listFunction = api.getFunction("notesDS");
const dataSource = api.getDataSource("notesDS");
Getting the function for a auto-created data source
const api = new AppSyncApi(stack, "GraphqlApi", {
schema: "graphql/schema.graphql",
resolvers: {
"Query listNotes": "src/list.main",
"Mutation createNote": "src/create.main",
},
});
const listFunction = api.getFunction("Query listNotes");
const dataSource = api.getDataSource("Query listNotes");
Data source: DynamoDB
import { MappingTemplate } from "aws-cdk-lib/aws-appsync";
const notesTable = new Table(stack, "Notes", {
fields: {
id: "string",
},
primaryIndex: { partitionKey: "id" },
});
new AppSyncApi(stack, "GraphqlApi", {
schema: "graphql/schema.graphql",
dataSources: {
tableDS: {
type: "dynamodb",
table: notesTable,
},
},
resolvers: {
"Query listNotes": {
dataSource: "tableDS",
cdk: {
resolver: {
requestMappingTemplate: MappingTemplate.dynamoDbScanTable(),
responseMappingTemplate: MappingTemplate.dynamoDbResultList(),
},
},
},
},
});
Data source: RDS
new AppSyncApi(stack, "GraphqlApi", {
schema: "graphql/schema.graphql",
dataSources: {
rdsDS: {
type: "rds",
rds: cluster,
},
},
resolvers: {
"Query listNotes": {
dataSource: "rdsDS",
requestMapping: {
inline: `
{
"version": "2018-05-29",
"statements": [
"SELECT * FROM notes"
]
}
`,
},
responseMapping: {
inline: `$util.rds.toJsonObject($ctx.result)`,
},
},
},
});
Data source: OpenSearch
import { Domain } from "aws-cdk-lib/aws-opensearchservice";
new AppSyncApi(stack, "GraphqlApi", {
schema: "graphql/schema.graphql",
dataSources: {
searchDS: {
type: "open_search",
cdk: {
dataSource: {
domain: Domain.fromDomainEndpoint(
stack,
"IDomain",
"https://search-test-domain-1234567890.us-east-1.es.amazonaws.com"
)
}
}
},
},
resolvers: {
"Query listNotes": {
dataSource: "searchDS",
requestMappingTemplate: appsync.MappingTemplate.fromString(JSON.stringify({
version: '2017-02-28',
operation: 'GET',
path: '/id/post/_search',
params: {
headers: {},
queryString: {},
body: { from: 0, size: 50 },
},
})),
responseMappingTemplate: appsync.MappingTemplate.fromString(`[
#foreach($entry in $context.result.hits.hits)
#if( $velocityCount > 1 ) , #end
$utils.toJson($entry.get("_source"))
#end
]`),
},
},
});
Data source: HTTP
Starting a Step Function execution on the Mutation callStepFunction
.
new AppSyncApi(stack, "GraphqlApi", {
schema: "graphql/schema.graphql",
dataSources: {
httpDS: {
type: "http",
endpoint: "https://states.amazonaws.com",
cdk: {
dataSource: {
authorizationConfig: {
signingRegion: "us-east-1",
signingServiceName: "states",
},
},
},
},
},
resolvers: {
"Mutation callStepFunction": {
dataSource: "httpDS",
requestMapping: { file: "request.vtl" },
responseMapping: { file: "response.vtl" },
},
},
});
Configuring resolvers
You can also add data sources and resolvers after the API has been created.
Adding data sources and resolvers
const api = new AppSyncApi(stack, "GraphqlApi", {
schema: "graphql/schema.graphql",
dataSources: {
notesDS: "src/notes.main",
},
resolvers: {
"Query listNotes": "notesDS",
"Mutation createNote": "notesDS",
},
});
api.addDataSources(stack, {
billingDS: "src/billing.main",
});
api.addResolvers(stack, {
"Mutation charge": "billingDS",
});
Auto-creating Lambda data sources
const api = new AppSyncApi(stack, "GraphqlApi", {
schema: "graphql/schema.graphql",
resolvers: {
"Query listNotes": "src/list.main",
"Query getNoteById": "src/get.main",
"Mutation createNote": "src/create.main",
},
});
api.addResolvers(stack, {
"Mutation updateNote": "src/update.main",
"Mutation deleteNote": "src/delete.main",
});
Lazily adding resolvers
const api = new AppSyncApi(stack, "GraphqlApi", {
schema: "graphql/schema.graphql",
});
api.addResolvers(stack, {
"Query listNotes": "src/list.main",
"Mutation createNote": "src/create.main",
});
Getting the function for a resolver
const api = new AppSyncApi(stack, "GraphqlApi", {
schema: "graphql/schema.graphql",
dataSources: {
notesDS: "src/notes.main",
billingDS: "src/billing.main",
},
resolvers: {
"Query listNotes": "notesDS",
"Mutation createNote": "notesDS",
"Mutation charge": "billingDS",
},
});
const resolver = api.getResolver("Mutation charge");
Custom domains
You can configure the API with a custom domain hosted either on Route 53 or externally.
Using the basic config
new AppSyncApi(stack, "GraphqlApi", {
schema: "graphql/schema.graphql",
customDomain: "api.domain.com",
});
Using the full config
new AppSyncApi(stack, "GraphqlApi", {
schema: "graphql/schema.graphql",
customDomain: {
domainName: "api.domain.com",
hostedZone: "domain.com",
recordType: "A_AAAA",
},
});
Importing an existing certificate
import { Certificate } from "aws-cdk-lib/aws-certificatemanager";
new AppSyncApi(stack, "GraphqlApi", {
schema: "graphql/schema.graphql",
customDomain: {
domainName: "api.domain.com",
cdk: {
certificate: Certificate.fromCertificateArn(stack, "MyCert", certArn),
},
},
});
Specifying a hosted zone
If you have multiple hosted zones for a given domain, you can choose the one you want to use to configure the domain.
import { HostedZone } from "aws-cdk-lib/aws-route53";
new AppSyncApi(stack, "GraphqlApi", {
schema: "graphql/schema.graphql",
customDomain: {
domainName: "api.domain.com",
cdk: {
hostedZone: HostedZone.fromHostedZoneAttributes(stack, "MyZone", {
hostedZoneId,
zoneName,
}),
},
},
});
Loading domain name from SSM parameter
If you have the domain name stored in AWS SSM Parameter Store, you can reference the value as the domain name:
import { StringParameter } from "aws-cdk-lib/aws-ssm";
const rootDomain = StringParameter.valueForStringParameter(
stack,
`/myApp/domain`
);
new AppSyncApi(stack, "GraphqlApi", {
schema: "graphql/schema.graphql",
customDomain: {
domainName: `api.${rootDomain}`,
cdk: {
hostedZone: HostedZone.fromHostedZoneAttributes(stack, "MyZone", {
hostedZoneId,
zoneName,
}),
},
},
});
Note that, normally SST will look for a hosted zone by stripping out the first part of the domainName
. But this is not possible when the domainName
is a reference. So you'll need to specify the cdk.hostedZone
explicitly.
Using externally hosted domain
import { Certificate } from "aws-cdk-lib/aws-certificatemanager";
new AppSyncApi(stack, "GraphqlApi", {
schema: "graphql/schema.graphql",
customDomain: {
isExternalDomain: true,
domainName: "api.domain.com",
cdk: {
certificate: Certificate.fromCertificateArn(stack, "MyCert", certArn),
},
},
});
Note that you can also migrate externally hosted domains to Route 53 by following this guide.
Authorization
Using API Key
import * as cdk from "aws-cdk-lib";
import * as appsync from "aws-cdk-lib/aws-appsync";
new AppSyncApi(stack, "GraphqlApi", {
schema: "graphql/schema.graphql",
cdk: {
graphqlApi: {
authorizationConfig: {
defaultAuthorization: {
authorizationType: appsync.AuthorizationType.API_KEY,
apiKeyConfig: {
expires: cdk.Expiration.after(cdk.Duration.days(365)),
},
},
},
},
},
});
Using Cognito User Pool
import * as appsync from "aws-cdk-lib/aws-appsync";
import { Auth, AppSyncApi } from "sst/constructs";
// Create a User Pool using the Auth construct
const auth = new Cognito(stack, "Auth");
new AppSyncApi(stack, "GraphqlApi", {
schema: "graphql/schema.graphql",
cdk: {
graphqlApi: {
authorizationConfig: {
defaultAuthorization: {
authorizationType: appsync.AuthorizationType.USER_POOL,
userPoolConfig: {
userPool: auth.cdk.userPool,
},
},
},
},
},
});
Using AWS IAM
import * as appsync from "aws-cdk-lib/aws-appsync";
new AppSyncApi(stack, "GraphqlApi", {
schema: "graphql/schema.graphql",
cdk: {
graphqlApi: {
authorizationConfig: {
defaultAuthorization: {
authorizationType: appsync.AuthorizationType.IAM,
},
},
},
},
});
Using OpenID Connect
import * as appsync from "aws-cdk-lib/aws-appsync";
new AppSyncApi(stack, "GraphqlApi", {
schema: "graphql/schema.graphql",
cdk: {
graphqlApi: {
authorizationConfig: {
defaultAuthorization: {
authorizationType: appsync.AuthorizationType.OIDC,
openIdConnectConfig: {
oidcProvider: "https://myorg.us.auth0.com",
},
},
},
},
},
});
Using Lambda
import * as appsync from "aws-cdk-lib/aws-appsync";
import { Function, AppSyncApi } from "sst/constructs";
const authorizer = new Function(stack, "AuthorizerFn", {
handler: "src/authorizer.main",
});
new AppSyncApi(stack, "GraphqlApi", {
schema: "graphql/schema.graphql",
cdk: {
graphqlApi: {
authorizationConfig: {
defaultAuthorization: {
authorizationType: appsync.AuthorizationType.LAMBDA,
lambdaAuthorizerConfig: {
handler: authorizer,
},
},
},
},
},
});
Using multiple authorization methods
import * as cdk from "aws-cdk-lib";
import * as appsync from "aws-cdk-lib/aws-appsync";
new AppSyncApi(stack, "GraphqlApi", {
schema: "graphql/schema.graphql",
cdk: {
graphqlApi: {
authorizationConfig: {
defaultAuthorization: {
authorizationType: appsync.AuthorizationType.API_KEY,
apiKeyConfig: {
expires: cdk.Expiration.after(cdk.Duration.days(365)),
},
},
additionalAuthorizationModes: [
{
authorizationType: appsync.AuthorizationType.IAM,
},
],
},
},
},
});
Advanced examples
Configuring the GraphQL Api
Configure the internally created CDK GraphqlApi
instance.
import * as appsync from "aws-cdk-lib/aws-appsync";
new AppSyncApi(stack, "GraphqlApi", {
schema: "graphql/schema.graphql",
cdk: {
graphqlApi: {
name: "My GraphQL API",
logConfig: {
excludeVerboseContent: false,
fieldLogLevel: appsync.FieldLogLevel.ALL,
},
xrayEnabled: false,
},
},
});
Importing an existing GraphQL Api
Override the internally created CDK GraphqlApi
instance.
import { GraphqlApi } from "aws-cdk-lib/aws-appsync";
new AppSyncApi(stack, "GraphqlApi", {
cdk: {
graphqlApi: GraphqlApi.fromGraphqlApiAttributes(stack, "IGraphqlApi", {
graphqlApiId,
}),
},
resolvers: {
"Query listNotes": "src/list.main",
"Mutation createNote": "src/create.main",
},
});
Sharing an API across stacks
You can create the AppSyncApi construct in one stack, and add resolvers in other stacks. To do this, return the API from your stack function.
import { AppSyncApi, StackContext } from "sst/constructs";
export function MainStack({ stack }: StackContext) {
const api = new AppSyncApi(stack, "GraphqlApi", {
schema: "graphql/schema.graphql",
resolvers: {
"Query listNotes": "src/list.main",
"Mutation createNote": "src/create.main",
},
});
return { api };
}
Then in another stack, utilize use
to import the first stack's API. Finally, call addResolvers
. Note that the AppSync resolver and data source resources for the added resolvers will be created in AnotherStack
.
import { StackContext, use } from "sst/constructs";
import { MainStack } from "./MainStack";
export function AnotherStack({ stack }: StackContext) {
const { api } = use(MainStack);
api.addResolvers(stack, {
"Query getNoteById": "src/get.main",
});
}
Batching GraphQL Resolvers (N+1)
Using naive GraphQL resolvers may result in what the GraphQL community calls the "N+1 Problem", which occurs when the system makes too many upstream requests for a given query.
For example, imagine that an incoming request is asking for 50 Company
objects, each with its associated list of Office
objects. Naive GraphQL resolvers will make a request to fetch the 50 Company
records first, then repeatedly request the Office
objects for the each of the 50 Company
records. This results in 51 requests in total.
Ideally, fetch operations should be batched, so that one request fetches the initial list of Company
records, and another request fetches all the related Office
records. This batching approach results in only two requests, and is much more efficient.
Defining a Batch Resolver
Create a function that uses a mapping template to create a "BatchInvoke" typed resolver, and use that function when defining the subfield resolver.
Here, we set up the resolvers for fetching companies and offices on their own, then we configure the batch resolver for fetching Company.offices
, but in batch mode.
const createBatchResolver = (fn: FunctionDefinition): AppSyncApiResolverProps => {
return {
function: fn,
requestMapping: {
inline: `{
"version" : "2017-02-28",
"operation" : "BatchInvoke",
"payload": {
"arguments": $utils.toJson($context.arguments),
"identity": $utils.toJson($context.identity),
"source": $utils.toJson($context.source),
"info": $utils.toJson($context.info),
"request": $utils.toJson($context.request)
}
}`
},
}
};
new AppSyncApi(stack, "GraphqlApi", {
schema: "graphql/schema.graphql",
dataSources: {
companiesDS: "src/companies.main",
officesDS: "src/offices.main",
},
resolvers: {
"Query companies": "companiesDS",
"Query offices": "officesDS",
"Company offices": createBatchResolver("src/offices.batchMain"),
}
});
The handler for the batch resolver (src/offices.batchMain
) looks very similar to a typical handler, except it accepts an array of AppSyncEvent
rather than a single instance.
Constructor
new AppSyncApi(scope, id, props)
Parameters
- scope Construct
- id string
- props AppSyncApiProps
AppSyncApiProps
customDomain?
Type : string | AppSyncApiDomainProps
Specify a custom domain to use in addition to the automatically generated one. SST currently supports domains that are configured using Route 53
new AppSyncApi(stack, "GraphqlApi", {
customDomain: "api.example.com"
})
new AppSyncApi(stack, "GraphqlApi", {
customDomain: {
domainName: "api.example.com",
hostedZone: "domain.com",
}
})
dataSources?
Type : Record<string, string | Function | AppSyncApiLambdaDataSourceProps | AppSyncApiDynamoDbDataSourceProps | AppSyncApiRdsDataSourceProps | AppSyncApiOpenSearchDataSourceProps | AppSyncApiHttpDataSourceProps | AppSyncApiNoneDataSourceProps>
Define datasources. Can be a function, dynamodb table, rds cluster or http endpoint
new AppSyncApi(stack, "GraphqlApi", {
dataSources: {
notes: "src/notes.main",
},
resolvers: {
"Query listNotes": "notes",
},
});
defaults?
Type :
defaults.function?
Type : FunctionProps
The default function props to be applied to all the Lambda functions in the AppSyncApi. The
environment
,
permissions
and
layers
properties will be merged with per route definitions if they are defined.
new AppSync(stack, "AppSync", {
defaults: {
function: {
timeout: 20,
environment: { tableName: table.tableName },
permissions: [table],
}
},
});
resolvers?
Type : Record<string, string | Function | AppSyncApiResolverProps>
The resolvers for this API. Takes an object, with the key being the type name and field name as a string and the value is either a string with the name of existing data source.
new AppSyncApi(stack, "GraphqlApi", {
resolvers: {
"Query listNotes": "src/list.main",
"Query getNoteById": "src/get.main",
"Mutation createNote": "src/create.main",
"Mutation updateNote": "src/update.main",
"Mutation deleteNote": "src/delete.main",
},
});
schema?
Type : string | Array<string>
The GraphQL schema definition.
new AppSyncApi(stack, "GraphqlApi", {
schema: "graphql/schema.graphql",
});
cdk?
Type :
cdk.graphqlApi?
Type : IGraphqlApi | AppSyncApiCdkGraphqlProps
Allows you to override default settings this construct uses internally to create the AppSync API.
cdk.id?
Type : string
Allows you to override default id for this construct.
Properties
An instance of AppSyncApi
has the following properties.
apiArn
Type : string
The ARN of the internally created AppSync GraphQL API.
apiId
Type : string
The Id of the internally created AppSync GraphQL API.
apiName
Type : string
The name of the internally created AppSync GraphQL API.
customDomainUrl
Type : undefined | string
If custom domain is enabled, this is the custom domain URL of the Api.
id
Type : string
url
Type : string
The AWS generated URL of the Api.
cdk
Type :
cdk.certificate?
Type : ICertificate
If custom domain is enabled, this is the internally created CDK Certificate instance.
cdk.graphqlApi
Type : GraphqlApi
The internally created appsync api
Methods
An instance of AppSyncApi
has the following methods.
addDataSources
addDataSources(scope, dataSources)
Parameters
- scope Construct
- dataSources
Add data sources after the construct has been created
api.addDataSources(stack, {
billingDS: "src/billing.main",
});
addResolvers
addResolvers(scope, resolvers)
Parameters
- scope Construct
- resolvers
Add resolvers the construct has been created
api.addResolvers(stack, {
"Mutation charge": "billingDS",
});
attachPermissions
attachPermissions(permissions)
Parameters
- permissions Permissions
Attaches the given list of permissions to all function data sources
api.attachPermissions(["s3"]);
attachPermissionsToDataSource
attachPermissionsToDataSource(key, permissions)
Parameters
- key string
- permissions Permissions
Attaches the given list of permissions to a specific function datasource. This allows that function to access other AWS resources.
api.attachPermissionsToDataSource("Mutation charge", ["s3"]);
bind
bind(constructs)
Parameters
- constructs Array<BindingResource>
Binds the given list of resources to all function data sources.
api.bind([STRIPE_KEY, bucket]);
bindToDataSource
bindToDataSource(key, constructs)
Parameters
- key string
- constructs Array<BindingResource>
Binds the given list of resources to a specific function data source.
api.bindToDataSource("Mutation charge", [STRIPE_KEY, bucket]);
getDataSource
getDataSource(key)
Parameters
- key string
Get a datasource by name
api.getDataSource("billingDS");
getFunction
getFunction(key)
Parameters
- key string
Get the instance of the internally created Function, for a given resolver.
const func = api.getFunction("Mutation charge");
getResolver
getResolver(key)
Parameters
- key string
Get a resolver
api.getResolver("Mutation charge");
MappingTemplateFile
file
Type : string
Path to the file containing the VTL mapping template
AppSyncApiDomainProps
domainName?
Type : string
The domain to be assigned to the API endpoint (ie. api.domain.com)
hostedZone?
Type : string
The hosted zone in Route 53 that contains the domain. By default, SST will look for a hosted zone by stripping out the first part of the domainName that's passed in. So, if your domainName is api.domain.com. SST will default the hostedZone to domain.com.
isExternalDomain?
Type : boolean
Set this option if the domain is not hosted on Amazon Route 53.
recordType?
Type : "CNAME" | "A_AAAA"
Default : CNAME
DNS record type for the Route 53 record associated with the custom domain. Default is CNAME.
cdk?
Type :
cdk.certificate?
Type : ICertificate
Override the internally created certificate
cdk.hostedZone?
Type : IHostedZone
Override the internally created hosted zone
MappingTemplateInline
inline
Type : string
Inline definition of the VTL mapping template
AppSyncApiResolverProps
Used to define full resolver config
dataSource?
Type : string
The data source for this resolver. The data source must be already created.
function?
Type : string | Function | FunctionProps
The function definition used to create the data source for this resolver.
requestMapping?
Type : MappingTemplateFile | MappingTemplateInline
VTL request mapping template
requestMapping: {
inline: '{"version" : "2017-02-28", "operation" : "Scan"}',
},
requestMapping: {
file: "path/to/template.vtl",
},
responseMapping?
Type : MappingTemplateFile | MappingTemplateInline
VTL response mapping template
responseMapping: {
inline: "$util.toJson($ctx.result.items)",
},
responseMapping: {
file: "path/to/template.vtl",
},
cdk?
Type :
cdk.resolver
Type : Omit<ResolverProps, "api" | "fieldName" | "typeName" | "dataSource">
This allows you to override the default settings this construct uses internally to create the resolver.
AppSyncApiCdkGraphqlProps
name?
Type : string
AppSyncApiRdsDataSourceProps
Used to define a RDS data source
new AppSyncApi(stack, "AppSync", {
dataSources: {
rds: {
type: "rds",
rds: myRDSCluster
},
},
});
databaseName?
Type : string
The name of the database to connect to
description?
Type : string
Description of the data source
name?
Type : string
Name of the data source
rds?
Type : RDS
Target RDS construct
type
Type : "rds"
String literal to signify that this data source is an RDS database
cdk?
Type :
cdk.dataSource?
Type :
cdk.dataSource.databaseName?
Type : string
cdk.dataSource.secretStore
Type : ISecret
cdk.dataSource.serverlessCluster
Type : IServerlessCluster
AppSyncApiHttpDataSourceProps
Used to define an http data source
new AppSyncApi(stack, "AppSync", {
dataSources: {
http: {
type: "http",
endpoint: "https://example.com"
},
},
});
description?
Type : string
Description of the data source
endpoint
Type : string
URL to forward requests to
name?
Type : string
Name of the data source
type
Type : "http"
String literal to signify that this data source is an HTTP endpoint
cdk?
Type :
cdk.dataSource?
Type :
cdk.dataSource.authorizationConfig?
Type : AwsIamConfig
AppSyncApiNoneDataSourceProps
Used to define a none data source
new AppSyncApi(stack, "AppSync", {
dataSources: {
none: {
type: "none",
},
},
});
description?
Type : string
Description of the data source
name?
Type : string
Name of the data source
type
Type : "none"
String literal to signify that this data source is an HTTP endpoint
AppSyncApiLambdaDataSourceProps
Used to define a lambda data source
new AppSyncApi(stack, "AppSync", {
dataSources: {
lambda: {
type: "function",
function: "src/function.handler"
},
},
});
description?
Type : string
Description of the data source
function
Type : string | Function | FunctionProps
Function definition
name?
Type : string
Name of the data source
type?
Type : "function"
String literal to signify that this data source is a function
AppSyncApiDynamoDbDataSourceProps
Used to define a DynamoDB data source
new AppSyncApi(stack, "AppSync", {
dataSources: {
table: {
type: "table",
table: MyTable
},
},
});
description?
Type : string
Description of the data source
name?
Type : string
Name of the data source
table?
Type : Table
Target table
type
Type : "dynamodb"
String literal to signify that this data source is a dynamodb table
cdk?
Type :
cdk.dataSource?
Type :
cdk.dataSource.table
Type : Table
AppSyncApiOpenSearchDataSourceProps
Used to define a OpenSearch data source
new AppSyncApi(stack, "AppSync", {
dataSources: {
search: {
type: "open_search",
cdk: {
dataSource: {
domain: myOpenSearchDomain,
}
}
}
}
});
description?
Type : string
Description of the data source
name?
Type : string
Name of the data source
type
Type : "open_search"
String literal to signify that this data source is an OpenSearch domain
cdk
Type :
cdk.dataSource
Type :
cdk.dataSource.domain
Type : IDomain