Skip to content

Commit

Permalink
Merge branch 'master' into njlynch/rds-oracle-se
Browse files Browse the repository at this point in the history
  • Loading branch information
njlynch authored Sep 9, 2020
2 parents 4c5b024 + 61865aa commit 865e9b2
Show file tree
Hide file tree
Showing 84 changed files with 2,718 additions and 662 deletions.
7 changes: 7 additions & 0 deletions allowed-breaking-changes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,10 @@ changed-type:@aws-cdk/aws-codedeploy.ServerDeploymentGroup.autoScalingGroups
change-return-type:@aws-cdk/aws-ecs.ContainerDefinition.renderContainerDefinition
change-return-type:@aws-cdk/aws-ecs.FirelensLogRouter.renderContainerDefinition
change-return-type:@aws-cdk/aws-ecs.LinuxParameters.renderLinuxParameters

# These were accidentally not marked @experimental
removed:@aws-cdk/core.BootstraplessSynthesizer.synthesizeStackArtifacts
removed:@aws-cdk/core.DefaultStackSynthesizer.synthesizeStackArtifacts
removed:@aws-cdk/core.LegacyStackSynthesizer.synthesizeStackArtifacts
removed:@aws-cdk/core.NestedStackSynthesizer.synthesizeStackArtifacts
removed:@aws-cdk/core.IStackSynthesizer.synthesizeStackArtifacts
12 changes: 12 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,18 @@
"@aws-cdk/core/minimatch/**",
"@aws-cdk/cx-api/semver",
"@aws-cdk/cx-api/semver/**",
"aws-cdk-lib/case",
"aws-cdk-lib/case/**",
"aws-cdk-lib/fs-extra",
"aws-cdk-lib/fs-extra/**",
"aws-cdk-lib/jsonschema",
"aws-cdk-lib/jsonschema/**",
"aws-cdk-lib/minimatch",
"aws-cdk-lib/minimatch/**",
"aws-cdk-lib/semver",
"aws-cdk-lib/semver/**",
"aws-cdk-lib/yaml",
"aws-cdk-lib/yaml/**",
"monocdk-experiment/case",
"monocdk-experiment/case/**",
"monocdk-experiment/fs-extra",
Expand Down
111 changes: 109 additions & 2 deletions packages/@aws-cdk/aws-appsync/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ APIs that use GraphQL.

### Example

### DynamoDB

Example of a GraphQL API with `AWS_IAM` authorization resolving into a DynamoDb
backend data source.
backend data source.

GraphQL schema file `schema.graphql`:

Expand Down Expand Up @@ -82,6 +84,83 @@ demoDS.createResolver({
});
```

#### HTTP Endpoints
GraphQL schema file `schema.graphql`:

```gql
type job {
id: String!
version: String!
}

input DemoInput {
version: String!
}

type Mutation {
callStepFunction(input: DemoInput!): job
}
```

GraphQL request mapping template `request.vtl`:

```
{
"version": "2018-05-29",
"method": "POST",
"resourcePath": "/",
"params": {
"headers": {
"content-type": "application/x-amz-json-1.0",
"x-amz-target":"AWSStepFunctions.StartExecution"
},
"body": {
"stateMachineArn": "<your step functions arn>",
"input": "{ \"id\": \"$context.arguments.id\" }"
}
}
}
```
GraphQL response mapping template `response.vtl`:
```
{
"id": "${context.result.id}"
}
```
CDK stack file `app-stack.ts`:
```ts
import * as appsync from '@aws-cdk/aws-appsync';
const api = new appsync.GraphqlApi(scope, 'api', {
name: 'api',
schema: appsync.Schema.fromFile(join(__dirname, 'schema.graphql')),
});
const httpDs = api.addHttpDataSource(
'ds',
'https://states.amazonaws.com',
{
name: 'httpDsWithStepF',
description: 'from appsync to StepFunctions Workflow',
authorizationConfig: {
signingRegion: 'us-east-1',
signingServiceName: 'states'
}
}
);
httpDs.createResolver({
typeName: 'Mutation',
fieldName: 'callStepFunction',
requestMappingTemplate: MappingTemplate.fromFile('request.vtl'),
responseMappingTemplate: MappingTemplate.fromFile('response.vtl')
});
```

### Schema

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

### Imports

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

##### Interface Types

Expand Down Expand Up @@ -591,6 +670,34 @@ api.addType(review);

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

### Union Types

**Union Types** are a special type of Intermediate Type. They are similar to
Interface Types, but they cannot specify any common fields between types.

**Note:** the fields of a union type need to be `Object Types`. In other words, you
can't create a union type out of interfaces, other unions, or inputs.

```gql
union Search = Human | Droid | Starship
```

The above GraphQL Union Type encompasses the Object Types of Human, Droid and Starship. It
can be expressed in CDK as the following:

```ts
const string = appsync.GraphqlType.string();
const human = new appsync.ObjectType('Human', { definition: { name: string } });
const droid = new appsync.ObjectType('Droid', { definition: { name: string } });
const starship = new appsync.ObjectType('Starship', { definition: { name: string } }););
const search = new appsync.UnionType('Search', {
definition: [ human, droid, starship ],
});
api.addType(search);
```

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

#### Query

Every schema requires a top level Query type. By default, the schema will look
Expand Down
30 changes: 29 additions & 1 deletion packages/@aws-cdk/aws-appsync/lib/data-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,21 @@ export class DynamoDbDataSource extends BackedDataSource {
}
}

/**
* The authorization config in case the HTTP endpoint requires authorization
*/
export interface AwsIamConfig {
/**
* The signing region for AWS IAM authorization
*/
readonly signingRegion: string;

/**
* The signing service name for AWS IAM authorization
*/
readonly signingServiceName: string;
}

/**
* Properties for an AppSync http datasource
*/
Expand All @@ -211,18 +226,31 @@ export interface HttpDataSourceProps extends BaseDataSourceProps {
* The http endpoint
*/
readonly endpoint: string;

/**
* The authorization config in case the HTTP endpoint requires authorization
*
* @default - none
*
*/
readonly authorizationConfig?: AwsIamConfig;
}

/**
* An AppSync datasource backed by a http endpoint
*/
export class HttpDataSource extends BaseDataSource {
constructor(scope: Construct, id: string, props: HttpDataSourceProps) {
const authorizationConfig = props.authorizationConfig ? {
authorizationType: 'AWS_IAM',
awsIamConfig: props.authorizationConfig,
} : undefined;
super(scope, id, props, {
type: 'HTTP',
httpConfig: {
endpoint: props.endpoint,
authorizationConfig,
},
type: 'HTTP',
});
}
}
Expand Down
19 changes: 16 additions & 3 deletions packages/@aws-cdk/aws-appsync/lib/graphqlapi-base.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
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';
import { DynamoDbDataSource, HttpDataSource, LambdaDataSource, NoneDataSource, AwsIamConfig } from './data-source';

/**
* Optional configuration for data sources
Expand All @@ -22,6 +22,18 @@ export interface DataSourceOptions {
readonly description?: string;
}

/**
* Optional configuration for Http data sources
*/
export interface HttpDataSourceOptions extends DataSourceOptions {
/**
* The authorization config in case the HTTP endpoint requires authorization
*
* @default - none
*/
readonly authorizationConfig?: AwsIamConfig;
}

/**
* Interface for GraphQL
*/
Expand Down Expand Up @@ -67,7 +79,7 @@ export interface IGraphqlApi extends IResource {
* @param endpoint The http endpoint
* @param options The optional configuration for this data source
*/
addHttpDataSource(id: string, endpoint: string, options?: DataSourceOptions): HttpDataSource;
addHttpDataSource(id: string, endpoint: string, options?: HttpDataSourceOptions): HttpDataSource;

/**
* add a new Lambda data source to this API
Expand Down Expand Up @@ -140,12 +152,13 @@ export abstract class GraphqlApiBase extends Resource implements IGraphqlApi {
* @param endpoint The http endpoint
* @param options The optional configuration for this data source
*/
public addHttpDataSource(id: string, endpoint: string, options?: DataSourceOptions): HttpDataSource {
public addHttpDataSource(id: string, endpoint: string, options?: HttpDataSourceOptions): HttpDataSource {
return new HttpDataSource(this, id, {
api: this,
endpoint,
name: options?.name,
description: options?.description,
authorizationConfig: options?.authorizationConfig,
});
}

Expand Down
Loading

0 comments on commit 865e9b2

Please sign in to comment.