-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(appsync): import existing graphql api (#9254)
**[ISSUE]** Appsync missing `fromXxx` functionality, making multiple stack appsync interaction impossible. **[Approach]** Created a base class for `GraphQLApi` and a `IGraphQLApi` interface for imports. Added `fromXxxAttributes` functions to code base that can add dataSources. **[Notes]** Only accessible props from `IGraphQLApi` are `apiId` and `arn`. Only accessible functions from `IGraphQLApi` are the `addXxxDataSource` functions. Added `props-physical-name:@aws-cdk/aws-appsync.GraphQLApiProps` as linter exception because the breaking change isn't worth the return of making the physical name (name exists already). Added `from-method:@aws-cdk/aws-appsync.GraphQLApi` as linter exception because a `fromGraphQLApiAttributes` function will turn into `from_graph_q_l_api_attributes` in python. Fixes #6959 BREAKING CHANGE: **appsync.addXxxDataSource** `name` and `description` props are now optional and in an `DataSourceOptions` interface. - **appsync**: the props `name` and `description` in `addXxxDataSource` have been moved into new props `options` of type `DataSourceOptions` - **appsync**: `DataSourceOptions.name` defaults to id - **appsync**: `DataSourceOptions.description` defaults to undefined ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
- Loading branch information
1 parent
1893a5e
commit 5732b8e
Showing
18 changed files
with
1,099 additions
and
182 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,177 @@ | ||
import { ITable } from '@aws-cdk/aws-dynamodb'; | ||
import { IFunction } from '@aws-cdk/aws-lambda'; | ||
import { CfnResource, IResource, Resource } from '@aws-cdk/core'; | ||
import { DynamoDbDataSource, HttpDataSource, LambdaDataSource, NoneDataSource } from './data-source'; | ||
|
||
/** | ||
* Optional configuration for data sources | ||
*/ | ||
export interface DataSourceOptions { | ||
/** | ||
* The name of the data source, overrides the id given by cdk | ||
* | ||
* @default - generated by cdk given the id | ||
*/ | ||
readonly name?: string; | ||
|
||
/** | ||
* The description of the data source | ||
* | ||
* @default - No description | ||
*/ | ||
readonly description?: string; | ||
} | ||
|
||
/** | ||
* Interface for GraphQL | ||
*/ | ||
export interface IGraphqlApi extends IResource { | ||
|
||
/** | ||
* an unique AWS AppSync GraphQL API identifier | ||
* i.e. 'lxz775lwdrgcndgz3nurvac7oa' | ||
* | ||
* @attribute | ||
*/ | ||
readonly apiId: string; | ||
|
||
/** | ||
* the ARN of the API | ||
* | ||
* @attribute | ||
*/ | ||
readonly arn: string; | ||
|
||
/** | ||
* add a new dummy data source to this API. 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 | ||
*/ | ||
addNoneDataSource(id: string, options?: DataSourceOptions): NoneDataSource; | ||
|
||
/** | ||
* add a new DynamoDB data source to this API | ||
* | ||
* @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 | ||
*/ | ||
addDynamoDbDataSource(id: string, table: ITable, options?: DataSourceOptions): DynamoDbDataSource; | ||
|
||
/** | ||
* add a new http data source to this API | ||
* | ||
* @param id The data source's id | ||
* @param endpoint The http endpoint | ||
* @param options The optional configuration for this data source | ||
*/ | ||
addHttpDataSource(id: string, endpoint: string, options?: DataSourceOptions): HttpDataSource; | ||
|
||
/** | ||
* add a new Lambda data source to this API | ||
* | ||
* @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 | ||
*/ | ||
addLambdaDataSource(id: string, lambdaFunction: IFunction, options?: DataSourceOptions): LambdaDataSource; | ||
|
||
/** | ||
* Add schema dependency if not imported | ||
* | ||
* @param construct the dependee | ||
*/ | ||
addSchemaDependency(construct: CfnResource): boolean; | ||
} | ||
|
||
/** | ||
* Base Class for GraphQL API | ||
*/ | ||
export abstract class GraphqlApiBase extends Resource implements IGraphqlApi { | ||
|
||
/** | ||
* an unique AWS AppSync GraphQL API identifier | ||
* i.e. 'lxz775lwdrgcndgz3nurvac7oa' | ||
*/ | ||
public abstract readonly apiId: string; | ||
|
||
/** | ||
* the ARN of the API | ||
*/ | ||
public abstract readonly arn: string; | ||
|
||
/** | ||
* add a new dummy data source to this API. 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 | ||
*/ | ||
public addNoneDataSource(id: string, options?: DataSourceOptions): NoneDataSource { | ||
return new NoneDataSource(this, id, { | ||
api: this, | ||
name: options?.name, | ||
description: options?.description, | ||
}); | ||
} | ||
|
||
/** | ||
* add a new DynamoDB data source to this API | ||
* | ||
* @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 | ||
*/ | ||
public addDynamoDbDataSource(id: string, table: ITable, options?: DataSourceOptions): DynamoDbDataSource { | ||
return new DynamoDbDataSource(this, id, { | ||
api: this, | ||
table, | ||
name: options?.name, | ||
description: options?.description, | ||
}); | ||
} | ||
|
||
/** | ||
* add a new http data source to this API | ||
* | ||
* @param id The data source's id | ||
* @param endpoint The http endpoint | ||
* @param options The optional configuration for this data source | ||
*/ | ||
public addHttpDataSource(id: string, endpoint: string, options?: DataSourceOptions): HttpDataSource { | ||
return new HttpDataSource(this, id, { | ||
api: this, | ||
endpoint, | ||
name: options?.name, | ||
description: options?.description, | ||
}); | ||
} | ||
|
||
/** | ||
* add a new Lambda data source to this API | ||
* | ||
* @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 | ||
*/ | ||
public addLambdaDataSource(id: string, lambdaFunction: IFunction, options?: DataSourceOptions): LambdaDataSource { | ||
return new LambdaDataSource(this, id, { | ||
api: this, | ||
lambdaFunction, | ||
name: options?.name, | ||
description: options?.description, | ||
}); | ||
} | ||
|
||
/** | ||
* Add schema dependency if not imported | ||
* | ||
* @param construct the dependee | ||
*/ | ||
public addSchemaDependency(construct: CfnResource): boolean { | ||
construct; | ||
return false; | ||
} | ||
} |
Oops, something went wrong.