Skip to content

Commit

Permalink
Merge pull request #22 from aws/master
Browse files Browse the repository at this point in the history
Merge
  • Loading branch information
flemjame-at-amazon authored Sep 2, 2020
2 parents 446a54c + 4e5829a commit 26f6998
Show file tree
Hide file tree
Showing 100 changed files with 3,825 additions and 974 deletions.
4 changes: 2 additions & 2 deletions packages/@aws-cdk/aws-apigateway/lib/usage-plan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,8 @@ export class UsagePlan extends Resource {
validateInteger(rateLimit, 'Throttle rate limit');

ret = {
burstLimit: burstLimit ? burstLimit : undefined,
rateLimit: rateLimit ? rateLimit : undefined,
burstLimit: burstLimit,
rateLimit: rateLimit,
};
}
return ret!;
Expand Down
56 changes: 55 additions & 1 deletion packages/@aws-cdk/aws-apigateway/test/test.usage-plan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export = {
const api = new apigateway.RestApi(stack, 'my-api', { cloudWatchRole: false, deploy: true, deployOptions: { stageName: 'test' } });
const method: apigateway.Method = api.root.addMethod('GET'); // Need at least one method on the api
const usagePlanName = 'Basic';
const usagePlanDescription = 'Basic Usage Plan with no throttling limits';
const usagePlanDescription = 'Basic Usage Plan with throttling limits';

// WHEN
new apigateway.UsagePlan(stack, 'my-usage-plan', {
Expand Down Expand Up @@ -82,6 +82,60 @@ export = {

},

'usage plan with blocked methods'(test: Test) {
// GIVEN
const stack = new cdk.Stack();
const api = new apigateway.RestApi(stack, 'my-api', { cloudWatchRole: false, deploy: true, deployOptions: { stageName: 'test' } });
const method: apigateway.Method = api.root.addMethod('GET'); // Need at least one method on the api
const usagePlanName = 'Basic';
const usagePlanDescription = 'Basic Usage Plan with throttling limits';

// WHEN
new apigateway.UsagePlan(stack, 'my-usage-plan', {
name: usagePlanName,
description: usagePlanDescription,
apiStages: [
{
stage: api.deploymentStage,
throttle: [
{
method,
throttle: {
burstLimit: 0,
rateLimit: 0,
},
},
],
},
],
});

// THEN
expect(stack).to(haveResource(RESOURCE_TYPE, {
UsagePlanName: usagePlanName,
Description: usagePlanDescription,
ApiStages: [
{
ApiId: {
Ref: 'myapi4C7BF186',
},
Stage: {
Ref: 'myapiDeploymentStagetest4A4AB65E',
},
Throttle: {
'//GET': {
BurstLimit: 0,
RateLimit: 0,
},
},
},
],
}, ResourcePart.Properties));

test.done();

},

'usage plan with quota limits'(test: Test) {
// GIVEN
const stack = new cdk.Stack();
Expand Down
47 changes: 37 additions & 10 deletions packages/@aws-cdk/aws-appsync/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ CDK stack file `app-stack.ts`:
import * as appsync from '@aws-cdk/aws-appsync';
import * as db from '@aws-cdk/aws-dynamodb';

const api = new appsync.GraphQLApi(stack, 'Api', {
const api = new appsync.GraphqlApi(stack, 'Api', {
name: 'demo',
schema: appsync.Schema.fromAsset(join(__dirname, 'schema.graphql')),
authorizationConfig: {
Expand Down Expand Up @@ -94,7 +94,7 @@ When declaring your GraphQL Api, CDK defaults to a code-first approach if the
`schema` property is not configured.

```ts
const api = new appsync.GraphQLApi(stack, 'api', { name: 'myApi' });
const api = new appsync.GraphqlApi(stack, 'api', { name: 'myApi' });
```

CDK will declare a `Schema` class that will give your Api access functions to
Expand All @@ -108,7 +108,7 @@ const schema = new appsync.Schema();
schema.addObjectType('demo', {
definition: { id: appsync.GraphqlType.id() },
});
const api = new appsync.GraphQLApi(stack, 'api', {
const api = new appsync.GraphqlApi(stack, 'api', {
name: 'myApi',
schema
});
Expand All @@ -122,7 +122,7 @@ You can define your GraphQL Schema from a file on disk. For convenience, use
the `appsync.Schema.fromAsset` to specify the file representing your schema.

```ts
const api = appsync.GraphQLApi(stack, 'api', {
const api = appsync.GraphqlApi(stack, 'api', {
name: 'myApi',
schema: appsync.Schema.fromAsset(join(__dirname, 'schema.graphl')),
});
Expand All @@ -132,10 +132,10 @@ const api = appsync.GraphQLApi(stack, 'api', {

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.
the ability to add data sources and resolvers through a `IGraphqlApi` interface.

```ts
const importedApi = appsync.GraphQLApi.fromGraphQLApiAttributes(stack, 'IApi', {
const importedApi = appsync.GraphqlApi.fromGraphqlApiAttributes(stack, 'IApi', {
graphqlApiId: api.apiId,
graphqlArn: api.arn,
});
Expand Down Expand Up @@ -191,7 +191,7 @@ Use the `grant` function for more granular authorization.
const role = new iam.Role(stack, 'Role', {
assumedBy: new iam.ServicePrincipal('lambda.amazonaws.com'),
});
const api = new appsync.GraphQLApi(stack, 'API', {
const api = new appsync.GraphqlApi(stack, 'API', {
definition
});

Expand Down Expand Up @@ -323,7 +323,7 @@ to generate our schema.
import * as appsync from '@aws-cdk/aws-appsync';
import * as schema from './object-types';

const api = new appsync.GraphQLApi(stack, 'Api', {
const api = new appsync.GraphqlApi(stack, 'Api', {
name: 'demo',
});

Expand Down Expand Up @@ -470,6 +470,7 @@ Types will be the meat of your GraphQL Schema as they are the types defined by y
Intermediate Types include:
- [**Interface Types**](#Interface-Types)
- [**Object Types**](#Object-Types)
- [**Input Types**](#Input-Types)

##### Interface Types

Expand All @@ -496,7 +497,7 @@ You can create Object Types in three ways:

1. Object Types can be created ***externally***.
```ts
const api = new appsync.GraphQLApi(stack, 'Api', {
const api = new appsync.GraphqlApi(stack, 'Api', {
name: 'demo',
});
const demo = new appsync.ObjectType('Demo', {
Expand Down Expand Up @@ -551,7 +552,7 @@ You can create Object Types in three ways:

3. Object Types can be created ***internally*** within the GraphQL API.
```ts
const api = new appsync.GraphQLApi(stack, 'Api', {
const api = new appsync.GraphqlApi(stack, 'Api', {
name: 'demo',
});
api.addType('Demo', {
Expand All @@ -563,6 +564,32 @@ You can create Object Types in three ways:
```
> This method provides easy use and is ideal for smaller projects.

##### Input Types

**Input Types** are special types of Intermediate Types. They give users an
easy way to pass complex objects for top level Mutation and Queries.

```gql
input Review {
stars: Int!
commentary: String
}
```

The above GraphQL Input Type can be expressed in CDK as the following:

```ts
const review = new appsync.InputType('Review', {
definition: {
stars: GraphqlType.int({ isRequired: true }),
commentary: GraphqlType.string(),
},
});
api.addType(review);
```

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

#### Query

Every schema requires a top level Query type. By default, the schema will look
Expand Down
14 changes: 7 additions & 7 deletions packages/@aws-cdk/aws-appsync/lib/graphqlapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ export interface LogConfig {
/**
* Properties for an AppSync GraphQL API
*/
export interface GraphQLApiProps {
export interface GraphqlApiProps {
/**
* the name of the GraphQL API
*/
Expand Down Expand Up @@ -293,7 +293,7 @@ export class IamResource {
*
* @param api The GraphQL API to give permissions
*/
public resourceArns(api: GraphQLApi): string[] {
public resourceArns(api: GraphqlApi): string[] {
return this.arns.map((arn) => Stack.of(api).formatArn({
service: 'appsync',
resource: `apis/${api.apiId}`,
Expand Down Expand Up @@ -325,7 +325,7 @@ export interface GraphqlApiAttributes {
*
* @resource AWS::AppSync::GraphQLApi
*/
export class GraphQLApi extends GraphqlApiBase {
export class GraphqlApi extends GraphqlApiBase {
/**
* Import a GraphQL API through this function
*
Expand Down Expand Up @@ -362,9 +362,9 @@ export class GraphQLApi extends GraphqlApiBase {
/**
* the URL of the endpoint created by AppSync
*
* @attribute
* @attribute GraphQlUrl
*/
public readonly graphQlUrl: string;
public readonly graphqlUrl: string;

/**
* the name of the API
Expand All @@ -387,7 +387,7 @@ export class GraphQLApi extends GraphqlApiBase {
private api: CfnGraphQLApi;
private apiKeyResource?: CfnApiKey;

constructor(scope: Construct, id: string, props: GraphQLApiProps) {
constructor(scope: Construct, id: string, props: GraphqlApiProps) {
super(scope, id);

const defaultMode = props.authorizationConfig?.defaultAuthorization ??
Expand All @@ -409,7 +409,7 @@ export class GraphQLApi extends GraphqlApiBase {

this.apiId = this.api.attrApiId;
this.arn = this.api.attrArn;
this.graphQlUrl = this.api.attrGraphQlUrl;
this.graphqlUrl = this.api.attrGraphQlUrl;
this.name = this.api.name;
this.schema = props.schema ?? new Schema();
this.schemaResource = this.schema.bind(this);
Expand Down
29 changes: 26 additions & 3 deletions packages/@aws-cdk/aws-appsync/lib/schema-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,30 @@ export interface IField {
argsToString(): string;
}

/**
* The options to add a field to an Intermediate Type
*/
export interface AddFieldOptions {
/**
* The name of the field
*
* This option must be configured for Object, Interface,
* Input and Enum Types.
*
* @default - no fieldName
*/
readonly fieldName?: string;
/**
* The resolvable field to add
*
* This option must be configured for Object, Interface,
* Input and Union Types.
*
* @default - no IField
*/
readonly field?: IField;
}

/**
* Intermediate Types are types that includes a certain set of fields
* that define the entirety of your schema
Expand Down Expand Up @@ -123,10 +147,9 @@ export interface IIntermediateType {
/**
* Add a field to this Intermediate Type
*
* @param fieldName - The name of the field
* @param field - the resolvable field to add
* @param options - the options to add a field
*/
addField(fieldName: string, field: IField): void;
addField(options: AddFieldOptions): void;
}

/**
Expand Down
Loading

0 comments on commit 26f6998

Please sign in to comment.