UNPKG

@aws-amplify/graphql-api-construct

Version:

AppSync GraphQL Api Construct using Amplify GraphQL Transformer.

181 lines (180 loc) 9.23 kB
import { Construct } from 'constructs'; import { Stack } from 'aws-cdk-lib'; import { AppsyncFunction, DataSourceOptions, DynamoDbDataSource, ElasticsearchDataSource, EventBridgeDataSource, ExtendedResolverProps, HttpDataSource, HttpDataSourceOptions, LambdaDataSource, NoneDataSource, OpenSearchDataSource, RdsDataSource, Resolver } from 'aws-cdk-lib/aws-appsync'; import { ITable } from 'aws-cdk-lib/aws-dynamodb'; import { IDomain } from 'aws-cdk-lib/aws-elasticsearch'; import { IDomain as IOpenSearchDomain } from 'aws-cdk-lib/aws-opensearchservice'; import { IEventBus } from 'aws-cdk-lib/aws-events'; import { IFunction } from 'aws-cdk-lib/aws-lambda'; import { IServerlessCluster } from 'aws-cdk-lib/aws-rds'; import { ISecret } from 'aws-cdk-lib/aws-secretsmanager'; import type { AmplifyGraphqlApiResources, AmplifyGraphqlApiProps, FunctionSlot, AddFunctionProps } from './types'; /** * L3 Construct which invokes the Amplify Transformer Pattern over an input Graphql Schema. * * This can be used to quickly define appsync apis which support full CRUD+List and Subscriptions, relationships, * auth, search over data, the ability to inject custom business logic and query/mutation operations, and connect to ML services. * * For more information, refer to the docs links below: * Data Modeling - https://docs.amplify.aws/cli/graphql/data-modeling/ * Authorization - https://docs.amplify.aws/cli/graphql/authorization-rules/ * Custom Business Logic - https://docs.amplify.aws/cli/graphql/custom-business-logic/ * Search - https://docs.amplify.aws/cli/graphql/search-and-result-aggregations/ * ML Services - https://docs.amplify.aws/cli/graphql/connect-to-machine-learning-services/ * * For a full reference of the supported custom graphql directives - https://docs.amplify.aws/cli/graphql/directives-reference/ * * The output of this construct is a mapping of L2 or L1 resources generated by the transformer, which generally follow the access pattern * * ```typescript * const api = new AmplifyGraphQlApi(this, 'api', { <params> }); * // Access L2 resources under `.resources` * api.resources.tables["Todo"].tableArn; * * // Access L1 resources under `.resources.cfnResources` * api.resources.cfnResources.cfnGraphqlApi.xrayEnabled = true; * Object.values(api.resources.cfnResources.cfnTables).forEach(table => { * table.pointInTimeRecoverySpecification = { pointInTimeRecoveryEnabled: false }; * }); * ``` * `resources.<ResourceType>.<ResourceName>` - you can then perform any CDK action on these resulting resoureces. */ export declare class AmplifyGraphqlApi extends Construct { /** * Generated L1 and L2 CDK resources. */ readonly resources: AmplifyGraphqlApiResources; /** * Reference to parent stack of data construct */ readonly stack: Stack; /** * Generated assets required for codegen steps. Persisted in order to render as part of the output strategy. */ private readonly codegenAssets; /** * Resolvers generated by the transform process, persisted on the side in order to facilitate pulling a manifest * for the purposes of inspecting and producing overrides. */ readonly generatedFunctionSlots: FunctionSlot[]; /** * Graphql URL For the generated API. May be a CDK Token. */ readonly graphqlUrl: string; /** * Realtime URL For the generated API. May be a CDK Token. */ readonly realtimeUrl: string; /** * Generated Api Key if generated. May be a CDK Token. */ readonly apiKey: string | undefined; /** * Generated Api Id. May be a CDK Token. */ readonly apiId: string; /** * DataStore conflict resolution setting */ private readonly dataStoreConfiguration; /** * Be very careful editing this value. This is the string that is used to identify graphql stacks in BI metrics */ private readonly stackType; /** * New AmplifyGraphqlApi construct, this will create an appsync api with authorization, a schema, and all necessary resolvers, functions, * and datasources. * @param scope the scope to create this construct within. * @param id the id to use for this api. * @param props the properties used to configure the generated api. */ constructor(scope: Construct, id: string, props: AmplifyGraphqlApiProps); /** * Stores graphql api output to be used for client config generation * @param outputStorageStrategy Strategy to store construct outputs. If no strategy is provided a default strategy will be used. */ private storeOutput; /** * The following are proxy methods to the L2 IGraphqlApi interface, to facilitate easier use of the L3 without needing * to access the underlying resources. */ /** * Add a new DynamoDB data source to this API. This is a proxy method to the L2 GraphqlApi Construct. * @param id The data source's id. * @param table The DynamoDB table backing this data source. * @param options The optional configuration for this data source. * @returns the generated data source. */ addDynamoDbDataSource(id: string, table: ITable, options?: DataSourceOptions): DynamoDbDataSource; /** * Add a new elasticsearch data source to this API. This is a proxy method to the L2 GraphqlApi Construct. * @deprecated use `addOpenSearchDataSource` * @param id The data source's id. * @param domain The elasticsearch domain for this data source. * @param options The optional configuration for this data source. * @returns the generated data source. */ addElasticsearchDataSource(id: string, domain: IDomain, options?: DataSourceOptions): ElasticsearchDataSource; /** * Add an EventBridge data source to this api. This is a proxy method to the L2 GraphqlApi Construct. * @param id The data source's id. * @param eventBus The EventBridge EventBus on which to put events. * @param options The optional configuration for this data source. */ addEventBridgeDataSource(id: string, eventBus: IEventBus, options?: DataSourceOptions): EventBridgeDataSource; /** * Add a new http data source to this API. This is a proxy method to the L2 GraphqlApi Construct. * @param id The data source's id. * @param endpoint The http endpoint. * @param options The optional configuration for this data source. * @returns the generated data source. */ addHttpDataSource(id: string, endpoint: string, options?: HttpDataSourceOptions): HttpDataSource; /** * Add a new Lambda data source to this API. This is a proxy method to the L2 GraphqlApi Construct. * @param id The data source's id. * @param lambdaFunction The Lambda function to call to interact with this data source. * @param options The optional configuration for this data source. * @returns the generated data source. */ addLambdaDataSource(id: string, lambdaFunction: IFunction, options?: DataSourceOptions): LambdaDataSource; /** * Add a new dummy data source to this API. This is a proxy method to the L2 GraphqlApi Construct. * Useful for pipeline resolvers and for backend changes that don't require a data source. * @param id The data source's id. * @param options The optional configuration for this data source. * @returns the generated data source. */ addNoneDataSource(id: string, options?: DataSourceOptions): NoneDataSource; /** * dd a new OpenSearch data source to this API. This is a proxy method to the L2 GraphqlApi Construct. * @param id The data source's id. * @param domain The OpenSearch domain for this data source. * @param options The optional configuration for this data source. * @returns the generated data source. */ addOpenSearchDataSource(id: string, domain: IOpenSearchDomain, options?: DataSourceOptions): OpenSearchDataSource; /** * Add a new Rds data source to this API. This is a proxy method to the L2 GraphqlApi Construct. * @param id The data source's id. * @param serverlessCluster The serverless cluster to interact with this data source. * @param secretStore The secret store that contains the username and password for the serverless cluster. * @param databaseName The optional name of the database to use within the cluster. * @param options The optional configuration for this data source. * @returns the generated data source. */ addRdsDataSource(id: string, serverlessCluster: IServerlessCluster, secretStore: ISecret, databaseName?: string, options?: DataSourceOptions): RdsDataSource; /** * Add a resolver to the api. This is a proxy method to the L2 GraphqlApi Construct. * @param id The resolver's id. * @param props the resolver properties. * @returns the generated resolver. */ addResolver(id: string, props: ExtendedResolverProps): Resolver; /** * Add an appsync function to the api. * @param id the function's id. * @returns the generated appsync function. */ addFunction(id: string, props: AddFunctionProps): AppsyncFunction; }