Skip to content

Commit 7f608ba

Browse files
Merge branch 'master' into feature/authorization_within_httpdatasource
2 parents 392bf12 + 327b72a commit 7f608ba

File tree

144 files changed

+5714
-1333
lines changed

Some content is hidden

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

144 files changed

+5714
-1333
lines changed

packages/@aws-cdk/aws-apigateway/lib/usage-plan.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,8 @@ export class UsagePlan extends Resource {
248248
validateInteger(rateLimit, 'Throttle rate limit');
249249

250250
ret = {
251-
burstLimit: burstLimit ? burstLimit : undefined,
252-
rateLimit: rateLimit ? rateLimit : undefined,
251+
burstLimit: burstLimit,
252+
rateLimit: rateLimit,
253253
};
254254
}
255255
return ret!;

packages/@aws-cdk/aws-apigateway/test/test.usage-plan.ts

+55-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export = {
3434
const api = new apigateway.RestApi(stack, 'my-api', { cloudWatchRole: false, deploy: true, deployOptions: { stageName: 'test' } });
3535
const method: apigateway.Method = api.root.addMethod('GET'); // Need at least one method on the api
3636
const usagePlanName = 'Basic';
37-
const usagePlanDescription = 'Basic Usage Plan with no throttling limits';
37+
const usagePlanDescription = 'Basic Usage Plan with throttling limits';
3838

3939
// WHEN
4040
new apigateway.UsagePlan(stack, 'my-usage-plan', {
@@ -82,6 +82,60 @@ export = {
8282

8383
},
8484

85+
'usage plan with blocked methods'(test: Test) {
86+
// GIVEN
87+
const stack = new cdk.Stack();
88+
const api = new apigateway.RestApi(stack, 'my-api', { cloudWatchRole: false, deploy: true, deployOptions: { stageName: 'test' } });
89+
const method: apigateway.Method = api.root.addMethod('GET'); // Need at least one method on the api
90+
const usagePlanName = 'Basic';
91+
const usagePlanDescription = 'Basic Usage Plan with throttling limits';
92+
93+
// WHEN
94+
new apigateway.UsagePlan(stack, 'my-usage-plan', {
95+
name: usagePlanName,
96+
description: usagePlanDescription,
97+
apiStages: [
98+
{
99+
stage: api.deploymentStage,
100+
throttle: [
101+
{
102+
method,
103+
throttle: {
104+
burstLimit: 0,
105+
rateLimit: 0,
106+
},
107+
},
108+
],
109+
},
110+
],
111+
});
112+
113+
// THEN
114+
expect(stack).to(haveResource(RESOURCE_TYPE, {
115+
UsagePlanName: usagePlanName,
116+
Description: usagePlanDescription,
117+
ApiStages: [
118+
{
119+
ApiId: {
120+
Ref: 'myapi4C7BF186',
121+
},
122+
Stage: {
123+
Ref: 'myapiDeploymentStagetest4A4AB65E',
124+
},
125+
Throttle: {
126+
'//GET': {
127+
BurstLimit: 0,
128+
RateLimit: 0,
129+
},
130+
},
131+
},
132+
],
133+
}, ResourcePart.Properties));
134+
135+
test.done();
136+
137+
},
138+
85139
'usage plan with quota limits'(test: Test) {
86140
// GIVEN
87141
const stack = new cdk.Stack();

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

+37-10
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ CDK stack file `app-stack.ts`:
4747
import * as appsync from '@aws-cdk/aws-appsync';
4848
import * as db from '@aws-cdk/aws-dynamodb';
4949

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

175175
```ts
176-
const api = new appsync.GraphQLApi(stack, 'api', { name: 'myApi' });
176+
const api = new appsync.GraphqlApi(stack, 'api', { name: 'myApi' });
177177
```
178178

179179
CDK will declare a `Schema` class that will give your Api access functions to
@@ -187,7 +187,7 @@ const schema = new appsync.Schema();
187187
schema.addObjectType('demo', {
188188
definition: { id: appsync.GraphqlType.id() },
189189
});
190-
const api = new appsync.GraphQLApi(stack, 'api', {
190+
const api = new appsync.GraphqlApi(stack, 'api', {
191191
name: 'myApi',
192192
schema
193193
});
@@ -201,7 +201,7 @@ You can define your GraphQL Schema from a file on disk. For convenience, use
201201
the `appsync.Schema.fromAsset` to specify the file representing your schema.
202202

203203
```ts
204-
const api = appsync.GraphQLApi(stack, 'api', {
204+
const api = appsync.GraphqlApi(stack, 'api', {
205205
name: 'myApi',
206206
schema: appsync.Schema.fromAsset(join(__dirname, 'schema.graphl')),
207207
});
@@ -210,10 +210,10 @@ const api = appsync.GraphQLApi(stack, 'api', {
210210
## Imports
211211
Any GraphQL Api that has been created outside the stack can be imported from
212212
another stack into your CDK app. Utilizing the `fromXxx` function, you have
213-
the ability to add data sources and resolvers through a `IGraphQLApi` interface.
213+
the ability to add data sources and resolvers through a `IGraphqlApi` interface.
214214

215215
```ts
216-
const importedApi = appsync.GraphQLApi.fromGraphQLApiAttributes(stack, 'IApi', {
216+
const importedApi = appsync.GraphqlApi.fromGraphqlApiAttributes(stack, 'IApi', {
217217
graphqlApiId: api.apiId,
218218
graphqlArn: api.arn,
219219
});
@@ -269,7 +269,7 @@ Use the `grant` function for more granular authorization.
269269
const role = new iam.Role(stack, 'Role', {
270270
assumedBy: new iam.ServicePrincipal('lambda.amazonaws.com'),
271271
});
272-
const api = new appsync.GraphQLApi(stack, 'API', {
272+
const api = new appsync.GraphqlApi(stack, 'API', {
273273
definition
274274
});
275275

@@ -401,7 +401,7 @@ to generate our schema.
401401
import * as appsync from '@aws-cdk/aws-appsync';
402402
import * as schema from './object-types';
403403

404-
const api = new appsync.GraphQLApi(stack, 'Api', {
404+
const api = new appsync.GraphqlApi(stack, 'Api', {
405405
name: 'demo',
406406
});
407407

@@ -548,6 +548,7 @@ Types will be the meat of your GraphQL Schema as they are the types defined by y
548548
Intermediate Types include:
549549
- [**Interface Types**](#Interface-Types)
550550
- [**Object Types**](#Object-Types)
551+
- [**Input Types**](#Input-Types)
551552

552553
##### Interface Types
553554

@@ -574,7 +575,7 @@ You can create Object Types in three ways:
574575

575576
1. Object Types can be created ***externally***.
576577
```ts
577-
const api = new appsync.GraphQLApi(stack, 'Api', {
578+
const api = new appsync.GraphqlApi(stack, 'Api', {
578579
name: 'demo',
579580
});
580581
const demo = new appsync.ObjectType('Demo', {
@@ -629,7 +630,7 @@ You can create Object Types in three ways:
629630

630631
3. Object Types can be created ***internally*** within the GraphQL API.
631632
```ts
632-
const api = new appsync.GraphQLApi(stack, 'Api', {
633+
const api = new appsync.GraphqlApi(stack, 'Api', {
633634
name: 'demo',
634635
});
635636
api.addType('Demo', {
@@ -641,6 +642,32 @@ You can create Object Types in three ways:
641642
```
642643
> This method provides easy use and is ideal for smaller projects.
643644

645+
##### Input Types
646+
647+
**Input Types** are special types of Intermediate Types. They give users an
648+
easy way to pass complex objects for top level Mutation and Queries.
649+
650+
```gql
651+
input Review {
652+
stars: Int!
653+
commentary: String
654+
}
655+
```
656+
657+
The above GraphQL Input Type can be expressed in CDK as the following:
658+
659+
```ts
660+
const review = new appsync.InputType('Review', {
661+
definition: {
662+
stars: GraphqlType.int({ isRequired: true }),
663+
commentary: GraphqlType.string(),
664+
},
665+
});
666+
api.addType(review);
667+
```
668+
669+
To learn more about **Input Types**, read the docs [here](https://graphql.org/learn/schema/#input-types).
670+
644671
#### Query
645672

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

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

+7-7
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ export interface LogConfig {
206206
/**
207207
* Properties for an AppSync GraphQL API
208208
*/
209-
export interface GraphQLApiProps {
209+
export interface GraphqlApiProps {
210210
/**
211211
* the name of the GraphQL API
212212
*/
@@ -293,7 +293,7 @@ export class IamResource {
293293
*
294294
* @param api The GraphQL API to give permissions
295295
*/
296-
public resourceArns(api: GraphQLApi): string[] {
296+
public resourceArns(api: GraphqlApi): string[] {
297297
return this.arns.map((arn) => Stack.of(api).formatArn({
298298
service: 'appsync',
299299
resource: `apis/${api.apiId}`,
@@ -325,7 +325,7 @@ export interface GraphqlApiAttributes {
325325
*
326326
* @resource AWS::AppSync::GraphQLApi
327327
*/
328-
export class GraphQLApi extends GraphqlApiBase {
328+
export class GraphqlApi extends GraphqlApiBase {
329329
/**
330330
* Import a GraphQL API through this function
331331
*
@@ -362,9 +362,9 @@ export class GraphQLApi extends GraphqlApiBase {
362362
/**
363363
* the URL of the endpoint created by AppSync
364364
*
365-
* @attribute
365+
* @attribute GraphQlUrl
366366
*/
367-
public readonly graphQlUrl: string;
367+
public readonly graphqlUrl: string;
368368

369369
/**
370370
* the name of the API
@@ -387,7 +387,7 @@ export class GraphQLApi extends GraphqlApiBase {
387387
private api: CfnGraphQLApi;
388388
private apiKeyResource?: CfnApiKey;
389389

390-
constructor(scope: Construct, id: string, props: GraphQLApiProps) {
390+
constructor(scope: Construct, id: string, props: GraphqlApiProps) {
391391
super(scope, id);
392392

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

410410
this.apiId = this.api.attrApiId;
411411
this.arn = this.api.attrArn;
412-
this.graphQlUrl = this.api.attrGraphQlUrl;
412+
this.graphqlUrl = this.api.attrGraphQlUrl;
413413
this.name = this.api.name;
414414
this.schema = props.schema ?? new Schema();
415415
this.schemaResource = this.schema.bind(this);

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

+26-3
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,30 @@ export interface IField {
6363
argsToString(): string;
6464
}
6565

66+
/**
67+
* The options to add a field to an Intermediate Type
68+
*/
69+
export interface AddFieldOptions {
70+
/**
71+
* The name of the field
72+
*
73+
* This option must be configured for Object, Interface,
74+
* Input and Enum Types.
75+
*
76+
* @default - no fieldName
77+
*/
78+
readonly fieldName?: string;
79+
/**
80+
* The resolvable field to add
81+
*
82+
* This option must be configured for Object, Interface,
83+
* Input and Union Types.
84+
*
85+
* @default - no IField
86+
*/
87+
readonly field?: IField;
88+
}
89+
6690
/**
6791
* Intermediate Types are types that includes a certain set of fields
6892
* that define the entirety of your schema
@@ -123,10 +147,9 @@ export interface IIntermediateType {
123147
/**
124148
* Add a field to this Intermediate Type
125149
*
126-
* @param fieldName - The name of the field
127-
* @param field - the resolvable field to add
150+
* @param options - the options to add a field
128151
*/
129-
addField(fieldName: string, field: IField): void;
152+
addField(options: AddFieldOptions): void;
130153
}
131154

132155
/**

0 commit comments

Comments
 (0)