Skip to content

Commit 7af4dab

Browse files
authored
Merge branch 'master' into appsync-expires
2 parents d38aa2a + b895599 commit 7af4dab

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1659
-697
lines changed

.mergify.yml

-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ pull_request_rules:
1717
method: squash
1818
strict_method: merge
1919
commit_message: title+body
20-
delete_head_branch: {}
2120
conditions:
2221
- base!=release
2322
- -title~=(WIP|wip)
@@ -41,7 +40,6 @@ pull_request_rules:
4140
method: squash
4241
strict_method: merge
4342
commit_message: title+body
44-
delete_head_branch: {}
4543
conditions:
4644
- base!=release
4745
- -title~=(WIP|wip)
@@ -67,7 +65,6 @@ pull_request_rules:
6765
method: merge
6866
strict_method: merge
6967
commit_message: title+body
70-
delete_head_branch: {}
7168
conditions:
7269
- -title~=(WIP|wip)
7370
- -label~=(blocked|do-not-merge)
@@ -115,7 +112,6 @@ pull_request_rules:
115112
# It's not dangerous: GitHub branch protection settings prevent merging stale branches.
116113
strict: false
117114
method: squash
118-
delete_head_branch: {}
119115
conditions:
120116
- -title~=(WIP|wip)
121117
- -label~=(blocked|do-not-merge)

allowed-breaking-changes.txt

+7
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,10 @@ changed-type:@aws-cdk/aws-codedeploy.ServerDeploymentGroup.autoScalingGroups
2828
change-return-type:@aws-cdk/aws-ecs.ContainerDefinition.renderContainerDefinition
2929
change-return-type:@aws-cdk/aws-ecs.FirelensLogRouter.renderContainerDefinition
3030
change-return-type:@aws-cdk/aws-ecs.LinuxParameters.renderLinuxParameters
31+
32+
# These were accidentally not marked @experimental
33+
removed:@aws-cdk/core.BootstraplessSynthesizer.synthesizeStackArtifacts
34+
removed:@aws-cdk/core.DefaultStackSynthesizer.synthesizeStackArtifacts
35+
removed:@aws-cdk/core.LegacyStackSynthesizer.synthesizeStackArtifacts
36+
removed:@aws-cdk/core.NestedStackSynthesizer.synthesizeStackArtifacts
37+
removed:@aws-cdk/core.IStackSynthesizer.synthesizeStackArtifacts

packages/@aws-cdk/aws-appsync/README.md

+109-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ APIs that use GraphQL.
1818

1919
### Example
2020

21+
### DynamoDB
22+
2123
Example of a GraphQL API with `AWS_IAM` authorization resolving into a DynamoDb
22-
backend data source.
24+
backend data source.
2325

2426
GraphQL schema file `schema.graphql`:
2527

@@ -82,6 +84,83 @@ demoDS.createResolver({
8284
});
8385
```
8486

87+
#### HTTP Endpoints
88+
GraphQL schema file `schema.graphql`:
89+
90+
```gql
91+
type job {
92+
id: String!
93+
version: String!
94+
}
95+
96+
input DemoInput {
97+
version: String!
98+
}
99+
100+
type Mutation {
101+
callStepFunction(input: DemoInput!): job
102+
}
103+
```
104+
105+
GraphQL request mapping template `request.vtl`:
106+
107+
```
108+
{
109+
"version": "2018-05-29",
110+
"method": "POST",
111+
"resourcePath": "/",
112+
"params": {
113+
"headers": {
114+
"content-type": "application/x-amz-json-1.0",
115+
"x-amz-target":"AWSStepFunctions.StartExecution"
116+
},
117+
"body": {
118+
"stateMachineArn": "<your step functions arn>",
119+
"input": "{ \"id\": \"$context.arguments.id\" }"
120+
}
121+
}
122+
}
123+
```
124+
125+
GraphQL response mapping template `response.vtl`:
126+
127+
```
128+
{
129+
"id": "${context.result.id}"
130+
}
131+
```
132+
133+
CDK stack file `app-stack.ts`:
134+
135+
```ts
136+
import * as appsync from '@aws-cdk/aws-appsync';
137+
138+
const api = new appsync.GraphqlApi(scope, 'api', {
139+
name: 'api',
140+
schema: appsync.Schema.fromFile(join(__dirname, 'schema.graphql')),
141+
});
142+
143+
const httpDs = api.addHttpDataSource(
144+
'ds',
145+
'https://states.amazonaws.com',
146+
{
147+
name: 'httpDsWithStepF',
148+
description: 'from appsync to StepFunctions Workflow',
149+
authorizationConfig: {
150+
signingRegion: 'us-east-1',
151+
signingServiceName: 'states'
152+
}
153+
}
154+
);
155+
156+
httpDs.createResolver({
157+
typeName: 'Mutation',
158+
fieldName: 'callStepFunction',
159+
requestMappingTemplate: MappingTemplate.fromFile('request.vtl'),
160+
responseMappingTemplate: MappingTemplate.fromFile('response.vtl')
161+
});
162+
```
163+
85164
### Schema
86165

87166
Every GraphQL Api needs a schema to define the Api. CDK offers `appsync.Schema`
@@ -129,7 +208,6 @@ const api = appsync.GraphqlApi(stack, 'api', {
129208
```
130209

131210
### Imports
132-
133211
Any GraphQL Api that has been created outside the stack can be imported from
134212
another stack into your CDK app. Utilizing the `fromXxx` function, you have
135213
the ability to add data sources and resolvers through a `IGraphqlApi` interface.
@@ -486,6 +564,7 @@ Intermediate Types include:
486564
- [**Interface Types**](#Interface-Types)
487565
- [**Object Types**](#Object-Types)
488566
- [**Input Types**](#Input-Types)
567+
- [**Union Types**](#Union-Types)
489568

490569
##### Interface Types
491570

@@ -591,6 +670,34 @@ api.addType(review);
591670

592671
To learn more about **Input Types**, read the docs [here](https://graphql.org/learn/schema/#input-types).
593672

673+
### Union Types
674+
675+
**Union Types** are a special type of Intermediate Type. They are similar to
676+
Interface Types, but they cannot specify any common fields between types.
677+
678+
**Note:** the fields of a union type need to be `Object Types`. In other words, you
679+
can't create a union type out of interfaces, other unions, or inputs.
680+
681+
```gql
682+
union Search = Human | Droid | Starship
683+
```
684+
685+
The above GraphQL Union Type encompasses the Object Types of Human, Droid and Starship. It
686+
can be expressed in CDK as the following:
687+
688+
```ts
689+
const string = appsync.GraphqlType.string();
690+
const human = new appsync.ObjectType('Human', { definition: { name: string } });
691+
const droid = new appsync.ObjectType('Droid', { definition: { name: string } });
692+
const starship = new appsync.ObjectType('Starship', { definition: { name: string } }););
693+
const search = new appsync.UnionType('Search', {
694+
definition: [ human, droid, starship ],
695+
});
696+
api.addType(search);
697+
```
698+
699+
To learn more about **Union Types**, read the docs [here](https://graphql.org/learn/schema/#union-types).
700+
594701
#### Query
595702

596703
Every schema requires a top level Query type. By default, the schema will look

packages/@aws-cdk/aws-appsync/lib/data-source.ts

+29-1
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,21 @@ export class DynamoDbDataSource extends BackedDataSource {
203203
}
204204
}
205205

206+
/**
207+
* The authorization config in case the HTTP endpoint requires authorization
208+
*/
209+
export interface AwsIamConfig {
210+
/**
211+
* The signing region for AWS IAM authorization
212+
*/
213+
readonly signingRegion: string;
214+
215+
/**
216+
* The signing service name for AWS IAM authorization
217+
*/
218+
readonly signingServiceName: string;
219+
}
220+
206221
/**
207222
* Properties for an AppSync http datasource
208223
*/
@@ -211,18 +226,31 @@ export interface HttpDataSourceProps extends BaseDataSourceProps {
211226
* The http endpoint
212227
*/
213228
readonly endpoint: string;
229+
230+
/**
231+
* The authorization config in case the HTTP endpoint requires authorization
232+
*
233+
* @default - none
234+
*
235+
*/
236+
readonly authorizationConfig?: AwsIamConfig;
214237
}
215238

216239
/**
217240
* An AppSync datasource backed by a http endpoint
218241
*/
219242
export class HttpDataSource extends BaseDataSource {
220243
constructor(scope: Construct, id: string, props: HttpDataSourceProps) {
244+
const authorizationConfig = props.authorizationConfig ? {
245+
authorizationType: 'AWS_IAM',
246+
awsIamConfig: props.authorizationConfig,
247+
} : undefined;
221248
super(scope, id, props, {
249+
type: 'HTTP',
222250
httpConfig: {
223251
endpoint: props.endpoint,
252+
authorizationConfig,
224253
},
225-
type: 'HTTP',
226254
});
227255
}
228256
}

packages/@aws-cdk/aws-appsync/lib/graphqlapi-base.ts

+16-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { ITable } from '@aws-cdk/aws-dynamodb';
22
import { IFunction } from '@aws-cdk/aws-lambda';
33
import { CfnResource, IResource, Resource } from '@aws-cdk/core';
4-
import { DynamoDbDataSource, HttpDataSource, LambdaDataSource, NoneDataSource } from './data-source';
4+
import { DynamoDbDataSource, HttpDataSource, LambdaDataSource, NoneDataSource, AwsIamConfig } from './data-source';
55

66
/**
77
* Optional configuration for data sources
@@ -22,6 +22,18 @@ export interface DataSourceOptions {
2222
readonly description?: string;
2323
}
2424

25+
/**
26+
* Optional configuration for Http data sources
27+
*/
28+
export interface HttpDataSourceOptions extends DataSourceOptions {
29+
/**
30+
* The authorization config in case the HTTP endpoint requires authorization
31+
*
32+
* @default - none
33+
*/
34+
readonly authorizationConfig?: AwsIamConfig;
35+
}
36+
2537
/**
2638
* Interface for GraphQL
2739
*/
@@ -67,7 +79,7 @@ export interface IGraphqlApi extends IResource {
6779
* @param endpoint The http endpoint
6880
* @param options The optional configuration for this data source
6981
*/
70-
addHttpDataSource(id: string, endpoint: string, options?: DataSourceOptions): HttpDataSource;
82+
addHttpDataSource(id: string, endpoint: string, options?: HttpDataSourceOptions): HttpDataSource;
7183

7284
/**
7385
* add a new Lambda data source to this API
@@ -140,12 +152,13 @@ export abstract class GraphqlApiBase extends Resource implements IGraphqlApi {
140152
* @param endpoint The http endpoint
141153
* @param options The optional configuration for this data source
142154
*/
143-
public addHttpDataSource(id: string, endpoint: string, options?: DataSourceOptions): HttpDataSource {
155+
public addHttpDataSource(id: string, endpoint: string, options?: HttpDataSourceOptions): HttpDataSource {
144156
return new HttpDataSource(this, id, {
145157
api: this,
146158
endpoint,
147159
name: options?.name,
148160
description: options?.description,
161+
authorizationConfig: options?.authorizationConfig,
149162
});
150163
}
151164

0 commit comments

Comments
 (0)