forked from aws/aws-cdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(appsync): support appsync functions for pipelineConfig (aws#10111)
Support AppSync Function by exposing Function Configuration. **BREAKING CHANGES**: `Resolver.pipelineConfig` no longer supports `string[]` - **AppSync**: `Resolver.pipelineConfig` no longer supports `string[]`, instead use `AppsyncFunction` - **AppSync**: Resolvers are scoped from `GraphqlApi` instead of its `Data Source`, this means that the **logical id** of resolvers will change! Fixes aws#9092 ---- *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
db9b95e
commit 68a4e98
Showing
21 changed files
with
632 additions
and
267 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
import { Resource, IResource, Lazy, Fn } from '@aws-cdk/core'; | ||
import { Construct } from 'constructs'; | ||
import { CfnFunctionConfiguration } from './appsync.generated'; | ||
import { BaseDataSource } from './data-source'; | ||
import { IGraphqlApi } from './graphqlapi-base'; | ||
import { MappingTemplate } from './mapping-template'; | ||
|
||
/** | ||
* the base properties for AppSync Functions | ||
*/ | ||
export interface BaseAppsyncFunctionProps { | ||
/** | ||
* the name of the AppSync Function | ||
*/ | ||
readonly name: string; | ||
/** | ||
* the description for this AppSync Function | ||
* | ||
* @default - no description | ||
*/ | ||
readonly description?: string; | ||
/** | ||
* the request mapping template for the AppSync Function | ||
* | ||
* @default - no request mapping template | ||
*/ | ||
readonly requestMappingTemplate?: MappingTemplate; | ||
/** | ||
* the response mapping template for the AppSync Function | ||
* | ||
* @default - no response mapping template | ||
*/ | ||
readonly responseMappingTemplate?: MappingTemplate; | ||
} | ||
|
||
/** | ||
* the CDK properties for AppSync Functions | ||
*/ | ||
export interface AppsyncFunctionProps extends BaseAppsyncFunctionProps { | ||
/** | ||
* the GraphQL Api linked to this AppSync Function | ||
*/ | ||
readonly api: IGraphqlApi; | ||
/** | ||
* the data source linked to this AppSync Function | ||
*/ | ||
readonly dataSource: BaseDataSource; | ||
} | ||
|
||
/** | ||
* The attributes for imported AppSync Functions | ||
*/ | ||
export interface AppsyncFunctionAttributes { | ||
/** | ||
* the ARN of the AppSync function | ||
*/ | ||
readonly functionArn: string; | ||
} | ||
|
||
/** | ||
* Interface for AppSync Functions | ||
*/ | ||
export interface IAppsyncFunction extends IResource { | ||
/** | ||
* the name of this AppSync Function | ||
* | ||
* @attribute | ||
*/ | ||
readonly functionId: string; | ||
/** | ||
* the ARN of the AppSync function | ||
* | ||
* @attribute | ||
*/ | ||
readonly functionArn: string; | ||
} | ||
|
||
/** | ||
* AppSync Functions are local functions that perform certain operations | ||
* onto a backend data source. Developers can compose operations (Functions) | ||
* and execute them in sequence with Pipeline Resolvers. | ||
* | ||
* @resource AWS::AppSync::FunctionConfiguration | ||
*/ | ||
export class AppsyncFunction extends Resource implements IAppsyncFunction { | ||
/** | ||
* Import Appsync Function from arn | ||
*/ | ||
public static fromAppsyncFunctionAttributes(scope: Construct, id: string, attrs: AppsyncFunctionAttributes): IAppsyncFunction { | ||
class Import extends Resource { | ||
public readonly functionId = Lazy.stringValue({ | ||
produce: () => Fn.select(3, Fn.split('/', attrs.functionArn)), | ||
}); | ||
public readonly functionArn = attrs.functionArn; | ||
constructor (s: Construct, i: string) { | ||
super(s, i); | ||
} | ||
} | ||
return new Import(scope, id); | ||
} | ||
|
||
/** | ||
* the name of this AppSync Function | ||
* | ||
* @attribute Name | ||
*/ | ||
public readonly functionName: string; | ||
/** | ||
* the ARN of the AppSync function | ||
* | ||
* @attribute | ||
*/ | ||
public readonly functionArn: string; | ||
/** | ||
* the ID of the AppSync function | ||
* | ||
* @attribute | ||
*/ | ||
public readonly functionId: string; | ||
/** | ||
* the data source of this AppSync Function | ||
* | ||
* @attribute DataSourceName | ||
*/ | ||
public readonly dataSource: BaseDataSource; | ||
|
||
private readonly function: CfnFunctionConfiguration; | ||
|
||
public constructor(scope: Construct, id: string, props: AppsyncFunctionProps) { | ||
super(scope, id); | ||
this.function = new CfnFunctionConfiguration(this, 'Resource', { | ||
name: props.name, | ||
description: props.description, | ||
apiId: props.api.apiId, | ||
dataSourceName: props.dataSource.name, | ||
functionVersion: '2018-05-29', | ||
requestMappingTemplate: props.requestMappingTemplate?.renderTemplate(), | ||
responseMappingTemplate: props.responseMappingTemplate?.renderTemplate(), | ||
}); | ||
this.functionName = this.function.attrName; | ||
this.functionArn = this.function.attrFunctionArn; | ||
this.functionId = this.function.attrFunctionId; | ||
this.dataSource = props.dataSource; | ||
|
||
this.function.addDependsOn(this.dataSource.ds); | ||
props.api.addSchemaDependency(this.function); | ||
} | ||
} |
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
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
Oops, something went wrong.