From ae65030521a146190564d44b4b1de068067d875a Mon Sep 17 00:00:00 2001 From: Bryan Pan Date: Thu, 16 Jul 2020 15:43:49 -0700 Subject: [PATCH 01/21] apiKeyConfig expire works using Expires from @aws-cdk/core --- .../@aws-cdk/aws-appsync/lib/graphqlapi.ts | 30 ++- .../aws-appsync/test/appsync-auth.test.ts | 95 +++++++++ .../aws-appsync/test/appsync.auth.graphql | 12 ++ .../test/integ.auth-apikey.expected.json | 185 ++++++++++++++++++ .../aws-appsync/test/integ.auth-apikey.ts | 68 +++++++ .../test/verify.integ.auth-apikey.sh | 37 ++++ .../lib/bucket-deployment.ts | 30 +-- .../test/bucket-deployment.test.ts | 12 +- packages/@aws-cdk/core/lib/expires.ts | 78 ++++++++ packages/@aws-cdk/core/lib/index.ts | 1 + 10 files changed, 496 insertions(+), 52 deletions(-) create mode 100644 packages/@aws-cdk/aws-appsync/test/appsync-auth.test.ts create mode 100644 packages/@aws-cdk/aws-appsync/test/appsync.auth.graphql create mode 100644 packages/@aws-cdk/aws-appsync/test/integ.auth-apikey.expected.json create mode 100644 packages/@aws-cdk/aws-appsync/test/integ.auth-apikey.ts create mode 100644 packages/@aws-cdk/aws-appsync/test/verify.integ.auth-apikey.sh create mode 100644 packages/@aws-cdk/core/lib/expires.ts diff --git a/packages/@aws-cdk/aws-appsync/lib/graphqlapi.ts b/packages/@aws-cdk/aws-appsync/lib/graphqlapi.ts index e5683ef98d9d6..4a91a9656221b 100644 --- a/packages/@aws-cdk/aws-appsync/lib/graphqlapi.ts +++ b/packages/@aws-cdk/aws-appsync/lib/graphqlapi.ts @@ -1,3 +1,4 @@ +import { readFileSync } from 'fs'; import { IUserPool } from '@aws-cdk/aws-cognito'; import { ITable } from '@aws-cdk/aws-dynamodb'; import { @@ -6,8 +7,7 @@ import { ServicePrincipal, } from '@aws-cdk/aws-iam'; import { IFunction } from '@aws-cdk/aws-lambda'; -import { Construct, Duration, IResolvable } from '@aws-cdk/core'; -import { readFileSync } from 'fs'; +import { Construct, Duration, Expires, IResolvable, EpochFormat } from '@aws-cdk/core'; import { CfnApiKey, CfnGraphQLApi, @@ -118,12 +118,13 @@ export interface ApiKeyConfig { readonly description?: string; /** - * The time from creation time after which the API key expires, using RFC3339 representation. + * The time from creation time after which the API key expires. * It must be a minimum of 1 day and a maximum of 365 days from date of creation. * Rounded down to the nearest hour. - * @default - 7 days from creation time + * + * @default - 7 days rounded down to nearest hour */ - readonly expires?: string; + readonly expires?: Expires; } /** @@ -350,7 +351,7 @@ export class GraphQLApi extends Construct { name: 'DefaultAPIKey', description: 'Default API Key created by CDK', }; - this.createAPIKey(apiKeyConfig); + this._apiKey = this.createAPIKey(apiKeyConfig); } let definition; @@ -518,23 +519,18 @@ export class GraphQLApi extends Construct { }; } - private createAPIKey(config: ApiKeyConfig) { - let expires: number | undefined; - if (config.expires) { - expires = new Date(config.expires).valueOf(); - const days = (d: number) => - Date.now() + Duration.days(d).toMilliseconds(); - if (expires < days(1) || expires > days(365)) { - throw Error('API key expiration must be between 1 and 365 days.'); - } - expires = Math.round(expires / 1000); + private createAPIKey(config: ApiKeyConfig): string { + if (config.expires && + (config.expires?.date < Expires.after(Duration.days(1)).date || config.expires?.date > Expires.after(Duration.days(365)).date)) { + throw Error('API key expiration must be between 1 and 365 days.'); } + const expires = config.expires ? config.expires.getEpoch(EpochFormat.HOUR) : undefined; const key = new CfnApiKey(this, `${config.name || 'DefaultAPIKey'}ApiKey`, { expires, description: config.description || 'Default API Key created by CDK', apiId: this.apiId, }); - this._apiKey = key.attrApiKey; + return key.attrApiKey; } private formatAdditionalAuthorizationModes( diff --git a/packages/@aws-cdk/aws-appsync/test/appsync-auth.test.ts b/packages/@aws-cdk/aws-appsync/test/appsync-auth.test.ts new file mode 100644 index 0000000000000..5a8ff27bd90cd --- /dev/null +++ b/packages/@aws-cdk/aws-appsync/test/appsync-auth.test.ts @@ -0,0 +1,95 @@ +import { join } from 'path'; +import '@aws-cdk/assert/jest'; +import * as cdk from '@aws-cdk/core'; +import * as appsync from '../lib'; + +let stack: cdk.Stack; +beforeEach(() => { + // GIVEN + stack = new cdk.Stack(); +}); + +describe('AuthorizationType ApiKey', () => { + + test('apiKeyConfig creates default description and no expire field', () => { + // WHEN + new appsync.GraphQLApi(stack, 'API', { + name: 'apiKeyUnitTest', + schemaDefinitionFile: join(__dirname, 'appsync.auth.graphql'), + authorizationConfig: { + defaultAuthorization: { + authorizationType: appsync.AuthorizationType.API_KEY, + }, + }, + }); + + // THEN + expect(stack).toHaveResource('AWS::AppSync::ApiKey', { + ApiId: { 'Fn::GetAtt': ['API62EA1CFF', 'ApiId' ] }, + Description: 'Default API Key created by CDK', + }); + }); + + test('apiKeyConfig creates default description and valid expiration date', () => { + const expirationDate: number = cdk.Expires.after(cdk.Duration.days(10)).getEpoch(cdk.EpochFormat.HOUR); + + // WHEN + new appsync.GraphQLApi(stack, 'API', { + name: 'apiKeyUnitTest', + schemaDefinitionFile: join(__dirname, 'appsync.auth.graphql'), + authorizationConfig: { + defaultAuthorization: { + authorizationType: appsync.AuthorizationType.API_KEY, + apiKeyConfig: { + expires: cdk.Expires.after(cdk.Duration.days(10)), + }, + }, + }, + }); + + // THEN + expect(stack).toHaveResourceLike('AWS::AppSync::ApiKey', { + ApiId: { 'Fn::GetAtt': ['API62EA1CFF', 'ApiId' ] }, + Description: 'Default API Key created by CDK', + Expires: expirationDate, + }); + }); + + test('apiKeyConfig fails if expire argument less than a day', () => { + // WHEN + const when = () => { new appsync.GraphQLApi(stack, 'API', { + name: 'apiKeyUnitTest', + schemaDefinitionFile: join(__dirname, 'appsync.auth.graphql'), + authorizationConfig: { + defaultAuthorization: { + authorizationType: appsync.AuthorizationType.API_KEY, + apiKeyConfig: { + expires: cdk.Expires.after(cdk.Duration.hours(1)), + }, + }, + }, + }); }; + + // THEN + expect(when).toThrowError('API key expiration must be between 1 and 365 days.'); + }); + + test('apiKeyConfig fails if expire argument greater than 365 day', () => { + // WHEN + const when = () => {new appsync.GraphQLApi(stack, 'API', { + name: 'apiKeyUnitTest', + schemaDefinitionFile: join(__dirname, 'appsync.auth.graphql'), + authorizationConfig: { + defaultAuthorization: { + authorizationType: appsync.AuthorizationType.API_KEY, + apiKeyConfig: { + expires: cdk.Expires.after(cdk.Duration.days(366)), + }, + }, + }, + }); }; + + // THEN + expect(when).toThrowError('API key expiration must be between 1 and 365 days.'); + }); +}); \ No newline at end of file diff --git a/packages/@aws-cdk/aws-appsync/test/appsync.auth.graphql b/packages/@aws-cdk/aws-appsync/test/appsync.auth.graphql new file mode 100644 index 0000000000000..e59469dedfd10 --- /dev/null +++ b/packages/@aws-cdk/aws-appsync/test/appsync.auth.graphql @@ -0,0 +1,12 @@ +type test { + id: Int! + version: String! +} + +type Query { + getTests: [ test! ] +} + +type Mutation { + addTest(version: String!): test! +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-appsync/test/integ.auth-apikey.expected.json b/packages/@aws-cdk/aws-appsync/test/integ.auth-apikey.expected.json new file mode 100644 index 0000000000000..0f132e5008273 --- /dev/null +++ b/packages/@aws-cdk/aws-appsync/test/integ.auth-apikey.expected.json @@ -0,0 +1,185 @@ +{ + "Resources": { + "ApiF70053CD": { + "Type": "AWS::AppSync::GraphQLApi", + "Properties": { + "AuthenticationType": "API_KEY", + "Name": "Integ_Test_APIKey" + } + }, + "ApiDefaultAPIKeyApiKey74F5313B": { + "Type": "AWS::AppSync::ApiKey", + "Properties": { + "ApiId": { + "Fn::GetAtt": [ + "ApiF70053CD", + "ApiId" + ] + }, + "Description": "Default API Key created by CDK", + "Expires": 1595109600 + } + }, + "ApiSchema510EECD7": { + "Type": "AWS::AppSync::GraphQLSchema", + "Properties": { + "ApiId": { + "Fn::GetAtt": [ + "ApiF70053CD", + "ApiId" + ] + }, + "Definition": "type test {\n id: Int!\n version: String!\n}\n\ntype Query {\n getTests: [ test! ]\n}\n\ntype Mutation {\n addTest(version: String!): test!\n}" + } + }, + "ApitestDataSourceDSServiceRoleE543E310": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "appsync.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + } + } + }, + "ApitestDataSourceDSServiceRoleDefaultPolicy53D2252C": { + "Type": "AWS::IAM::Policy", + "Properties": { + "PolicyDocument": { + "Statement": [ + { + "Action": [ + "dynamodb:BatchGetItem", + "dynamodb:GetRecords", + "dynamodb:GetShardIterator", + "dynamodb:Query", + "dynamodb:GetItem", + "dynamodb:Scan", + "dynamodb:BatchWriteItem", + "dynamodb:PutItem", + "dynamodb:UpdateItem", + "dynamodb:DeleteItem" + ], + "Effect": "Allow", + "Resource": [ + { + "Fn::GetAtt": [ + "TestTable5769773A", + "Arn" + ] + }, + { + "Ref": "AWS::NoValue" + } + ] + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "ApitestDataSourceDSServiceRoleDefaultPolicy53D2252C", + "Roles": [ + { + "Ref": "ApitestDataSourceDSServiceRoleE543E310" + } + ] + } + }, + "ApitestDataSourceDS776EA507": { + "Type": "AWS::AppSync::DataSource", + "Properties": { + "ApiId": { + "Fn::GetAtt": [ + "ApiF70053CD", + "ApiId" + ] + }, + "Name": "testDataSource", + "Type": "AMAZON_DYNAMODB", + "Description": "Table for Tests\"", + "DynamoDBConfig": { + "AwsRegion": { + "Ref": "AWS::Region" + }, + "TableName": { + "Ref": "TestTable5769773A" + } + }, + "ServiceRoleArn": { + "Fn::GetAtt": [ + "ApitestDataSourceDSServiceRoleE543E310", + "Arn" + ] + } + } + }, + "ApitestDataSourceDSQuerygetTestsResolver61ED88B6": { + "Type": "AWS::AppSync::Resolver", + "Properties": { + "ApiId": { + "Fn::GetAtt": [ + "ApiF70053CD", + "ApiId" + ] + }, + "FieldName": "getTests", + "TypeName": "Query", + "DataSourceName": "testDataSource", + "Kind": "UNIT", + "RequestMappingTemplate": "{\"version\" : \"2017-02-28\", \"operation\" : \"Scan\"}", + "ResponseMappingTemplate": "$util.toJson($ctx.result.items)" + }, + "DependsOn": [ + "ApiSchema510EECD7", + "ApitestDataSourceDS776EA507" + ] + }, + "ApitestDataSourceDSMutationaddTestResolver0D3A4591": { + "Type": "AWS::AppSync::Resolver", + "Properties": { + "ApiId": { + "Fn::GetAtt": [ + "ApiF70053CD", + "ApiId" + ] + }, + "FieldName": "addTest", + "TypeName": "Mutation", + "DataSourceName": "testDataSource", + "Kind": "UNIT", + "RequestMappingTemplate": "\n #set($input = $ctx.args.test)\n \n {\n \"version\": \"2017-02-28\",\n \"operation\": \"PutItem\",\n \"key\" : {\n \"id\" : $util.dynamodb.toDynamoDBJson($util.autoId())\n },\n \"attributeValues\": $util.dynamodb.toMapValuesJson($input)\n }", + "ResponseMappingTemplate": "$util.toJson($ctx.result)" + }, + "DependsOn": [ + "ApiSchema510EECD7", + "ApitestDataSourceDS776EA507" + ] + }, + "TestTable5769773A": { + "Type": "AWS::DynamoDB::Table", + "Properties": { + "KeySchema": [ + { + "AttributeName": "id", + "KeyType": "HASH" + } + ], + "AttributeDefinitions": [ + { + "AttributeName": "id", + "AttributeType": "S" + } + ], + "BillingMode": "PAY_PER_REQUEST" + }, + "UpdateReplacePolicy": "Delete", + "DeletionPolicy": "Delete" + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-appsync/test/integ.auth-apikey.ts b/packages/@aws-cdk/aws-appsync/test/integ.auth-apikey.ts new file mode 100644 index 0000000000000..2f88b7582d8e6 --- /dev/null +++ b/packages/@aws-cdk/aws-appsync/test/integ.auth-apikey.ts @@ -0,0 +1,68 @@ +import { join } from 'path'; +import { AttributeType, BillingMode, Table } from '@aws-cdk/aws-dynamodb'; +import { App, RemovalPolicy, Stack, Expires, Duration } from '@aws-cdk/core'; +import { + AuthorizationType, + GraphQLApi, + MappingTemplate, + PrimaryKey, + Values, +} from '../lib'; + +/* + * Creates an Appsync GraphQL API with API_KEY authorization. + * Testing for API_KEY Authorization. + * + * Stack verification steps: + * Deploy stack, get api-key and endpoint. + * Check if authorization occurs with empty get. + * + * -- bash verify.integ.auth-apikey.sh --start -- deploy stack -- + * -- aws appsync list-graphql-apis -- obtain api id && endpoint -- + * -- aws appsync list-api-keys --api-id [API ID] -- obtain api key -- + * -- bash verify.integ.auth-apikey.sh --check [APIKEY] [ENDPOINT] -- check if fails/success -- + * -- bash verify.integ.auth-apikey.sh --clean -- clean dependencies/stack -- + */ + +const app = new App(); +const stack = new Stack(app, 'aws-appsync-integ'); + +const api = new GraphQLApi(stack, 'Api', { + name: 'Integ_Test_APIKey', + schemaDefinitionFile: join(__dirname, 'appsync.auth.graphql'), + authorizationConfig: { + defaultAuthorization: { + authorizationType: AuthorizationType.API_KEY, + apiKeyConfig: { + expires: Expires.after(Duration.days(2)), + }, + }, + }, +}); + +const testTable = new Table(stack, 'TestTable', { + billingMode: BillingMode.PAY_PER_REQUEST, + partitionKey: { + name: 'id', + type: AttributeType.STRING, + }, + removalPolicy: RemovalPolicy.DESTROY, +}); + +const testDS = api.addDynamoDbDataSource('testDataSource', 'Table for Tests"', testTable); + +testDS.createResolver({ + typeName: 'Query', + fieldName: 'getTests', + requestMappingTemplate: MappingTemplate.dynamoDbScanTable(), + responseMappingTemplate: MappingTemplate.dynamoDbResultList(), +}); + +testDS.createResolver({ + typeName: 'Mutation', + fieldName: 'addTest', + requestMappingTemplate: MappingTemplate.dynamoDbPutItem(PrimaryKey.partition('id').auto(), Values.projecting('test')), + responseMappingTemplate: MappingTemplate.dynamoDbResultItem(), +}); + +app.synth(); \ No newline at end of file diff --git a/packages/@aws-cdk/aws-appsync/test/verify.integ.auth-apikey.sh b/packages/@aws-cdk/aws-appsync/test/verify.integ.auth-apikey.sh new file mode 100644 index 0000000000000..2102f10d627e4 --- /dev/null +++ b/packages/@aws-cdk/aws-appsync/test/verify.integ.auth-apikey.sh @@ -0,0 +1,37 @@ +#!/bin/bash + +function error { + printf "\e[91;5;81m$@\e[0m\n" +} + +function usage { + echo "###############################################################################" + echo "# run 'verify.integ.auth-apikey.sh --start' to deploy #" + echo "# run 'verify.integ.auth-apikey.sh --check [APIKEY] [ENDPOINT]' to run check #" + echo "# run 'verify.integ.auth-apikey.sh --clean' to clean up stack #" + echo "###############################################################################" +} + +if [[ "$1" == "--start" ]]; then + cdk deploy --app "node integ.auth-apikey.js" +elif [[ "$1" == "--check" ]]; then + if [[ -z $2 || -z $3 ]]; then + error "Error: --check flag requires [APIKEY] [ENDPOINT]" + usage + exit 1 + fi + echo THIS TEST SHOULD FAIL + curl -XPOST -H "Content-Type:application/graphql" -H "x-api-key:garbage" -d '{ "query": "query { getTests { id version } }" }" }' $3 + echo "" + echo "" + echo THIS TEST SHOULD SUCCEED + curl -XPOST -H "Content-Type:application/graphql" -H "x-api-key:$2" -d '{ "query": "query { getTests { id version } }" }" }' $3 + echo "" +elif [[ "$1" == "--clean" ]];then + cdk destroy --app "node integ.auth-apikey.js" +else + error "Error: use flags --start, --check, --clean" + usage + exit 1 +fi + diff --git a/packages/@aws-cdk/aws-s3-deployment/lib/bucket-deployment.ts b/packages/@aws-cdk/aws-s3-deployment/lib/bucket-deployment.ts index 0fdd4fb18da23..eca74167b20e4 100644 --- a/packages/@aws-cdk/aws-s3-deployment/lib/bucket-deployment.ts +++ b/packages/@aws-cdk/aws-s3-deployment/lib/bucket-deployment.ts @@ -129,7 +129,7 @@ export interface BucketDeploymentProps { * @default - The objects in the distribution will not expire. * @see https://docs.aws.amazon.com/AmazonS3/latest/dev/UsingMetadata.html#SysMetadata */ - readonly expires?: Expires; + readonly expires?: cdk.Expires; /** * System-defined x-amz-server-side-encryption metadata to be set on all objects in the deployment. * @default - Server side encryption is not used. @@ -327,34 +327,6 @@ export enum StorageClass { DEEP_ARCHIVE = 'DEEP_ARCHIVE' } -/** - * Used for HTTP expires header, which influences downstream caches. Does NOT influence deletion of the object. - * @see https://docs.aws.amazon.com/AmazonS3/latest/dev/UsingMetadata.html#SysMetadata - */ -export class Expires { - /** - * Expire at the specified date - * @param d date to expire at - */ - public static atDate(d: Date) { return new Expires(d.toUTCString()); } - - /** - * Expire at the specified timestamp - * @param t timestamp in unix milliseconds - */ - public static atTimestamp(t: number) { return Expires.atDate(new Date(t)); } - - /** - * Expire once the specified duration has passed since deployment time - * @param t the duration to wait before expiring - */ - public static after(t: cdk.Duration) { return Expires.atDate(new Date(now + t.toMilliseconds())); } - - public static fromString(s: string) { return new Expires(s); } - - private constructor(public readonly value: any) {} -} - export interface UserDefinedObjectMetadata { /** * Arbitrary metadata key-values diff --git a/packages/@aws-cdk/aws-s3-deployment/test/bucket-deployment.test.ts b/packages/@aws-cdk/aws-s3-deployment/test/bucket-deployment.test.ts index 0859347c66c5f..5f3e64d5d4b31 100644 --- a/packages/@aws-cdk/aws-s3-deployment/test/bucket-deployment.test.ts +++ b/packages/@aws-cdk/aws-s3-deployment/test/bucket-deployment.test.ts @@ -319,7 +319,7 @@ test('system metadata is correctly transformed', () => { serverSideEncryptionCustomerAlgorithm: 'rot13', websiteRedirectLocation: 'example', cacheControl: [s3deploy.CacheControl.setPublic(), s3deploy.CacheControl.maxAge(cdk.Duration.hours(1))], - expires: s3deploy.Expires.after(cdk.Duration.hours(12)), + expires: cdk.Expires.after(cdk.Duration.hours(12)), }); // THEN @@ -332,7 +332,7 @@ test('system metadata is correctly transformed', () => { 'sse': 'aws:kms', 'sse-kms-key-id': 'mykey', 'cache-control': 'public, max-age=3600', - 'expires': s3deploy.Expires.after(cdk.Duration.hours(12)).value, + 'expires': cdk.Expires.after(cdk.Duration.hours(12)).value, 'sse-c-copy-source': 'rot13', 'website-redirect': 'example', }, @@ -340,10 +340,10 @@ test('system metadata is correctly transformed', () => { }); test('expires type has correct values', () => { - expect(s3deploy.Expires.atDate(new Date('Sun, 26 Jan 2020 00:53:20 GMT')).value).toEqual('Sun, 26 Jan 2020 00:53:20 GMT'); - expect(s3deploy.Expires.atTimestamp(1580000000000).value).toEqual('Sun, 26 Jan 2020 00:53:20 GMT'); - expect(Math.abs(new Date(s3deploy.Expires.after(cdk.Duration.minutes(10)).value).getTime() - (Date.now() + 600000)) < 15000).toBeTruthy(); - expect(s3deploy.Expires.fromString('Tue, 04 Feb 2020 08:45:33 GMT').value).toEqual('Tue, 04 Feb 2020 08:45:33 GMT'); + expect(cdk.Expires.atDate(new Date('Sun, 26 Jan 2020 00:53:20 GMT')).value).toEqual('Sun, 26 Jan 2020 00:53:20 GMT'); + expect(cdk.Expires.atTimestamp(1580000000000).value).toEqual('Sun, 26 Jan 2020 00:53:20 GMT'); + expect(Math.abs(new Date(cdk.Expires.after(cdk.Duration.minutes(10)).value).getTime() - (Date.now() + 600000)) < 15000).toBeTruthy(); + expect(cdk.Expires.fromString('Tue, 04 Feb 2020 08:45:33 GMT').value).toEqual('Tue, 04 Feb 2020 08:45:33 GMT'); }); diff --git a/packages/@aws-cdk/core/lib/expires.ts b/packages/@aws-cdk/core/lib/expires.ts new file mode 100644 index 0000000000000..b7be4643d67cc --- /dev/null +++ b/packages/@aws-cdk/core/lib/expires.ts @@ -0,0 +1,78 @@ +import { Duration } from './duration'; + +/** + * Enum for formating getEpoch output + */ +export enum EpochFormat { + /** + * Round down to nearest day + */ + DAY = 86400000, + /** + * Round down to nearest hour + */ + HOUR = 3600000, + /** + * Round down to nearest minute + */ + MINUTE = 60000, + /** + * Round down to nearest second + */ + SECOND = 1000, +} + +/** + * Represents a date of expiration. + * + * The amount can be specified either as a Date object, timestamp, Duration or string. + */ +export class Expires { + /** + * Expire at the specified date + * @param d date to expire at + */ + public static atDate(d: Date) { return new Expires(d.toUTCString(), d); } + + /** + * Expire at the specified timestamp + * @param t timestamp in unix milliseconds + */ + public static atTimestamp(t: number) { return Expires.atDate(new Date(t)); } + + /** + * Expire once the specified duration has passed since deployment time + * @param t the duration to wait before expiring + */ + public static after(t: Duration) { return Expires.atDate(new Date(Date.now() + t.toMilliseconds())); } + + /** + * Expire at specified date, represented as a string + * + * @param s the string that represents date to expire at + */ + public static fromString(s: string) { return new Expires(s, new Date(s)); } + + /** + * Expiration value as a string + */ + public readonly value: string; + + /** + * Expiration value as a Date object + */ + public readonly date: Date; + + private constructor(value: string, date: Date) { + this.value = value; + this.date = date; + } + /** + * Exipration Value in a formatted Unix Epoch Time in seconds + * @param format - round down to nearest formated number, default is seconds + */ + public getEpoch(format?: EpochFormat): number { + format = format ?? EpochFormat.SECOND; + return Math.floor( this.date.getTime() / format) * format / EpochFormat.SECOND; + } +} \ No newline at end of file diff --git a/packages/@aws-cdk/core/lib/index.ts b/packages/@aws-cdk/core/lib/index.ts index 6c54a222901d6..6a6a81e25bb49 100644 --- a/packages/@aws-cdk/core/lib/index.ts +++ b/packages/@aws-cdk/core/lib/index.ts @@ -30,6 +30,7 @@ export * from './cfn-json'; export * from './removal-policy'; export * from './arn'; export * from './duration'; +export * from './expires'; export * from './from-cfn'; export * from './size'; export * from './stack-trace'; From 5a72efe3bb5e28e2e7ad9d623f57a3439ec1d346 Mon Sep 17 00:00:00 2001 From: Bryan Pan Date: Thu, 16 Jul 2020 17:16:03 -0700 Subject: [PATCH 02/21] remove unused variable --- packages/@aws-cdk/aws-s3-deployment/lib/bucket-deployment.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/@aws-cdk/aws-s3-deployment/lib/bucket-deployment.ts b/packages/@aws-cdk/aws-s3-deployment/lib/bucket-deployment.ts index eca74167b20e4..a9a53b71899e8 100644 --- a/packages/@aws-cdk/aws-s3-deployment/lib/bucket-deployment.ts +++ b/packages/@aws-cdk/aws-s3-deployment/lib/bucket-deployment.ts @@ -8,7 +8,6 @@ import * as s3 from '@aws-cdk/aws-s3'; import * as cdk from '@aws-cdk/core'; import { ISource, SourceConfig } from './source'; -const now = Date.now(); const handlerCodeBundle = path.join(__dirname, '..', 'lambda', 'bundle.zip'); const handlerSourceDirectory = path.join(__dirname, '..', 'lambda', 'src'); From 72b5999d7572a694c5a5657feea16fc5c28f07ee Mon Sep 17 00:00:00 2001 From: Bryan Pan Date: Thu, 16 Jul 2020 17:31:17 -0700 Subject: [PATCH 03/21] update integ --- .../@aws-cdk/aws-appsync/test/integ.auth-apikey.expected.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@aws-cdk/aws-appsync/test/integ.auth-apikey.expected.json b/packages/@aws-cdk/aws-appsync/test/integ.auth-apikey.expected.json index 0f132e5008273..057b3df0501b0 100644 --- a/packages/@aws-cdk/aws-appsync/test/integ.auth-apikey.expected.json +++ b/packages/@aws-cdk/aws-appsync/test/integ.auth-apikey.expected.json @@ -17,7 +17,7 @@ ] }, "Description": "Default API Key created by CDK", - "Expires": 1595109600 + "Expires": 1595116800 } }, "ApiSchema510EECD7": { From 9397fe4f0d4be4e0b79d8dfff0dc4ba41d66f926 Mon Sep 17 00:00:00 2001 From: Bryan Pan Date: Mon, 20 Jul 2020 17:13:29 -0700 Subject: [PATCH 04/21] address suggestions for expire --- .../@aws-cdk/aws-appsync/lib/graphqlapi.ts | 5 +-- .../aws-appsync/test/appsync-auth.test.ts | 4 ++- .../test/integ.auth-apikey.expected.json | 2 +- .../aws-appsync/test/integ.auth-apikey.ts | 1 - packages/@aws-cdk/core/lib/expires.ts | 31 ------------------- packages/@aws-cdk/core/test/test.expires.ts | 29 +++++++++++++++++ 6 files changed, 36 insertions(+), 36 deletions(-) create mode 100644 packages/@aws-cdk/core/test/test.expires.ts diff --git a/packages/@aws-cdk/aws-appsync/lib/graphqlapi.ts b/packages/@aws-cdk/aws-appsync/lib/graphqlapi.ts index 4a91a9656221b..0de7e426173af 100644 --- a/packages/@aws-cdk/aws-appsync/lib/graphqlapi.ts +++ b/packages/@aws-cdk/aws-appsync/lib/graphqlapi.ts @@ -7,7 +7,7 @@ import { ServicePrincipal, } from '@aws-cdk/aws-iam'; import { IFunction } from '@aws-cdk/aws-lambda'; -import { Construct, Duration, Expires, IResolvable, EpochFormat } from '@aws-cdk/core'; +import { Construct, Duration, Expires, IResolvable } from '@aws-cdk/core'; import { CfnApiKey, CfnGraphQLApi, @@ -524,7 +524,8 @@ export class GraphQLApi extends Construct { (config.expires?.date < Expires.after(Duration.days(1)).date || config.expires?.date > Expires.after(Duration.days(365)).date)) { throw Error('API key expiration must be between 1 and 365 days.'); } - const expires = config.expires ? config.expires.getEpoch(EpochFormat.HOUR) : undefined; + const getEpoch = (d: Expires) => { return Math.floor( d.date.getTime() / 1000); }; + const expires = config.expires ? getEpoch(config.expires) : undefined; const key = new CfnApiKey(this, `${config.name || 'DefaultAPIKey'}ApiKey`, { expires, description: config.description || 'Default API Key created by CDK', diff --git a/packages/@aws-cdk/aws-appsync/test/appsync-auth.test.ts b/packages/@aws-cdk/aws-appsync/test/appsync-auth.test.ts index 5a8ff27bd90cd..8d6180bcfa28c 100644 --- a/packages/@aws-cdk/aws-appsync/test/appsync-auth.test.ts +++ b/packages/@aws-cdk/aws-appsync/test/appsync-auth.test.ts @@ -9,6 +9,8 @@ beforeEach(() => { stack = new cdk.Stack(); }); +const getEpoch = (d: cdk.Expires) => { return Math.floor( d.date.getTime()/1000 ); }; + describe('AuthorizationType ApiKey', () => { test('apiKeyConfig creates default description and no expire field', () => { @@ -31,7 +33,7 @@ describe('AuthorizationType ApiKey', () => { }); test('apiKeyConfig creates default description and valid expiration date', () => { - const expirationDate: number = cdk.Expires.after(cdk.Duration.days(10)).getEpoch(cdk.EpochFormat.HOUR); + const expirationDate: number = getEpoch(cdk.Expires.after(cdk.Duration.days(10))); // WHEN new appsync.GraphQLApi(stack, 'API', { diff --git a/packages/@aws-cdk/aws-appsync/test/integ.auth-apikey.expected.json b/packages/@aws-cdk/aws-appsync/test/integ.auth-apikey.expected.json index 057b3df0501b0..70334c8f72d68 100644 --- a/packages/@aws-cdk/aws-appsync/test/integ.auth-apikey.expected.json +++ b/packages/@aws-cdk/aws-appsync/test/integ.auth-apikey.expected.json @@ -17,7 +17,7 @@ ] }, "Description": "Default API Key created by CDK", - "Expires": 1595116800 + "Expires": 1595460955 } }, "ApiSchema510EECD7": { diff --git a/packages/@aws-cdk/aws-appsync/test/integ.auth-apikey.ts b/packages/@aws-cdk/aws-appsync/test/integ.auth-apikey.ts index 2f88b7582d8e6..934848b954be7 100644 --- a/packages/@aws-cdk/aws-appsync/test/integ.auth-apikey.ts +++ b/packages/@aws-cdk/aws-appsync/test/integ.auth-apikey.ts @@ -8,7 +8,6 @@ import { PrimaryKey, Values, } from '../lib'; - /* * Creates an Appsync GraphQL API with API_KEY authorization. * Testing for API_KEY Authorization. diff --git a/packages/@aws-cdk/core/lib/expires.ts b/packages/@aws-cdk/core/lib/expires.ts index b7be4643d67cc..aaa76f541250e 100644 --- a/packages/@aws-cdk/core/lib/expires.ts +++ b/packages/@aws-cdk/core/lib/expires.ts @@ -1,27 +1,4 @@ import { Duration } from './duration'; - -/** - * Enum for formating getEpoch output - */ -export enum EpochFormat { - /** - * Round down to nearest day - */ - DAY = 86400000, - /** - * Round down to nearest hour - */ - HOUR = 3600000, - /** - * Round down to nearest minute - */ - MINUTE = 60000, - /** - * Round down to nearest second - */ - SECOND = 1000, -} - /** * Represents a date of expiration. * @@ -67,12 +44,4 @@ export class Expires { this.value = value; this.date = date; } - /** - * Exipration Value in a formatted Unix Epoch Time in seconds - * @param format - round down to nearest formated number, default is seconds - */ - public getEpoch(format?: EpochFormat): number { - format = format ?? EpochFormat.SECOND; - return Math.floor( this.date.getTime() / format) * format / EpochFormat.SECOND; - } } \ No newline at end of file diff --git a/packages/@aws-cdk/core/test/test.expires.ts b/packages/@aws-cdk/core/test/test.expires.ts new file mode 100644 index 0000000000000..6ff17f69a6441 --- /dev/null +++ b/packages/@aws-cdk/core/test/test.expires.ts @@ -0,0 +1,29 @@ +import * as nodeunit from 'nodeunit'; +import { Duration, Expires } from '../lib'; + +export = nodeunit.testCase({ + 'from string'(test: nodeunit.Test) { + const date = new Date('Sun, 26 Jan 2020 00:53:20 GMT'); + test.equal(Expires.fromString('Sun, 26 Jan 2020 00:53:20 GMT').date.getDate(), date.getDate()); + test.done(); + }, + + 'at specified date'(test: nodeunit.Test) { + const date = new Date('Sun, 26 Jan 2020 00:53:20 GMT'); + test.equal(Expires.atDate(new Date('Sun, 26 Jan 2020 00:53:20 GMT')).value, 'Sun, 26 Jan 2020 00:53:20 GMT'); + test.equal(Expires.atDate(new Date(1580000000000)).value, 'Sun, 26 Jan 2020 00:53:20 GMT'); + test.equal(Expires.atDate(new Date(date)).value, 'Sun, 26 Jan 2020 00:53:20 GMT'); + test.done(); + }, + + 'at time stamp'(test: nodeunit.Test) { + test.equal(Expires.atDate(new Date(1580000000000)).value, 'Sun, 26 Jan 2020 00:53:20 GMT'); + test.done(); + }, + + 'after'(test: nodeunit.Test) { + test.ok(Math.abs(new Date(Expires.after(Duration.minutes(10)).value).getTime() - (Date.now() + 600000)) < 15000); + test.done(); + }, + +}); From 7ac8c883af348d79d0e50d00c975fc42e9f49052 Mon Sep 17 00:00:00 2001 From: Bryan Pan Date: Tue, 21 Jul 2020 08:37:48 -0700 Subject: [PATCH 05/21] run integ --- .../@aws-cdk/aws-appsync/test/integ.auth-apikey.expected.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@aws-cdk/aws-appsync/test/integ.auth-apikey.expected.json b/packages/@aws-cdk/aws-appsync/test/integ.auth-apikey.expected.json index 70334c8f72d68..a4e1d87c9393d 100644 --- a/packages/@aws-cdk/aws-appsync/test/integ.auth-apikey.expected.json +++ b/packages/@aws-cdk/aws-appsync/test/integ.auth-apikey.expected.json @@ -17,7 +17,7 @@ ] }, "Description": "Default API Key created by CDK", - "Expires": 1595460955 + "Expires": 1595518602 } }, "ApiSchema510EECD7": { From 8803379e39231dcce45c36bad84aa1b9270b5c33 Mon Sep 17 00:00:00 2001 From: Bryan Pan Date: Tue, 21 Jul 2020 09:30:03 -0700 Subject: [PATCH 06/21] adjust integ to set up for a year --- packages/@aws-cdk/aws-appsync/lib/graphqlapi.ts | 5 +++-- packages/@aws-cdk/aws-appsync/test/appsync-auth.test.ts | 2 +- .../aws-appsync/test/integ.auth-apikey.expected.json | 2 +- packages/@aws-cdk/aws-appsync/test/integ.auth-apikey.ts | 5 +++-- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/@aws-cdk/aws-appsync/lib/graphqlapi.ts b/packages/@aws-cdk/aws-appsync/lib/graphqlapi.ts index 0de7e426173af..3eb8df73f67ec 100644 --- a/packages/@aws-cdk/aws-appsync/lib/graphqlapi.ts +++ b/packages/@aws-cdk/aws-appsync/lib/graphqlapi.ts @@ -521,10 +521,11 @@ export class GraphQLApi extends Construct { private createAPIKey(config: ApiKeyConfig): string { if (config.expires && - (config.expires?.date < Expires.after(Duration.days(1)).date || config.expires?.date > Expires.after(Duration.days(365)).date)) { + (config.expires?.date < Expires.after(Duration.days(1)).date + || config.expires?.date > Expires.after(Duration.days(365)).date)) { throw Error('API key expiration must be between 1 and 365 days.'); } - const getEpoch = (d: Expires) => { return Math.floor( d.date.getTime() / 1000); }; + const getEpoch = (d: Expires) => { return Math.floor( d.date.getTime() / 86400000) * 86400; }; const expires = config.expires ? getEpoch(config.expires) : undefined; const key = new CfnApiKey(this, `${config.name || 'DefaultAPIKey'}ApiKey`, { expires, diff --git a/packages/@aws-cdk/aws-appsync/test/appsync-auth.test.ts b/packages/@aws-cdk/aws-appsync/test/appsync-auth.test.ts index 8d6180bcfa28c..2144e05c97330 100644 --- a/packages/@aws-cdk/aws-appsync/test/appsync-auth.test.ts +++ b/packages/@aws-cdk/aws-appsync/test/appsync-auth.test.ts @@ -9,7 +9,7 @@ beforeEach(() => { stack = new cdk.Stack(); }); -const getEpoch = (d: cdk.Expires) => { return Math.floor( d.date.getTime()/1000 ); }; +const getEpoch = (d: cdk.Expires) => { return Math.floor( d.date.getTime()/ 86400000) * 86400; }; describe('AuthorizationType ApiKey', () => { diff --git a/packages/@aws-cdk/aws-appsync/test/integ.auth-apikey.expected.json b/packages/@aws-cdk/aws-appsync/test/integ.auth-apikey.expected.json index a4e1d87c9393d..b23167154c743 100644 --- a/packages/@aws-cdk/aws-appsync/test/integ.auth-apikey.expected.json +++ b/packages/@aws-cdk/aws-appsync/test/integ.auth-apikey.expected.json @@ -17,7 +17,7 @@ ] }, "Description": "Default API Key created by CDK", - "Expires": 1595518602 + "Expires": 1626566400 } }, "ApiSchema510EECD7": { diff --git a/packages/@aws-cdk/aws-appsync/test/integ.auth-apikey.ts b/packages/@aws-cdk/aws-appsync/test/integ.auth-apikey.ts index 934848b954be7..acd2cf6095765 100644 --- a/packages/@aws-cdk/aws-appsync/test/integ.auth-apikey.ts +++ b/packages/@aws-cdk/aws-appsync/test/integ.auth-apikey.ts @@ -1,6 +1,6 @@ import { join } from 'path'; import { AttributeType, BillingMode, Table } from '@aws-cdk/aws-dynamodb'; -import { App, RemovalPolicy, Stack, Expires, Duration } from '@aws-cdk/core'; +import { App, RemovalPolicy, Stack, Expires } from '@aws-cdk/core'; import { AuthorizationType, GraphQLApi, @@ -33,7 +33,8 @@ const api = new GraphQLApi(stack, 'Api', { defaultAuthorization: { authorizationType: AuthorizationType.API_KEY, apiKeyConfig: { - expires: Expires.after(Duration.days(2)), + // Generate a timestamp that's 365 days ahead, use atTimestamp so integ test doesn't fail + expires: Expires.atTimestamp(1626609600000), }, }, }, From 25dc05f6ed0a97f350904f22a90f0ce33f51a4a8 Mon Sep 17 00:00:00 2001 From: Bryan Pan Date: Tue, 28 Jul 2020 12:32:31 -0700 Subject: [PATCH 07/21] move utility to core --- .../@aws-cdk/aws-appsync/lib/graphqlapi.ts | 11 ++- .../aws-appsync/test/appsync-auth.test.ts | 10 ++- .../aws-appsync/test/integ.auth-apikey.ts | 13 ++-- .../lib/bucket-deployment.ts | 33 ++++++++- .../test/bucket-deployment.test.ts | 10 +-- packages/@aws-cdk/core/lib/expiration.ts | 69 +++++++++++++++++++ packages/@aws-cdk/core/lib/expires.ts | 47 ------------- packages/@aws-cdk/core/lib/index.ts | 2 +- .../@aws-cdk/core/test/test.expiration.ts | 29 ++++++++ packages/@aws-cdk/core/test/test.expires.ts | 29 -------- 10 files changed, 148 insertions(+), 105 deletions(-) create mode 100644 packages/@aws-cdk/core/lib/expiration.ts delete mode 100644 packages/@aws-cdk/core/lib/expires.ts create mode 100644 packages/@aws-cdk/core/test/test.expiration.ts delete mode 100644 packages/@aws-cdk/core/test/test.expires.ts diff --git a/packages/@aws-cdk/aws-appsync/lib/graphqlapi.ts b/packages/@aws-cdk/aws-appsync/lib/graphqlapi.ts index 3eb8df73f67ec..3a07de40fc401 100644 --- a/packages/@aws-cdk/aws-appsync/lib/graphqlapi.ts +++ b/packages/@aws-cdk/aws-appsync/lib/graphqlapi.ts @@ -7,7 +7,7 @@ import { ServicePrincipal, } from '@aws-cdk/aws-iam'; import { IFunction } from '@aws-cdk/aws-lambda'; -import { Construct, Duration, Expires, IResolvable } from '@aws-cdk/core'; +import { Construct, Duration, Expiration, IResolvable } from '@aws-cdk/core'; import { CfnApiKey, CfnGraphQLApi, @@ -124,7 +124,7 @@ export interface ApiKeyConfig { * * @default - 7 days rounded down to nearest hour */ - readonly expires?: Expires; + readonly expires?: Expiration; } /** @@ -520,13 +520,10 @@ export class GraphQLApi extends Construct { } private createAPIKey(config: ApiKeyConfig): string { - if (config.expires && - (config.expires?.date < Expires.after(Duration.days(1)).date - || config.expires?.date > Expires.after(Duration.days(365)).date)) { + if (config.expires?.lessThan(Duration.days(1)) || config.expires?.greaterThan(Duration.days(365))) { throw Error('API key expiration must be between 1 and 365 days.'); } - const getEpoch = (d: Expires) => { return Math.floor( d.date.getTime() / 86400000) * 86400; }; - const expires = config.expires ? getEpoch(config.expires) : undefined; + const expires = config.expires ? config.expires.asEpoch() : undefined; const key = new CfnApiKey(this, `${config.name || 'DefaultAPIKey'}ApiKey`, { expires, description: config.description || 'Default API Key created by CDK', diff --git a/packages/@aws-cdk/aws-appsync/test/appsync-auth.test.ts b/packages/@aws-cdk/aws-appsync/test/appsync-auth.test.ts index 2144e05c97330..574b70df1b43b 100644 --- a/packages/@aws-cdk/aws-appsync/test/appsync-auth.test.ts +++ b/packages/@aws-cdk/aws-appsync/test/appsync-auth.test.ts @@ -9,8 +9,6 @@ beforeEach(() => { stack = new cdk.Stack(); }); -const getEpoch = (d: cdk.Expires) => { return Math.floor( d.date.getTime()/ 86400000) * 86400; }; - describe('AuthorizationType ApiKey', () => { test('apiKeyConfig creates default description and no expire field', () => { @@ -33,7 +31,7 @@ describe('AuthorizationType ApiKey', () => { }); test('apiKeyConfig creates default description and valid expiration date', () => { - const expirationDate: number = getEpoch(cdk.Expires.after(cdk.Duration.days(10))); + const expirationDate: number = cdk.Expiration.after(cdk.Duration.days(10)).asEpoch(); // WHEN new appsync.GraphQLApi(stack, 'API', { @@ -43,7 +41,7 @@ describe('AuthorizationType ApiKey', () => { defaultAuthorization: { authorizationType: appsync.AuthorizationType.API_KEY, apiKeyConfig: { - expires: cdk.Expires.after(cdk.Duration.days(10)), + expires: cdk.Expiration.after(cdk.Duration.days(10)), }, }, }, @@ -66,7 +64,7 @@ describe('AuthorizationType ApiKey', () => { defaultAuthorization: { authorizationType: appsync.AuthorizationType.API_KEY, apiKeyConfig: { - expires: cdk.Expires.after(cdk.Duration.hours(1)), + expires: cdk.Expiration.after(cdk.Duration.hours(1)), }, }, }, @@ -85,7 +83,7 @@ describe('AuthorizationType ApiKey', () => { defaultAuthorization: { authorizationType: appsync.AuthorizationType.API_KEY, apiKeyConfig: { - expires: cdk.Expires.after(cdk.Duration.days(366)), + expires: cdk.Expiration.after(cdk.Duration.days(366)), }, }, }, diff --git a/packages/@aws-cdk/aws-appsync/test/integ.auth-apikey.ts b/packages/@aws-cdk/aws-appsync/test/integ.auth-apikey.ts index acd2cf6095765..6970ce498be94 100644 --- a/packages/@aws-cdk/aws-appsync/test/integ.auth-apikey.ts +++ b/packages/@aws-cdk/aws-appsync/test/integ.auth-apikey.ts @@ -1,13 +1,8 @@ import { join } from 'path'; import { AttributeType, BillingMode, Table } from '@aws-cdk/aws-dynamodb'; -import { App, RemovalPolicy, Stack, Expires } from '@aws-cdk/core'; -import { - AuthorizationType, - GraphQLApi, - MappingTemplate, - PrimaryKey, - Values, -} from '../lib'; +import { App, RemovalPolicy, Stack, Expiration } from '@aws-cdk/core'; +import { AuthorizationType, GraphQLApi, MappingTemplate, PrimaryKey, Values } from '../lib'; + /* * Creates an Appsync GraphQL API with API_KEY authorization. * Testing for API_KEY Authorization. @@ -34,7 +29,7 @@ const api = new GraphQLApi(stack, 'Api', { authorizationType: AuthorizationType.API_KEY, apiKeyConfig: { // Generate a timestamp that's 365 days ahead, use atTimestamp so integ test doesn't fail - expires: Expires.atTimestamp(1626609600000), + expires: Expiration.atTimestamp(1626566400000), }, }, }, diff --git a/packages/@aws-cdk/aws-s3-deployment/lib/bucket-deployment.ts b/packages/@aws-cdk/aws-s3-deployment/lib/bucket-deployment.ts index a9a53b71899e8..aa9038f3f533b 100644 --- a/packages/@aws-cdk/aws-s3-deployment/lib/bucket-deployment.ts +++ b/packages/@aws-cdk/aws-s3-deployment/lib/bucket-deployment.ts @@ -128,7 +128,7 @@ export interface BucketDeploymentProps { * @default - The objects in the distribution will not expire. * @see https://docs.aws.amazon.com/AmazonS3/latest/dev/UsingMetadata.html#SysMetadata */ - readonly expires?: cdk.Expires; + readonly expires?: cdk.Expiration; /** * System-defined x-amz-server-side-encryption metadata to be set on all objects in the deployment. * @default - Server side encryption is not used. @@ -326,6 +326,37 @@ export enum StorageClass { DEEP_ARCHIVE = 'DEEP_ARCHIVE' } +/** + * Used for HTTP expires header, which influences downstream caches. Does NOT influence deletion of the object. + * @see https://docs.aws.amazon.com/AmazonS3/latest/dev/UsingMetadata.html#SysMetadata + * + * @deprecated use core.Expiration + */ +export class Expires { + /** + * Expire at the specified date + * @param d date to expire at + */ + public static atDate(d: Date) { return new Expires(d.toUTCString()); } + + /** + * Expire at the specified timestamp + * @param t timestamp in unix milliseconds + */ + public static atTimestamp(t: number) { return Expires.atDate(new Date(t)); } + + /** + * Expire once the specified duration has passed since deployment time + * @param t the duration to wait before expiring + */ + public static after(t: cdk.Duration) { return Expires.atDate(new Date(Date.now() + t.toMilliseconds())); } + + public static fromString(s: string) { return new Expires(s); } + + private constructor(public readonly value: any) {} +} + + export interface UserDefinedObjectMetadata { /** * Arbitrary metadata key-values diff --git a/packages/@aws-cdk/aws-s3-deployment/test/bucket-deployment.test.ts b/packages/@aws-cdk/aws-s3-deployment/test/bucket-deployment.test.ts index 5f3e64d5d4b31..f17249918d27f 100644 --- a/packages/@aws-cdk/aws-s3-deployment/test/bucket-deployment.test.ts +++ b/packages/@aws-cdk/aws-s3-deployment/test/bucket-deployment.test.ts @@ -319,7 +319,7 @@ test('system metadata is correctly transformed', () => { serverSideEncryptionCustomerAlgorithm: 'rot13', websiteRedirectLocation: 'example', cacheControl: [s3deploy.CacheControl.setPublic(), s3deploy.CacheControl.maxAge(cdk.Duration.hours(1))], - expires: cdk.Expires.after(cdk.Duration.hours(12)), + expires: cdk.Expiration.after(cdk.Duration.hours(12)), }); // THEN @@ -332,7 +332,7 @@ test('system metadata is correctly transformed', () => { 'sse': 'aws:kms', 'sse-kms-key-id': 'mykey', 'cache-control': 'public, max-age=3600', - 'expires': cdk.Expires.after(cdk.Duration.hours(12)).value, + 'expires': cdk.Expiration.after(cdk.Duration.hours(12)).value, 'sse-c-copy-source': 'rot13', 'website-redirect': 'example', }, @@ -340,10 +340,10 @@ test('system metadata is correctly transformed', () => { }); test('expires type has correct values', () => { - expect(cdk.Expires.atDate(new Date('Sun, 26 Jan 2020 00:53:20 GMT')).value).toEqual('Sun, 26 Jan 2020 00:53:20 GMT'); - expect(cdk.Expires.atTimestamp(1580000000000).value).toEqual('Sun, 26 Jan 2020 00:53:20 GMT'); + expect(cdk.Expiration.atDate(new Date('Sun, 26 Jan 2020 00:53:20 GMT')).value).toEqual('Sun, 26 Jan 2020 00:53:20 GMT'); + expect(cdk.Expiration.atTimestamp(1580000000000).value).toEqual('Sun, 26 Jan 2020 00:53:20 GMT'); expect(Math.abs(new Date(cdk.Expires.after(cdk.Duration.minutes(10)).value).getTime() - (Date.now() + 600000)) < 15000).toBeTruthy(); - expect(cdk.Expires.fromString('Tue, 04 Feb 2020 08:45:33 GMT').value).toEqual('Tue, 04 Feb 2020 08:45:33 GMT'); + expect(cdk.Expiration.fromString('Tue, 04 Feb 2020 08:45:33 GMT').value).toEqual('Tue, 04 Feb 2020 08:45:33 GMT'); }); diff --git a/packages/@aws-cdk/core/lib/expiration.ts b/packages/@aws-cdk/core/lib/expiration.ts new file mode 100644 index 0000000000000..d446b917a892c --- /dev/null +++ b/packages/@aws-cdk/core/lib/expiration.ts @@ -0,0 +1,69 @@ +import { Duration } from './duration'; +/** + * Represents a date of expiration. + * + * The amount can be specified either as a Date object, timestamp, Duration or string. + */ +export class Expiration { + /** + * Expire at the specified date + * @param d date to expire at + */ + public static atDate(d: Date) { return new Expiration(d.toUTCString(), d); } + + /** + * Expire at the specified timestamp + * @param t timestamp in unix milliseconds + */ + public static atTimestamp(t: number) { return Expiration.atDate(new Date(t)); } + + /** + * Expire once the specified duration has passed since deployment time + * @param t the duration to wait before expiring + */ + public static after(t: Duration) { return Expiration.atDate(new Date(Date.now() + t.toMilliseconds())); } + + /** + * Expire at specified date, represented as a string + * + * @param s the string that represents date to expire at + */ + public static fromString(s: string) { return new Expiration(s, new Date(s)); } + + /** + * Expiration value as a string + */ + public readonly value: string; + + /** + * Expiration value as a Date object + */ + public readonly date: Date; + + private constructor(value: string, date: Date) { + this.value = value; + this.date = date; + } + + /** + * Exipration Value in a formatted Unix Epoch Time in seconds + */ + public asEpoch(): number { + return Math.floor( this.date.getTime() / 86400000) * 86400; + } + /** + * Check if Exipiration is less than input + * @param t the duration to check against + */ + public lessThan( t: Duration ): boolean { + return this.date < new Date(Date.now() + t.toMilliseconds()); + } + + /** + * Check if Exipiration is greater than input + * @param t the duration to check against + */ + public greaterThan( t: Duration ): boolean { + return this.date > new Date(Date.now() + t.toMilliseconds()); + } +} \ No newline at end of file diff --git a/packages/@aws-cdk/core/lib/expires.ts b/packages/@aws-cdk/core/lib/expires.ts deleted file mode 100644 index aaa76f541250e..0000000000000 --- a/packages/@aws-cdk/core/lib/expires.ts +++ /dev/null @@ -1,47 +0,0 @@ -import { Duration } from './duration'; -/** - * Represents a date of expiration. - * - * The amount can be specified either as a Date object, timestamp, Duration or string. - */ -export class Expires { - /** - * Expire at the specified date - * @param d date to expire at - */ - public static atDate(d: Date) { return new Expires(d.toUTCString(), d); } - - /** - * Expire at the specified timestamp - * @param t timestamp in unix milliseconds - */ - public static atTimestamp(t: number) { return Expires.atDate(new Date(t)); } - - /** - * Expire once the specified duration has passed since deployment time - * @param t the duration to wait before expiring - */ - public static after(t: Duration) { return Expires.atDate(new Date(Date.now() + t.toMilliseconds())); } - - /** - * Expire at specified date, represented as a string - * - * @param s the string that represents date to expire at - */ - public static fromString(s: string) { return new Expires(s, new Date(s)); } - - /** - * Expiration value as a string - */ - public readonly value: string; - - /** - * Expiration value as a Date object - */ - public readonly date: Date; - - private constructor(value: string, date: Date) { - this.value = value; - this.date = date; - } -} \ No newline at end of file diff --git a/packages/@aws-cdk/core/lib/index.ts b/packages/@aws-cdk/core/lib/index.ts index 6a6a81e25bb49..dede59956ee4e 100644 --- a/packages/@aws-cdk/core/lib/index.ts +++ b/packages/@aws-cdk/core/lib/index.ts @@ -30,7 +30,7 @@ export * from './cfn-json'; export * from './removal-policy'; export * from './arn'; export * from './duration'; -export * from './expires'; +export * from './expiration'; export * from './from-cfn'; export * from './size'; export * from './stack-trace'; diff --git a/packages/@aws-cdk/core/test/test.expiration.ts b/packages/@aws-cdk/core/test/test.expiration.ts new file mode 100644 index 0000000000000..4e8650e1268fb --- /dev/null +++ b/packages/@aws-cdk/core/test/test.expiration.ts @@ -0,0 +1,29 @@ +import * as nodeunit from 'nodeunit'; +import { Duration, Expiration } from '../lib'; + +export = nodeunit.testCase({ + 'from string'(test: nodeunit.Test) { + const date = new Date('Sun, 26 Jan 2020 00:53:20 GMT'); + test.equal(Expiration.fromString('Sun, 26 Jan 2020 00:53:20 GMT').date.getDate(), date.getDate()); + test.done(); + }, + + 'at specified date'(test: nodeunit.Test) { + const date = new Date('Sun, 26 Jan 2020 00:53:20 GMT'); + test.equal(Expiration.atDate(new Date('Sun, 26 Jan 2020 00:53:20 GMT')).value, 'Sun, 26 Jan 2020 00:53:20 GMT'); + test.equal(Expiration.atDate(new Date(1580000000000)).value, 'Sun, 26 Jan 2020 00:53:20 GMT'); + test.equal(Expiration.atDate(new Date(date)).value, 'Sun, 26 Jan 2020 00:53:20 GMT'); + test.done(); + }, + + 'at time stamp'(test: nodeunit.Test) { + test.equal(Expiration.atDate(new Date(1580000000000)).value, 'Sun, 26 Jan 2020 00:53:20 GMT'); + test.done(); + }, + + 'after'(test: nodeunit.Test) { + test.ok(Math.abs(new Date(Expiration.after(Duration.minutes(10)).value).getTime() - (Date.now() + 600000)) < 15000); + test.done(); + }, + +}); diff --git a/packages/@aws-cdk/core/test/test.expires.ts b/packages/@aws-cdk/core/test/test.expires.ts deleted file mode 100644 index 6ff17f69a6441..0000000000000 --- a/packages/@aws-cdk/core/test/test.expires.ts +++ /dev/null @@ -1,29 +0,0 @@ -import * as nodeunit from 'nodeunit'; -import { Duration, Expires } from '../lib'; - -export = nodeunit.testCase({ - 'from string'(test: nodeunit.Test) { - const date = new Date('Sun, 26 Jan 2020 00:53:20 GMT'); - test.equal(Expires.fromString('Sun, 26 Jan 2020 00:53:20 GMT').date.getDate(), date.getDate()); - test.done(); - }, - - 'at specified date'(test: nodeunit.Test) { - const date = new Date('Sun, 26 Jan 2020 00:53:20 GMT'); - test.equal(Expires.atDate(new Date('Sun, 26 Jan 2020 00:53:20 GMT')).value, 'Sun, 26 Jan 2020 00:53:20 GMT'); - test.equal(Expires.atDate(new Date(1580000000000)).value, 'Sun, 26 Jan 2020 00:53:20 GMT'); - test.equal(Expires.atDate(new Date(date)).value, 'Sun, 26 Jan 2020 00:53:20 GMT'); - test.done(); - }, - - 'at time stamp'(test: nodeunit.Test) { - test.equal(Expires.atDate(new Date(1580000000000)).value, 'Sun, 26 Jan 2020 00:53:20 GMT'); - test.done(); - }, - - 'after'(test: nodeunit.Test) { - test.ok(Math.abs(new Date(Expires.after(Duration.minutes(10)).value).getTime() - (Date.now() + 600000)) < 15000); - test.done(); - }, - -}); From 93b26be7d504d491b5b7178c5407e9f11b9157a7 Mon Sep 17 00:00:00 2001 From: Bryan Pan Date: Tue, 28 Jul 2020 12:36:58 -0700 Subject: [PATCH 08/21] linter stop it --- .../lib/bucket-deployment.ts | 43 +++++++++---------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/packages/@aws-cdk/aws-s3-deployment/lib/bucket-deployment.ts b/packages/@aws-cdk/aws-s3-deployment/lib/bucket-deployment.ts index aa9038f3f533b..d659523b44378 100644 --- a/packages/@aws-cdk/aws-s3-deployment/lib/bucket-deployment.ts +++ b/packages/@aws-cdk/aws-s3-deployment/lib/bucket-deployment.ts @@ -333,29 +333,28 @@ export enum StorageClass { * @deprecated use core.Expiration */ export class Expires { - /** - * Expire at the specified date - * @param d date to expire at - */ - public static atDate(d: Date) { return new Expires(d.toUTCString()); } - - /** - * Expire at the specified timestamp - * @param t timestamp in unix milliseconds - */ - public static atTimestamp(t: number) { return Expires.atDate(new Date(t)); } - - /** - * Expire once the specified duration has passed since deployment time - * @param t the duration to wait before expiring - */ - public static after(t: cdk.Duration) { return Expires.atDate(new Date(Date.now() + t.toMilliseconds())); } - - public static fromString(s: string) { return new Expires(s); } - - private constructor(public readonly value: any) {} -} + /** + * Expire at the specified date + * @param d date to expire at + */ + public static atDate(d: Date) { return new Expires(d.toUTCString()); } + + /** + * Expire at the specified timestamp + * @param t timestamp in unix milliseconds + */ + public static atTimestamp(t: number) { return Expires.atDate(new Date(t)); } + /** + * Expire once the specified duration has passed since deployment time + * @param t the duration to wait before expiring + */ + public static after(t: cdk.Duration) { return Expires.atDate(new Date(Date.now() + t.toMilliseconds())); } + + public static fromString(s: string) { return new Expires(s); } + + private constructor(public readonly value: any) {} +} export interface UserDefinedObjectMetadata { /** From 8d7d41513aaa0effe5a34cfba9793367fffd5e5b Mon Sep 17 00:00:00 2001 From: Bryan Pan Date: Tue, 28 Jul 2020 12:38:01 -0700 Subject: [PATCH 09/21] linter fix --- packages/@aws-cdk/aws-s3-deployment/lib/bucket-deployment.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/@aws-cdk/aws-s3-deployment/lib/bucket-deployment.ts b/packages/@aws-cdk/aws-s3-deployment/lib/bucket-deployment.ts index d659523b44378..6eee118a13f40 100644 --- a/packages/@aws-cdk/aws-s3-deployment/lib/bucket-deployment.ts +++ b/packages/@aws-cdk/aws-s3-deployment/lib/bucket-deployment.ts @@ -336,7 +336,7 @@ export class Expires { /** * Expire at the specified date * @param d date to expire at - */ + */ public static atDate(d: Date) { return new Expires(d.toUTCString()); } /** @@ -354,7 +354,7 @@ export class Expires { public static fromString(s: string) { return new Expires(s); } private constructor(public readonly value: any) {} -} +} export interface UserDefinedObjectMetadata { /** From 0b1bf9723903d20a2e7805f4b0e9f84ab76452c3 Mon Sep 17 00:00:00 2001 From: Bryan Pan Date: Tue, 28 Jul 2020 13:03:22 -0700 Subject: [PATCH 10/21] fix bug in s3-deployments --- .../@aws-cdk/aws-s3-deployment/test/bucket-deployment.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@aws-cdk/aws-s3-deployment/test/bucket-deployment.test.ts b/packages/@aws-cdk/aws-s3-deployment/test/bucket-deployment.test.ts index f17249918d27f..54c77ac9f37c3 100644 --- a/packages/@aws-cdk/aws-s3-deployment/test/bucket-deployment.test.ts +++ b/packages/@aws-cdk/aws-s3-deployment/test/bucket-deployment.test.ts @@ -342,7 +342,7 @@ test('system metadata is correctly transformed', () => { test('expires type has correct values', () => { expect(cdk.Expiration.atDate(new Date('Sun, 26 Jan 2020 00:53:20 GMT')).value).toEqual('Sun, 26 Jan 2020 00:53:20 GMT'); expect(cdk.Expiration.atTimestamp(1580000000000).value).toEqual('Sun, 26 Jan 2020 00:53:20 GMT'); - expect(Math.abs(new Date(cdk.Expires.after(cdk.Duration.minutes(10)).value).getTime() - (Date.now() + 600000)) < 15000).toBeTruthy(); + expect(Math.abs(new Date(cdk.Expiration.after(cdk.Duration.minutes(10)).value).getTime() - (Date.now() + 600000)) < 15000).toBeTruthy(); expect(cdk.Expiration.fromString('Tue, 04 Feb 2020 08:45:33 GMT').value).toEqual('Tue, 04 Feb 2020 08:45:33 GMT'); }); From 771ee1c56c1a35ea739aa817e77bdecb92d0d3eb Mon Sep 17 00:00:00 2001 From: Bryan Pan Date: Tue, 28 Jul 2020 13:17:34 -0700 Subject: [PATCH 11/21] lint --- .../@aws-cdk/aws-s3-deployment/lib/bucket-deployment.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/@aws-cdk/aws-s3-deployment/lib/bucket-deployment.ts b/packages/@aws-cdk/aws-s3-deployment/lib/bucket-deployment.ts index 6eee118a13f40..02824e50ec867 100644 --- a/packages/@aws-cdk/aws-s3-deployment/lib/bucket-deployment.ts +++ b/packages/@aws-cdk/aws-s3-deployment/lib/bucket-deployment.ts @@ -326,12 +326,12 @@ export enum StorageClass { DEEP_ARCHIVE = 'DEEP_ARCHIVE' } -/** - * Used for HTTP expires header, which influences downstream caches. Does NOT influence deletion of the object. - * @see https://docs.aws.amazon.com/AmazonS3/latest/dev/UsingMetadata.html#SysMetadata +/** + * Used for HTTP expires header, which influences downstream caches. Does NOT influence deletion of the object. + * @see https://docs.aws.amazon.com/AmazonS3/latest/dev/UsingMetadata.html#SysMetadata * * @deprecated use core.Expiration - */ + */ export class Expires { /** * Expire at the specified date From 2f3f29dda2d510efd95a28f95f8ec5cf6014fcd9 Mon Sep 17 00:00:00 2001 From: Bryan Pan Date: Tue, 28 Jul 2020 16:25:27 -0700 Subject: [PATCH 12/21] change less/greaterThan to isBefore/After --- .../@aws-cdk/aws-appsync/lib/graphqlapi.ts | 2 +- packages/@aws-cdk/core/lib/expiration.ts | 8 ++++---- .../@aws-cdk/core/test/test.expiration.ts | 20 +++++++++++++++++++ 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/packages/@aws-cdk/aws-appsync/lib/graphqlapi.ts b/packages/@aws-cdk/aws-appsync/lib/graphqlapi.ts index 148cf34e4a7db..76a50bb81da9b 100644 --- a/packages/@aws-cdk/aws-appsync/lib/graphqlapi.ts +++ b/packages/@aws-cdk/aws-appsync/lib/graphqlapi.ts @@ -621,7 +621,7 @@ export class GraphQLApi extends Construct { } private createAPIKey(config: ApiKeyConfig): string { - if (config.expires?.lessThan(Duration.days(1)) || config.expires?.greaterThan(Duration.days(365))) { + if (config.expires?.isBefore(Duration.days(1)) || config.expires?.isAfter(Duration.days(365))) { throw Error('API key expiration must be between 1 and 365 days.'); } const expires = config.expires ? config.expires.asEpoch() : undefined; diff --git a/packages/@aws-cdk/core/lib/expiration.ts b/packages/@aws-cdk/core/lib/expiration.ts index d446b917a892c..b4700ee1a584d 100644 --- a/packages/@aws-cdk/core/lib/expiration.ts +++ b/packages/@aws-cdk/core/lib/expiration.ts @@ -52,18 +52,18 @@ export class Expiration { return Math.floor( this.date.getTime() / 86400000) * 86400; } /** - * Check if Exipiration is less than input + * Check if Exipiration expires before input * @param t the duration to check against */ - public lessThan( t: Duration ): boolean { + public isBefore( t: Duration ): boolean { return this.date < new Date(Date.now() + t.toMilliseconds()); } /** - * Check if Exipiration is greater than input + * Check if Exipiration expires after input * @param t the duration to check against */ - public greaterThan( t: Duration ): boolean { + public isAfter( t: Duration ): boolean { return this.date > new Date(Date.now() + t.toMilliseconds()); } } \ No newline at end of file diff --git a/packages/@aws-cdk/core/test/test.expiration.ts b/packages/@aws-cdk/core/test/test.expiration.ts index 4e8650e1268fb..320ec7398dccd 100644 --- a/packages/@aws-cdk/core/test/test.expiration.ts +++ b/packages/@aws-cdk/core/test/test.expiration.ts @@ -26,4 +26,24 @@ export = nodeunit.testCase({ test.done(); }, + 'asEpoch returns correct value'(test: nodeunit.Test) { + const date = new Date('Sun, 26 Jan 2020 00:53:20 GMT'); + test.equal(Expiration.atDate(date).asEpoch(), 1579996800); + test.done(); + }, + + 'isBefore'(test: nodeunit.Test) { + const expire = Expiration.after(Duration.days(2)); + test.ok(!expire.isBefore(Duration.days(1))); + test.ok(expire.isBefore(Duration.days(3))); + test.done(); + }, + + 'isAfter'(test: nodeunit.Test) { + const expire = Expiration.after(Duration.days(2)); + test.ok(expire.isAfter(Duration.days(1))); + test.ok(!expire.isAfter(Duration.days(3))); + test.done(); + }, + }); From 70245f3a4715356a450151df57ba453cede6abeb Mon Sep 17 00:00:00 2001 From: Bryan Pan Date: Fri, 7 Aug 2020 10:11:12 -0700 Subject: [PATCH 13/21] clean up asEpoch --- packages/@aws-cdk/core/lib/expiration.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@aws-cdk/core/lib/expiration.ts b/packages/@aws-cdk/core/lib/expiration.ts index b4700ee1a584d..d80923ab72b26 100644 --- a/packages/@aws-cdk/core/lib/expiration.ts +++ b/packages/@aws-cdk/core/lib/expiration.ts @@ -49,7 +49,7 @@ export class Expiration { * Exipration Value in a formatted Unix Epoch Time in seconds */ public asEpoch(): number { - return Math.floor( this.date.getTime() / 86400000) * 86400; + return Math.round( this.date.getTime() / 1000); } /** * Check if Exipiration expires before input From a006853dcae7a5b324656ca35a888441bc783b97 Mon Sep 17 00:00:00 2001 From: Bryan Pan Date: Fri, 7 Aug 2020 11:12:57 -0700 Subject: [PATCH 14/21] update test --- packages/@aws-cdk/core/test/test.expiration.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@aws-cdk/core/test/test.expiration.ts b/packages/@aws-cdk/core/test/test.expiration.ts index 320ec7398dccd..c2795e5a6cb20 100644 --- a/packages/@aws-cdk/core/test/test.expiration.ts +++ b/packages/@aws-cdk/core/test/test.expiration.ts @@ -28,7 +28,7 @@ export = nodeunit.testCase({ 'asEpoch returns correct value'(test: nodeunit.Test) { const date = new Date('Sun, 26 Jan 2020 00:53:20 GMT'); - test.equal(Expiration.atDate(date).asEpoch(), 1579996800); + test.equal(Expiration.atDate(date).asEpoch(), 1580000000); test.done(); }, From 701442448c66d8e540e2b0f4482dc552039f7006 Mon Sep 17 00:00:00 2001 From: Bryan Pan Date: Mon, 17 Aug 2020 11:12:12 -0700 Subject: [PATCH 15/21] fix build --- packages/@aws-cdk/core/lib/index.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/@aws-cdk/core/lib/index.ts b/packages/@aws-cdk/core/lib/index.ts index dede59956ee4e..1c8a73af0e9a5 100644 --- a/packages/@aws-cdk/core/lib/index.ts +++ b/packages/@aws-cdk/core/lib/index.ts @@ -31,7 +31,6 @@ export * from './removal-policy'; export * from './arn'; export * from './duration'; export * from './expiration'; -export * from './from-cfn'; export * from './size'; export * from './stack-trace'; From 52bb9943eef05dee06cd3bfb616206445c1577c2 Mon Sep 17 00:00:00 2001 From: Bryan Pan Date: Mon, 17 Aug 2020 14:08:31 -0700 Subject: [PATCH 16/21] fix breaking changes --- .../@aws-cdk/aws-appsync/lib/graphqlapi.ts | 2 +- .../aws-appsync/test/appsync-auth.test.ts | 8 +++++-- .../test/integ.auth-apikey.expected.json | 21 +++++++++---------- .../aws-appsync/test/integ.auth-apikey.ts | 5 +++-- 4 files changed, 20 insertions(+), 16 deletions(-) diff --git a/packages/@aws-cdk/aws-appsync/lib/graphqlapi.ts b/packages/@aws-cdk/aws-appsync/lib/graphqlapi.ts index e42ebf3b86ba7..ec9f88f75ff06 100644 --- a/packages/@aws-cdk/aws-appsync/lib/graphqlapi.ts +++ b/packages/@aws-cdk/aws-appsync/lib/graphqlapi.ts @@ -1,7 +1,7 @@ import { readFileSync } from 'fs'; import { IUserPool } from '@aws-cdk/aws-cognito'; import { ManagedPolicy, Role, ServicePrincipal, Grant, IGrantable } from '@aws-cdk/aws-iam'; -import { CfnResource, Construct, Duration, IResolvable, Stack } from '@aws-cdk/core'; +import { CfnResource, Construct, Duration, Expiration, IResolvable, Stack } from '@aws-cdk/core'; import { CfnApiKey, CfnGraphQLApi, CfnGraphQLSchema } from './appsync.generated'; import { IGraphqlApi, GraphqlApiBase } from './graphqlapi-base'; import { ObjectType, ObjectTypeProps } from './schema-types'; diff --git a/packages/@aws-cdk/aws-appsync/test/appsync-auth.test.ts b/packages/@aws-cdk/aws-appsync/test/appsync-auth.test.ts index 574b70df1b43b..fed1979337fd0 100644 --- a/packages/@aws-cdk/aws-appsync/test/appsync-auth.test.ts +++ b/packages/@aws-cdk/aws-appsync/test/appsync-auth.test.ts @@ -15,6 +15,7 @@ describe('AuthorizationType ApiKey', () => { // WHEN new appsync.GraphQLApi(stack, 'API', { name: 'apiKeyUnitTest', + schemaDefinition: appsync.SchemaDefinition.FILE, schemaDefinitionFile: join(__dirname, 'appsync.auth.graphql'), authorizationConfig: { defaultAuthorization: { @@ -25,7 +26,7 @@ describe('AuthorizationType ApiKey', () => { // THEN expect(stack).toHaveResource('AWS::AppSync::ApiKey', { - ApiId: { 'Fn::GetAtt': ['API62EA1CFF', 'ApiId' ] }, + ApiId: { 'Fn::GetAtt': ['API62EA1CFF', 'ApiId'] }, Description: 'Default API Key created by CDK', }); }); @@ -36,6 +37,7 @@ describe('AuthorizationType ApiKey', () => { // WHEN new appsync.GraphQLApi(stack, 'API', { name: 'apiKeyUnitTest', + schemaDefinition: appsync.SchemaDefinition.FILE, schemaDefinitionFile: join(__dirname, 'appsync.auth.graphql'), authorizationConfig: { defaultAuthorization: { @@ -49,7 +51,7 @@ describe('AuthorizationType ApiKey', () => { // THEN expect(stack).toHaveResourceLike('AWS::AppSync::ApiKey', { - ApiId: { 'Fn::GetAtt': ['API62EA1CFF', 'ApiId' ] }, + ApiId: { 'Fn::GetAtt': ['API62EA1CFF', 'ApiId'] }, Description: 'Default API Key created by CDK', Expires: expirationDate, }); @@ -59,6 +61,7 @@ describe('AuthorizationType ApiKey', () => { // WHEN const when = () => { new appsync.GraphQLApi(stack, 'API', { name: 'apiKeyUnitTest', + schemaDefinition: appsync.SchemaDefinition.FILE, schemaDefinitionFile: join(__dirname, 'appsync.auth.graphql'), authorizationConfig: { defaultAuthorization: { @@ -78,6 +81,7 @@ describe('AuthorizationType ApiKey', () => { // WHEN const when = () => {new appsync.GraphQLApi(stack, 'API', { name: 'apiKeyUnitTest', + schemaDefinition: appsync.SchemaDefinition.FILE, schemaDefinitionFile: join(__dirname, 'appsync.auth.graphql'), authorizationConfig: { defaultAuthorization: { diff --git a/packages/@aws-cdk/aws-appsync/test/integ.auth-apikey.expected.json b/packages/@aws-cdk/aws-appsync/test/integ.auth-apikey.expected.json index b23167154c743..9c72b87a76309 100644 --- a/packages/@aws-cdk/aws-appsync/test/integ.auth-apikey.expected.json +++ b/packages/@aws-cdk/aws-appsync/test/integ.auth-apikey.expected.json @@ -32,7 +32,7 @@ "Definition": "type test {\n id: Int!\n version: String!\n}\n\ntype Query {\n getTests: [ test! ]\n}\n\ntype Mutation {\n addTest(version: String!): test!\n}" } }, - "ApitestDataSourceDSServiceRoleE543E310": { + "ApitestDataSourceServiceRoleACBC3F3D": { "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { @@ -49,7 +49,7 @@ } } }, - "ApitestDataSourceDSServiceRoleDefaultPolicy53D2252C": { + "ApitestDataSourceServiceRoleDefaultPolicy897CD912": { "Type": "AWS::IAM::Policy", "Properties": { "PolicyDocument": { @@ -83,15 +83,15 @@ ], "Version": "2012-10-17" }, - "PolicyName": "ApitestDataSourceDSServiceRoleDefaultPolicy53D2252C", + "PolicyName": "ApitestDataSourceServiceRoleDefaultPolicy897CD912", "Roles": [ { - "Ref": "ApitestDataSourceDSServiceRoleE543E310" + "Ref": "ApitestDataSourceServiceRoleACBC3F3D" } ] } }, - "ApitestDataSourceDS776EA507": { + "ApitestDataSource96AE54D5": { "Type": "AWS::AppSync::DataSource", "Properties": { "ApiId": { @@ -102,7 +102,6 @@ }, "Name": "testDataSource", "Type": "AMAZON_DYNAMODB", - "Description": "Table for Tests\"", "DynamoDBConfig": { "AwsRegion": { "Ref": "AWS::Region" @@ -113,13 +112,13 @@ }, "ServiceRoleArn": { "Fn::GetAtt": [ - "ApitestDataSourceDSServiceRoleE543E310", + "ApitestDataSourceServiceRoleACBC3F3D", "Arn" ] } } }, - "ApitestDataSourceDSQuerygetTestsResolver61ED88B6": { + "ApitestDataSourceQuerygetTestsResolverA3BBB672": { "Type": "AWS::AppSync::Resolver", "Properties": { "ApiId": { @@ -137,10 +136,10 @@ }, "DependsOn": [ "ApiSchema510EECD7", - "ApitestDataSourceDS776EA507" + "ApitestDataSource96AE54D5" ] }, - "ApitestDataSourceDSMutationaddTestResolver0D3A4591": { + "ApitestDataSourceMutationaddTestResolver36203D6B": { "Type": "AWS::AppSync::Resolver", "Properties": { "ApiId": { @@ -158,7 +157,7 @@ }, "DependsOn": [ "ApiSchema510EECD7", - "ApitestDataSourceDS776EA507" + "ApitestDataSource96AE54D5" ] }, "TestTable5769773A": { diff --git a/packages/@aws-cdk/aws-appsync/test/integ.auth-apikey.ts b/packages/@aws-cdk/aws-appsync/test/integ.auth-apikey.ts index 6970ce498be94..c3bc157e90b25 100644 --- a/packages/@aws-cdk/aws-appsync/test/integ.auth-apikey.ts +++ b/packages/@aws-cdk/aws-appsync/test/integ.auth-apikey.ts @@ -1,7 +1,7 @@ import { join } from 'path'; import { AttributeType, BillingMode, Table } from '@aws-cdk/aws-dynamodb'; import { App, RemovalPolicy, Stack, Expiration } from '@aws-cdk/core'; -import { AuthorizationType, GraphQLApi, MappingTemplate, PrimaryKey, Values } from '../lib'; +import { AuthorizationType, GraphQLApi, MappingTemplate, PrimaryKey, SchemaDefinition, Values } from '../lib'; /* * Creates an Appsync GraphQL API with API_KEY authorization. @@ -23,6 +23,7 @@ const stack = new Stack(app, 'aws-appsync-integ'); const api = new GraphQLApi(stack, 'Api', { name: 'Integ_Test_APIKey', + schemaDefinition: SchemaDefinition.FILE, schemaDefinitionFile: join(__dirname, 'appsync.auth.graphql'), authorizationConfig: { defaultAuthorization: { @@ -44,7 +45,7 @@ const testTable = new Table(stack, 'TestTable', { removalPolicy: RemovalPolicy.DESTROY, }); -const testDS = api.addDynamoDbDataSource('testDataSource', 'Table for Tests"', testTable); +const testDS = api.addDynamoDbDataSource('testDataSource', testTable); testDS.createResolver({ typeName: 'Query', From b9845face6e38930821b2f0d4b1bf37030da8814 Mon Sep 17 00:00:00 2001 From: Bryan Pan Date: Mon, 31 Aug 2020 09:33:05 -0700 Subject: [PATCH 17/21] fix merge conflicts --- packages/@aws-cdk/aws-appsync/test/appsync-auth.test.ts | 9 +++------ packages/@aws-cdk/aws-appsync/test/integ.auth-apikey.ts | 5 ++--- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/packages/@aws-cdk/aws-appsync/test/appsync-auth.test.ts b/packages/@aws-cdk/aws-appsync/test/appsync-auth.test.ts index 335bb1dda246e..6ba406e37e9bf 100644 --- a/packages/@aws-cdk/aws-appsync/test/appsync-auth.test.ts +++ b/packages/@aws-cdk/aws-appsync/test/appsync-auth.test.ts @@ -94,8 +94,7 @@ describe('AppSync API Key Authorization', () => { // WHEN new appsync.GraphQLApi(stack, 'API', { name: 'apiKeyUnitTest', - schemaDefinition: appsync.SchemaDefinition.FILE, - schemaDefinitionFile: path.join(__dirname, 'appsync.auth.graphql'), + schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.auth.graphql')), authorizationConfig: { defaultAuthorization: { authorizationType: appsync.AuthorizationType.API_KEY, @@ -117,8 +116,7 @@ describe('AppSync API Key Authorization', () => { const when = () => { new appsync.GraphQLApi(stack, 'API', { name: 'apiKeyUnitTest', - schemaDefinition: appsync.SchemaDefinition.FILE, - schemaDefinitionFile: path.join(__dirname, 'appsync.auth.graphql'), + schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.auth.graphql')), authorizationConfig: { defaultAuthorization: { authorizationType: appsync.AuthorizationType.API_KEY, @@ -139,8 +137,7 @@ describe('AppSync API Key Authorization', () => { const when = () => { new appsync.GraphQLApi(stack, 'API', { name: 'apiKeyUnitTest', - schemaDefinition: appsync.SchemaDefinition.FILE, - schemaDefinitionFile: path.join(__dirname, 'appsync.auth.graphql'), + schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.auth.graphql')), authorizationConfig: { defaultAuthorization: { authorizationType: appsync.AuthorizationType.API_KEY, diff --git a/packages/@aws-cdk/aws-appsync/test/integ.auth-apikey.ts b/packages/@aws-cdk/aws-appsync/test/integ.auth-apikey.ts index c3bc157e90b25..eec4cec5ed7cf 100644 --- a/packages/@aws-cdk/aws-appsync/test/integ.auth-apikey.ts +++ b/packages/@aws-cdk/aws-appsync/test/integ.auth-apikey.ts @@ -1,7 +1,7 @@ import { join } from 'path'; import { AttributeType, BillingMode, Table } from '@aws-cdk/aws-dynamodb'; import { App, RemovalPolicy, Stack, Expiration } from '@aws-cdk/core'; -import { AuthorizationType, GraphQLApi, MappingTemplate, PrimaryKey, SchemaDefinition, Values } from '../lib'; +import { AuthorizationType, GraphQLApi, MappingTemplate, PrimaryKey, Schema, Values } from '../lib'; /* * Creates an Appsync GraphQL API with API_KEY authorization. @@ -23,8 +23,7 @@ const stack = new Stack(app, 'aws-appsync-integ'); const api = new GraphQLApi(stack, 'Api', { name: 'Integ_Test_APIKey', - schemaDefinition: SchemaDefinition.FILE, - schemaDefinitionFile: join(__dirname, 'appsync.auth.graphql'), + schema: Schema.fromAsset(join(__dirname, 'appsync.auth.graphql')), authorizationConfig: { defaultAuthorization: { authorizationType: AuthorizationType.API_KEY, From f3c77e35237abb980e50ab300fb39eb72a1f3934 Mon Sep 17 00:00:00 2001 From: Bryan Pan Date: Mon, 31 Aug 2020 14:56:35 -0700 Subject: [PATCH 18/21] refactor(appsync): graphQLApi to graphqlApi for better snakecasing --- .../@aws-cdk/aws-appsync/lib/graphqlapi.ts | 14 +++--- packages/@aws-cdk/aws-appsync/lib/schema.ts | 4 +- packages/@aws-cdk/aws-appsync/package.json | 3 +- .../aws-appsync/test/appsync-auth.test.ts | 46 +++++++++---------- .../test/appsync-code-first.test.ts | 16 +++---- .../aws-appsync/test/appsync-dynamodb.test.ts | 10 ++-- .../aws-appsync/test/appsync-grant.test.ts | 4 +- .../aws-appsync/test/appsync-http.test.ts | 10 ++-- .../test/appsync-interface-type.test.ts | 4 +- .../aws-appsync/test/appsync-lambda.test.ts | 10 ++-- .../aws-appsync/test/appsync-none.test.ts | 10 ++-- .../test/appsync-object-type.test.ts | 4 +- .../test/appsync-scalar-type.test.ts | 4 +- .../aws-appsync/test/appsync-schema.test.ts | 24 +++++----- .../@aws-cdk/aws-appsync/test/appsync.test.ts | 6 +-- .../aws-appsync/test/integ.api-import.ts | 8 ++-- .../aws-appsync/test/integ.graphql-iam.ts | 8 ++-- .../aws-appsync/test/integ.graphql-schema.ts | 2 +- .../aws-appsync/test/integ.graphql.ts | 4 +- 19 files changed, 95 insertions(+), 96 deletions(-) diff --git a/packages/@aws-cdk/aws-appsync/lib/graphqlapi.ts b/packages/@aws-cdk/aws-appsync/lib/graphqlapi.ts index 4251336f017ea..052e3ecd53392 100644 --- a/packages/@aws-cdk/aws-appsync/lib/graphqlapi.ts +++ b/packages/@aws-cdk/aws-appsync/lib/graphqlapi.ts @@ -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 */ @@ -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}`, @@ -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 * @@ -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 @@ -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 ?? @@ -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); diff --git a/packages/@aws-cdk/aws-appsync/lib/schema.ts b/packages/@aws-cdk/aws-appsync/lib/schema.ts index f7751f38a3182..0efb28074fc27 100644 --- a/packages/@aws-cdk/aws-appsync/lib/schema.ts +++ b/packages/@aws-cdk/aws-appsync/lib/schema.ts @@ -1,7 +1,7 @@ import { readFileSync } from 'fs'; import { Lazy } from '@aws-cdk/core'; import { CfnGraphQLSchema } from './appsync.generated'; -import { GraphQLApi } from './graphqlapi'; +import { GraphqlApi } from './graphqlapi'; import { SchemaMode, shapeAddition } from './private'; import { IIntermediateType } from './schema-base'; import { ResolvableField } from './schema-field'; @@ -72,7 +72,7 @@ export class Schema { * * @param api The binding GraphQL Api */ - public bind(api: GraphQLApi): CfnGraphQLSchema { + public bind(api: GraphqlApi): CfnGraphQLSchema { if (!this.schema) { this.schema = new CfnGraphQLSchema(api, 'Schema', { apiId: api.apiId, diff --git a/packages/@aws-cdk/aws-appsync/package.json b/packages/@aws-cdk/aws-appsync/package.json index 7c38409b37325..6726dc41c43a4 100644 --- a/packages/@aws-cdk/aws-appsync/package.json +++ b/packages/@aws-cdk/aws-appsync/package.json @@ -98,8 +98,7 @@ "no-unused-type:@aws-cdk/aws-appsync.ApiKeyConfig", "no-unused-type:@aws-cdk/aws-appsync.UserPoolConfig", "no-unused-type:@aws-cdk/aws-appsync.UserPoolDefaultAction", - "props-physical-name:@aws-cdk/aws-appsync.GraphQLApiProps", - "from-method:@aws-cdk/aws-appsync.GraphQLApi" + "props-physical-name:@aws-cdk/aws-appsync.GraphqlApiProps" ] }, "stability": "experimental", diff --git a/packages/@aws-cdk/aws-appsync/test/appsync-auth.test.ts b/packages/@aws-cdk/aws-appsync/test/appsync-auth.test.ts index fabde1d59c95e..5815908198feb 100644 --- a/packages/@aws-cdk/aws-appsync/test/appsync-auth.test.ts +++ b/packages/@aws-cdk/aws-appsync/test/appsync-auth.test.ts @@ -13,7 +13,7 @@ beforeEach(() => { describe('AppSync API Key Authorization', () => { test('AppSync creates default api key', () => { // WHEN - new appsync.GraphQLApi(stack, 'api', { + new appsync.GraphqlApi(stack, 'api', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), }); @@ -24,7 +24,7 @@ describe('AppSync API Key Authorization', () => { test('AppSync creates api key from additionalAuthorizationModes', () => { // WHEN - new appsync.GraphQLApi(stack, 'api', { + new appsync.GraphqlApi(stack, 'api', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), authorizationConfig: { @@ -41,7 +41,7 @@ describe('AppSync API Key Authorization', () => { test('AppSync does not create unspecified api key from additionalAuthorizationModes', () => { // WHEN - new appsync.GraphQLApi(stack, 'api', { + new appsync.GraphqlApi(stack, 'api', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), authorizationConfig: { @@ -55,7 +55,7 @@ describe('AppSync API Key Authorization', () => { test('appsync does not create unspecified api key with empty additionalAuthorizationModes', () => { // WHEN - new appsync.GraphQLApi(stack, 'api', { + new appsync.GraphqlApi(stack, 'api', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), authorizationConfig: { @@ -70,7 +70,7 @@ describe('AppSync API Key Authorization', () => { test('appsync creates configured api key with additionalAuthorizationModes', () => { // WHEN - new appsync.GraphQLApi(stack, 'api', { + new appsync.GraphqlApi(stack, 'api', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), authorizationConfig: { @@ -90,7 +90,7 @@ describe('AppSync API Key Authorization', () => { test('appsync creates configured api key with additionalAuthorizationModes (not as first element)', () => { // WHEN - new appsync.GraphQLApi(stack, 'api', { + new appsync.GraphqlApi(stack, 'api', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), authorizationConfig: { @@ -117,7 +117,7 @@ describe('AppSync API Key Authorization', () => { test('appsync fails when empty default and API_KEY in additional', () => { // THEN expect(() => { - new appsync.GraphQLApi(stack, 'api', { + new appsync.GraphqlApi(stack, 'api', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), authorizationConfig: { @@ -132,7 +132,7 @@ describe('AppSync API Key Authorization', () => { test('appsync fails when multiple API_KEY auth modes', () => { // THEN expect(() => { - new appsync.GraphQLApi(stack, 'api', { + new appsync.GraphqlApi(stack, 'api', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), authorizationConfig: { @@ -148,7 +148,7 @@ describe('AppSync API Key Authorization', () => { test('appsync fails when multiple API_KEY auth modes in additionalXxx', () => { // THEN expect(() => { - new appsync.GraphQLApi(stack, 'api', { + new appsync.GraphqlApi(stack, 'api', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), authorizationConfig: { @@ -166,7 +166,7 @@ describe('AppSync API Key Authorization', () => { describe('AppSync IAM Authorization', () => { test('Iam authorization configurable in default authorization', () => { // WHEN - new appsync.GraphQLApi(stack, 'api', { + new appsync.GraphqlApi(stack, 'api', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), authorizationConfig: { @@ -182,7 +182,7 @@ describe('AppSync IAM Authorization', () => { test('Iam authorization configurable in additional authorization', () => { // WHEN - new appsync.GraphQLApi(stack, 'api', { + new appsync.GraphqlApi(stack, 'api', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), authorizationConfig: { @@ -199,7 +199,7 @@ describe('AppSync IAM Authorization', () => { test('appsync fails when multiple iam auth modes', () => { // THEN expect(() => { - new appsync.GraphQLApi(stack, 'api', { + new appsync.GraphqlApi(stack, 'api', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), authorizationConfig: { @@ -213,7 +213,7 @@ describe('AppSync IAM Authorization', () => { test('appsync fails when multiple IAM auth modes in additionalXxx', () => { // THEN expect(() => { - new appsync.GraphQLApi(stack, 'api', { + new appsync.GraphqlApi(stack, 'api', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), authorizationConfig: { @@ -234,7 +234,7 @@ describe('AppSync User Pool Authorization', () => { }); test('User Pool authorization configurable in default authorization has default configuration', () => { // WHEN - new appsync.GraphQLApi(stack, 'api', { + new appsync.GraphqlApi(stack, 'api', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), authorizationConfig: { @@ -258,7 +258,7 @@ describe('AppSync User Pool Authorization', () => { test('User Pool authorization configurable in default authorization', () => { // WHEN - new appsync.GraphQLApi(stack, 'api', { + new appsync.GraphqlApi(stack, 'api', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), authorizationConfig: { @@ -287,7 +287,7 @@ describe('AppSync User Pool Authorization', () => { test('User Pool authorization configurable in additional authorization has default configuration', () => { // WHEN - new appsync.GraphQLApi(stack, 'api', { + new appsync.GraphqlApi(stack, 'api', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), authorizationConfig: { @@ -312,7 +312,7 @@ describe('AppSync User Pool Authorization', () => { test('User Pool property defaultAction does not configure when in additional auth', () => { // WHEN - new appsync.GraphQLApi(stack, 'api', { + new appsync.GraphqlApi(stack, 'api', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), authorizationConfig: { @@ -342,7 +342,7 @@ describe('AppSync User Pool Authorization', () => { test('User Pool property defaultAction does not configure when in additional auth', () => { // WHEN - new appsync.GraphQLApi(stack, 'api', { + new appsync.GraphqlApi(stack, 'api', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), authorizationConfig: { @@ -399,7 +399,7 @@ describe('AppSync User Pool Authorization', () => { describe('AppSync OIDC Authorization', () => { test('OIDC authorization configurable in default authorization has default configuration', () => { // WHEN - new appsync.GraphQLApi(stack, 'api', { + new appsync.GraphqlApi(stack, 'api', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), authorizationConfig: { @@ -421,7 +421,7 @@ describe('AppSync OIDC Authorization', () => { test('User Pool authorization configurable in default authorization', () => { // WHEN - new appsync.GraphQLApi(stack, 'api', { + new appsync.GraphqlApi(stack, 'api', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), authorizationConfig: { @@ -451,7 +451,7 @@ describe('AppSync OIDC Authorization', () => { test('OIDC authorization configurable in additional authorization has default configuration', () => { // WHEN - new appsync.GraphQLApi(stack, 'api', { + new appsync.GraphqlApi(stack, 'api', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), authorizationConfig: { @@ -475,7 +475,7 @@ describe('AppSync OIDC Authorization', () => { test('User Pool authorization configurable in additional authorization', () => { // WHEN - new appsync.GraphQLApi(stack, 'api', { + new appsync.GraphqlApi(stack, 'api', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), authorizationConfig: { @@ -507,7 +507,7 @@ describe('AppSync OIDC Authorization', () => { test('User Pool authorization configurable in with multiple authorization', () => { // WHEN - new appsync.GraphQLApi(stack, 'api', { + new appsync.GraphqlApi(stack, 'api', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), authorizationConfig: { diff --git a/packages/@aws-cdk/aws-appsync/test/appsync-code-first.test.ts b/packages/@aws-cdk/aws-appsync/test/appsync-code-first.test.ts index 0b39cab4c4c24..98460fd8be00d 100644 --- a/packages/@aws-cdk/aws-appsync/test/appsync-code-first.test.ts +++ b/packages/@aws-cdk/aws-appsync/test/appsync-code-first.test.ts @@ -10,10 +10,10 @@ beforeEach(() => { }); describe('code-first implementation through GraphQL Api functions`', () => { - let api: appsync.GraphQLApi; + let api: appsync.GraphqlApi; beforeEach(() => { // GIVEN - api = new appsync.GraphQLApi(stack, 'api', { + api = new appsync.GraphqlApi(stack, 'api', { name: 'api', }); }); @@ -164,7 +164,7 @@ describe('code-first implementation through Schema functions`', () => { schema.addType(test); test.addField('dupid', t.dup_id); - new appsync.GraphQLApi(stack, 'api', { + new appsync.GraphqlApi(stack, 'api', { name: 'api', schema, }); @@ -190,7 +190,7 @@ describe('code-first implementation through Schema functions`', () => { schema.addType(test); test.addField('dupid', t.dup_id); - new appsync.GraphQLApi(stack, 'api', { + new appsync.GraphqlApi(stack, 'api', { name: 'api', schema, }); @@ -215,7 +215,7 @@ describe('code-first implementation through Schema functions`', () => { }, })); - new appsync.GraphQLApi(stack, 'api', { + new appsync.GraphqlApi(stack, 'api', { name: 'api', schema, }); @@ -241,7 +241,7 @@ describe('code-first implementation through Schema functions`', () => { })); test.addField('dupid', t.dup_id); - new appsync.GraphQLApi(stack, 'api', { + new appsync.GraphqlApi(stack, 'api', { name: 'api', schema, }); @@ -265,7 +265,7 @@ describe('code-first implementation through Schema functions`', () => { dupid: t.dup_id, }, })); - new appsync.GraphQLApi(stack, 'api', { + new appsync.GraphqlApi(stack, 'api', { name: 'api', schema, }); @@ -290,7 +290,7 @@ describe('code-first implementation through Schema functions`', () => { })); test.addField('dupid', t.dup_id); - new appsync.GraphQLApi(stack, 'api', { + new appsync.GraphqlApi(stack, 'api', { name: 'api', schema, }); diff --git a/packages/@aws-cdk/aws-appsync/test/appsync-dynamodb.test.ts b/packages/@aws-cdk/aws-appsync/test/appsync-dynamodb.test.ts index e54a9576396d1..07565edd1fba5 100644 --- a/packages/@aws-cdk/aws-appsync/test/appsync-dynamodb.test.ts +++ b/packages/@aws-cdk/aws-appsync/test/appsync-dynamodb.test.ts @@ -10,10 +10,10 @@ function joined(str: string): string { // GLOBAL GIVEN let stack: cdk.Stack; -let api: appsync.GraphQLApi; +let api: appsync.GraphqlApi; beforeEach(() => { stack = new cdk.Stack(); - api = new appsync.GraphQLApi(stack, 'baseApi', { + api = new appsync.GraphqlApi(stack, 'baseApi', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), }); @@ -75,7 +75,7 @@ describe('DynamoDb Data Source configuration', () => { expect(() => { api.addDynamoDbDataSource('ds', table); api.addDynamoDbDataSource('ds', table); - }).toThrow("There is already a Construct with name 'ds' in GraphQLApi [baseApi]"); + }).toThrow("There is already a Construct with name 'ds' in GraphqlApi [baseApi]"); }); }); @@ -160,7 +160,7 @@ describe('adding DynamoDb data source from imported api', () => { test('imported api can add DynamoDbDataSource from id', () => { // WHEN - const importedApi = appsync.GraphQLApi.fromGraphqlApiAttributes(stack, 'importedApi', { + const importedApi = appsync.GraphqlApi.fromGraphqlApiAttributes(stack, 'importedApi', { graphqlApiId: api.apiId, }); importedApi.addDynamoDbDataSource('ds', table); @@ -174,7 +174,7 @@ describe('adding DynamoDb data source from imported api', () => { test('imported api can add DynamoDbDataSource from attributes', () => { // WHEN - const importedApi = appsync.GraphQLApi.fromGraphqlApiAttributes(stack, 'importedApi', { + const importedApi = appsync.GraphqlApi.fromGraphqlApiAttributes(stack, 'importedApi', { graphqlApiId: api.apiId, graphqlApiArn: api.arn, }); diff --git a/packages/@aws-cdk/aws-appsync/test/appsync-grant.test.ts b/packages/@aws-cdk/aws-appsync/test/appsync-grant.test.ts index 44251cd7fabee..d59b7c5d363cb 100644 --- a/packages/@aws-cdk/aws-appsync/test/appsync-grant.test.ts +++ b/packages/@aws-cdk/aws-appsync/test/appsync-grant.test.ts @@ -6,14 +6,14 @@ import * as appsync from '../lib'; let stack: cdk.Stack; let role: iam.Role; -let api: appsync.GraphQLApi; +let api: appsync.GraphqlApi; beforeEach(() => { // GIVEN stack = new cdk.Stack(); role = new iam.Role(stack, 'Role', { assumedBy: new iam.ServicePrincipal('lambda.amazonaws.com'), }); - api = new appsync.GraphQLApi(stack, 'API', { + api = new appsync.GraphqlApi(stack, 'API', { name: 'demo', schema: appsync.Schema.fromAsset(join(__dirname, 'appsync.test.graphql')), authorizationConfig: { diff --git a/packages/@aws-cdk/aws-appsync/test/appsync-http.test.ts b/packages/@aws-cdk/aws-appsync/test/appsync-http.test.ts index 899a76ebd19f4..6bc237e0f5c71 100644 --- a/packages/@aws-cdk/aws-appsync/test/appsync-http.test.ts +++ b/packages/@aws-cdk/aws-appsync/test/appsync-http.test.ts @@ -5,11 +5,11 @@ import * as appsync from '../lib'; // GLOBAL GIVEN let stack: cdk.Stack; -let api: appsync.GraphQLApi; +let api: appsync.GraphqlApi; let endpoint: string; beforeEach(() => { stack = new cdk.Stack(); - api = new appsync.GraphQLApi(stack, 'baseApi', { + api = new appsync.GraphqlApi(stack, 'baseApi', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), }); @@ -62,14 +62,14 @@ describe('Http Data Source configuration', () => { expect(() => { api.addHttpDataSource('ds', endpoint); api.addHttpDataSource('ds', endpoint); - }).toThrow("There is already a Construct with name 'ds' in GraphQLApi [baseApi]"); + }).toThrow("There is already a Construct with name 'ds' in GraphqlApi [baseApi]"); }); }); describe('adding http data source from imported api', () => { test('imported api can add HttpDataSource from id', () => { // WHEN - const importedApi = appsync.GraphQLApi.fromGraphqlApiAttributes(stack, 'importedApi', { + const importedApi = appsync.GraphqlApi.fromGraphqlApiAttributes(stack, 'importedApi', { graphqlApiId: api.apiId, }); importedApi.addHttpDataSource('ds', endpoint); @@ -83,7 +83,7 @@ describe('adding http data source from imported api', () => { test('imported api can add HttpDataSource from attributes', () => { // WHEN - const importedApi = appsync.GraphQLApi.fromGraphqlApiAttributes(stack, 'importedApi', { + const importedApi = appsync.GraphqlApi.fromGraphqlApiAttributes(stack, 'importedApi', { graphqlApiId: api.apiId, graphqlApiArn: api.arn, }); diff --git a/packages/@aws-cdk/aws-appsync/test/appsync-interface-type.test.ts b/packages/@aws-cdk/aws-appsync/test/appsync-interface-type.test.ts index 981ec8b60a039..644e7fae42354 100644 --- a/packages/@aws-cdk/aws-appsync/test/appsync-interface-type.test.ts +++ b/packages/@aws-cdk/aws-appsync/test/appsync-interface-type.test.ts @@ -4,11 +4,11 @@ import * as appsync from '../lib'; import * as t from './scalar-type-defintions'; let stack: cdk.Stack; -let api: appsync.GraphQLApi; +let api: appsync.GraphqlApi; beforeEach(() => { // GIVEN stack = new cdk.Stack(); - api = new appsync.GraphQLApi(stack, 'api', { + api = new appsync.GraphqlApi(stack, 'api', { name: 'api', }); }); diff --git a/packages/@aws-cdk/aws-appsync/test/appsync-lambda.test.ts b/packages/@aws-cdk/aws-appsync/test/appsync-lambda.test.ts index a67fd4b1691b7..0cc8396382017 100644 --- a/packages/@aws-cdk/aws-appsync/test/appsync-lambda.test.ts +++ b/packages/@aws-cdk/aws-appsync/test/appsync-lambda.test.ts @@ -6,10 +6,10 @@ import * as appsync from '../lib'; // GLOBAL GIVEN let stack: cdk.Stack; -let api: appsync.GraphQLApi; +let api: appsync.GraphqlApi; beforeEach(() => { stack = new cdk.Stack(); - api = new appsync.GraphQLApi(stack, 'baseApi', { + api = new appsync.GraphqlApi(stack, 'baseApi', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), }); @@ -70,7 +70,7 @@ describe('Lambda Data Source configuration', () => { expect(() => { api.addLambdaDataSource('ds', func); api.addLambdaDataSource('ds', func); - }).toThrow("There is already a Construct with name 'ds' in GraphQLApi [baseApi]"); + }).toThrow("There is already a Construct with name 'ds' in GraphqlApi [baseApi]"); }); }); @@ -86,7 +86,7 @@ describe('adding lambda data source from imported api', () => { test('imported api can add LambdaDbDataSource from id', () => { // WHEN - const importedApi = appsync.GraphQLApi.fromGraphqlApiAttributes(stack, 'importedApi', { + const importedApi = appsync.GraphqlApi.fromGraphqlApiAttributes(stack, 'importedApi', { graphqlApiId: api.apiId, }); importedApi.addLambdaDataSource('ds', func); @@ -100,7 +100,7 @@ describe('adding lambda data source from imported api', () => { test('imported api can add LambdaDataSource from attributes', () => { // WHEN - const importedApi = appsync.GraphQLApi.fromGraphqlApiAttributes(stack, 'importedApi', { + const importedApi = appsync.GraphqlApi.fromGraphqlApiAttributes(stack, 'importedApi', { graphqlApiId: api.apiId, graphqlApiArn: api.arn, }); diff --git a/packages/@aws-cdk/aws-appsync/test/appsync-none.test.ts b/packages/@aws-cdk/aws-appsync/test/appsync-none.test.ts index f2b52c7dfba03..3985cebc30719 100644 --- a/packages/@aws-cdk/aws-appsync/test/appsync-none.test.ts +++ b/packages/@aws-cdk/aws-appsync/test/appsync-none.test.ts @@ -5,10 +5,10 @@ import * as appsync from '../lib'; // GLOBAL GIVEN let stack: cdk.Stack; -let api: appsync.GraphQLApi; +let api: appsync.GraphqlApi; beforeEach(() => { stack = new cdk.Stack(); - api = new appsync.GraphQLApi(stack, 'baseApi', { + api = new appsync.GraphqlApi(stack, 'baseApi', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), }); @@ -60,7 +60,7 @@ describe('None Data Source configuration', () => { expect(() => { api.addNoneDataSource('ds'); api.addNoneDataSource('ds'); - }).toThrow("There is already a Construct with name 'ds' in GraphQLApi [baseApi]"); + }).toThrow("There is already a Construct with name 'ds' in GraphqlApi [baseApi]"); }); test('appsync errors when creating multiple none data sources with same name configuration', () => { @@ -75,7 +75,7 @@ describe('None Data Source configuration', () => { describe('adding none data source from imported api', () => { test('imported api can add NoneDataSource from id', () => { // WHEN - const importedApi = appsync.GraphQLApi.fromGraphqlApiAttributes(stack, 'importedApi', { + const importedApi = appsync.GraphqlApi.fromGraphqlApiAttributes(stack, 'importedApi', { graphqlApiId: api.apiId, }); importedApi.addNoneDataSource('none'); @@ -89,7 +89,7 @@ describe('adding none data source from imported api', () => { test('imported api can add NoneDataSource from attributes', () => { // WHEN - const importedApi = appsync.GraphQLApi.fromGraphqlApiAttributes(stack, 'importedApi', { + const importedApi = appsync.GraphqlApi.fromGraphqlApiAttributes(stack, 'importedApi', { graphqlApiId: api.apiId, graphqlApiArn: api.arn, }); diff --git a/packages/@aws-cdk/aws-appsync/test/appsync-object-type.test.ts b/packages/@aws-cdk/aws-appsync/test/appsync-object-type.test.ts index a60a5242f6fe7..02f0d9b43ff57 100644 --- a/packages/@aws-cdk/aws-appsync/test/appsync-object-type.test.ts +++ b/packages/@aws-cdk/aws-appsync/test/appsync-object-type.test.ts @@ -4,11 +4,11 @@ import * as appsync from '../lib'; import * as t from './scalar-type-defintions'; let stack: cdk.Stack; -let api: appsync.GraphQLApi; +let api: appsync.GraphqlApi; beforeEach(() => { // GIVEN stack = new cdk.Stack(); - api = new appsync.GraphQLApi(stack, 'api', { + api = new appsync.GraphqlApi(stack, 'api', { name: 'api', }); }); diff --git a/packages/@aws-cdk/aws-appsync/test/appsync-scalar-type.test.ts b/packages/@aws-cdk/aws-appsync/test/appsync-scalar-type.test.ts index 64fddd55bc3d3..312d7a3784b98 100644 --- a/packages/@aws-cdk/aws-appsync/test/appsync-scalar-type.test.ts +++ b/packages/@aws-cdk/aws-appsync/test/appsync-scalar-type.test.ts @@ -4,11 +4,11 @@ import * as appsync from '../lib'; import * as t from './scalar-type-defintions'; let stack: cdk.Stack; -let api: appsync.GraphQLApi; +let api: appsync.GraphqlApi; beforeEach(() => { // GIVEN stack = new cdk.Stack(); - api = new appsync.GraphQLApi(stack, 'api', { + api = new appsync.GraphqlApi(stack, 'api', { name: 'api', }); }); diff --git a/packages/@aws-cdk/aws-appsync/test/appsync-schema.test.ts b/packages/@aws-cdk/aws-appsync/test/appsync-schema.test.ts index f60d63f1dec5c..95fe1ac7c500a 100644 --- a/packages/@aws-cdk/aws-appsync/test/appsync-schema.test.ts +++ b/packages/@aws-cdk/aws-appsync/test/appsync-schema.test.ts @@ -36,7 +36,7 @@ describe('basic testing schema definition mode `code`', () => { test('definition mode `code` produces empty schema definition', () => { // WHEN - new appsync.GraphQLApi(stack, 'API', { + new appsync.GraphqlApi(stack, 'API', { name: 'demo', }); @@ -48,7 +48,7 @@ describe('basic testing schema definition mode `code`', () => { test('definition mode `code` generates correct schema with addToSchema', () => { // WHEN - const api = new appsync.GraphQLApi(stack, 'API', { + const api = new appsync.GraphqlApi(stack, 'API', { name: 'demo', }); api.addType(type); @@ -63,7 +63,7 @@ describe('basic testing schema definition mode `code`', () => { test('definition mode `code` allows for api to addQuery', () => { // WHEN - const api = new appsync.GraphQLApi(stack, 'API', { + const api = new appsync.GraphqlApi(stack, 'API', { name: 'demo', }); api.addQuery('test', new appsync.ResolvableField({ @@ -79,7 +79,7 @@ describe('basic testing schema definition mode `code`', () => { test('definition mode `code` allows for schema to addQuery', () => { // WHEN const schema = new appsync.Schema(); - new appsync.GraphQLApi(stack, 'API', { + new appsync.GraphqlApi(stack, 'API', { name: 'demo', schema, }); @@ -95,7 +95,7 @@ describe('basic testing schema definition mode `code`', () => { test('definition mode `code` allows for api to addMutation', () => { // WHEN - const api = new appsync.GraphQLApi(stack, 'API', { + const api = new appsync.GraphqlApi(stack, 'API', { name: 'demo', }); api.addMutation('test', new appsync.ResolvableField({ @@ -111,7 +111,7 @@ describe('basic testing schema definition mode `code`', () => { test('definition mode `code` allows for schema to addMutation', () => { // WHEN const schema = new appsync.Schema(); - new appsync.GraphQLApi(stack, 'API', { + new appsync.GraphqlApi(stack, 'API', { name: 'demo', schema, }); @@ -130,7 +130,7 @@ describe('testing schema definition mode `file`', () => { test('definition mode `file` produces correct output', () => { // WHEN - new appsync.GraphQLApi(stack, 'API', { + new appsync.GraphqlApi(stack, 'API', { name: 'demo', schema: appsync.Schema.fromAsset(join(__dirname, 'appsync.test.graphql')), }); @@ -143,7 +143,7 @@ describe('testing schema definition mode `file`', () => { test('definition mode `file` errors when addType for object is called', () => { // WHEN - const api = new appsync.GraphQLApi(stack, 'API', { + const api = new appsync.GraphqlApi(stack, 'API', { name: 'demo', schema: appsync.Schema.fromAsset(join(__dirname, 'appsync.test.graphql')), }); @@ -158,7 +158,7 @@ describe('testing schema definition mode `file`', () => { test('definition mode `file` errors when addType for interface is called', () => { // WHEN - const api = new appsync.GraphQLApi(stack, 'API', { + const api = new appsync.GraphqlApi(stack, 'API', { name: 'demo', schema: appsync.Schema.fromAsset(join(__dirname, 'appsync.test.graphql')), }); @@ -173,7 +173,7 @@ describe('testing schema definition mode `file`', () => { test('definition mode `file` errors when addToSchema is called', () => { // WHEN - const api = new appsync.GraphQLApi(stack, 'API', { + const api = new appsync.GraphqlApi(stack, 'API', { name: 'demo', schema: appsync.Schema.fromAsset(join(__dirname, 'appsync.test.graphql')), }); @@ -186,7 +186,7 @@ describe('testing schema definition mode `file`', () => { test('definition mode `file` errors when addQuery is called', () => { // WHEN - const api = new appsync.GraphQLApi(stack, 'API', { + const api = new appsync.GraphqlApi(stack, 'API', { name: 'demo', schema: appsync.Schema.fromAsset(join(__dirname, 'appsync.test.graphql')), }); @@ -199,7 +199,7 @@ describe('testing schema definition mode `file`', () => { test('definition mode `file` errors when addMutation is called', () => { // WHEN - const api = new appsync.GraphQLApi(stack, 'API', { + const api = new appsync.GraphqlApi(stack, 'API', { name: 'demo', schema: appsync.Schema.fromAsset(join(__dirname, 'appsync.test.graphql')), }); diff --git a/packages/@aws-cdk/aws-appsync/test/appsync.test.ts b/packages/@aws-cdk/aws-appsync/test/appsync.test.ts index 9dc6808a672e1..debdfa71ce4f0 100644 --- a/packages/@aws-cdk/aws-appsync/test/appsync.test.ts +++ b/packages/@aws-cdk/aws-appsync/test/appsync.test.ts @@ -4,10 +4,10 @@ import * as cdk from '@aws-cdk/core'; import * as appsync from '../lib'; let stack: cdk.Stack; -let api: appsync.GraphQLApi; +let api: appsync.GraphqlApi; beforeEach(() => { stack = new cdk.Stack(); - api = new appsync.GraphQLApi(stack, 'api', { + api = new appsync.GraphqlApi(stack, 'api', { authorizationConfig: {}, name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), @@ -61,7 +61,7 @@ test('appsync should configure resolver as unit when pipelineConfig is empty arr test('when xray is enabled should not throw an Error', () => { // WHEN - new appsync.GraphQLApi(stack, 'api-x-ray', { + new appsync.GraphqlApi(stack, 'api-x-ray', { authorizationConfig: {}, name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), diff --git a/packages/@aws-cdk/aws-appsync/test/integ.api-import.ts b/packages/@aws-cdk/aws-appsync/test/integ.api-import.ts index b36c6a1bef7b1..8781f83fe117e 100644 --- a/packages/@aws-cdk/aws-appsync/test/integ.api-import.ts +++ b/packages/@aws-cdk/aws-appsync/test/integ.api-import.ts @@ -11,7 +11,7 @@ import * as appsync from '../lib'; * * Stack verification steps: * Install dependencies and deploy integration test. Check if data sources are - * connected to the graphQL Api + * connected to the GraphQL Api * * -- cdk deploy --app 'node integ.api-import.js' stack -- start -- * -- aws appsync list-graphql-apis -- obtain api id -- @@ -22,13 +22,13 @@ import * as appsync from '../lib'; const app = new cdk.App(); const baseStack = new cdk.Stack(app, 'baseStack'); -const baseApi = new appsync.GraphQLApi(baseStack, 'baseApi', { +const baseApi = new appsync.GraphqlApi(baseStack, 'baseApi', { name: 'baseApi', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), }); const stack = new cdk.Stack(app, 'stack'); -const api = appsync.GraphQLApi.fromGraphqlApiAttributes(stack, 'Api', { +const api = appsync.GraphqlApi.fromGraphqlApiAttributes(stack, 'Api', { graphqlApiId: `${baseApi.apiId}`, }); @@ -57,7 +57,7 @@ testDS.createResolver({ responseMappingTemplate: appsync.MappingTemplate.dynamoDbResultItem(), }); -const api2 = appsync.GraphQLApi.fromGraphqlApiAttributes(stack, 'api2', { +const api2 = appsync.GraphqlApi.fromGraphqlApiAttributes(stack, 'api2', { graphqlApiId: baseApi.apiId, graphqlApiArn: baseApi.arn, }); diff --git a/packages/@aws-cdk/aws-appsync/test/integ.graphql-iam.ts b/packages/@aws-cdk/aws-appsync/test/integ.graphql-iam.ts index 0d4c95a10ea3f..185fc8ef3e729 100644 --- a/packages/@aws-cdk/aws-appsync/test/integ.graphql-iam.ts +++ b/packages/@aws-cdk/aws-appsync/test/integ.graphql-iam.ts @@ -6,7 +6,7 @@ import { Code, Function, Runtime } from '@aws-cdk/aws-lambda'; import { App, RemovalPolicy, Stack } from '@aws-cdk/core'; import { AuthorizationType, - GraphQLApi, + GraphqlApi, MappingTemplate, PrimaryKey, UserPoolDefaultAction, @@ -36,7 +36,7 @@ const userPool = new UserPool(stack, 'Pool', { userPoolName: 'myPool', }); -const api = new GraphQLApi(stack, 'Api', { +const api = new GraphqlApi(stack, 'Api', { name: 'Integ_Test_IAM', schema: Schema.fromAsset(join(__dirname, 'integ.graphql-iam.graphql')), authorizationConfig: { @@ -98,14 +98,14 @@ new Function(stack, 'testQuery', { code: Code.fromAsset('verify'), handler: 'iam-query.handler', runtime: Runtime.NODEJS_12_X, - environment: { APPSYNC_ENDPOINT: api.graphQlUrl }, + environment: { APPSYNC_ENDPOINT: api.graphqlUrl }, role: lambdaIAM, }); new Function(stack, 'testFail', { code: Code.fromAsset('verify'), handler: 'iam-query.handler', runtime: Runtime.NODEJS_12_X, - environment: { APPSYNC_ENDPOINT: api.graphQlUrl }, + environment: { APPSYNC_ENDPOINT: api.graphqlUrl }, }); app.synth(); diff --git a/packages/@aws-cdk/aws-appsync/test/integ.graphql-schema.ts b/packages/@aws-cdk/aws-appsync/test/integ.graphql-schema.ts index 8bde313c6f724..8cb3daafab11a 100644 --- a/packages/@aws-cdk/aws-appsync/test/integ.graphql-schema.ts +++ b/packages/@aws-cdk/aws-appsync/test/integ.graphql-schema.ts @@ -29,7 +29,7 @@ const node = schema.addType(new appsync.InterfaceType('Node', { }, })); -const api = new appsync.GraphQLApi(stack, 'code-first-api', { +const api = new appsync.GraphqlApi(stack, 'code-first-api', { name: 'api', schema: schema, }); diff --git a/packages/@aws-cdk/aws-appsync/test/integ.graphql.ts b/packages/@aws-cdk/aws-appsync/test/integ.graphql.ts index 9882fead1cf12..1de80995c90a0 100644 --- a/packages/@aws-cdk/aws-appsync/test/integ.graphql.ts +++ b/packages/@aws-cdk/aws-appsync/test/integ.graphql.ts @@ -4,7 +4,7 @@ import { AttributeType, BillingMode, Table } from '@aws-cdk/aws-dynamodb'; import { App, RemovalPolicy, Stack } from '@aws-cdk/core'; import { AuthorizationType, - GraphQLApi, + GraphqlApi, KeyCondition, MappingTemplate, PrimaryKey, @@ -33,7 +33,7 @@ const userPool = new UserPool(stack, 'Pool', { userPoolName: 'myPool', }); -const api = new GraphQLApi(stack, 'Api', { +const api = new GraphqlApi(stack, 'Api', { name: 'demoapi', schema: Schema.fromAsset(join(__dirname, 'integ.graphql.graphql')), authorizationConfig: { From 51edc01b01fb75896770ca1d28647f2a12be755f Mon Sep 17 00:00:00 2001 From: Bryan Pan Date: Mon, 31 Aug 2020 15:04:47 -0700 Subject: [PATCH 19/21] Revert "refactor(appsync): graphQLApi to graphqlApi for better snakecasing" This reverts commit f3c77e35237abb980e50ab300fb39eb72a1f3934. --- .../@aws-cdk/aws-appsync/lib/graphqlapi.ts | 14 +++--- packages/@aws-cdk/aws-appsync/lib/schema.ts | 4 +- packages/@aws-cdk/aws-appsync/package.json | 3 +- .../aws-appsync/test/appsync-auth.test.ts | 46 +++++++++---------- .../test/appsync-code-first.test.ts | 16 +++---- .../aws-appsync/test/appsync-dynamodb.test.ts | 10 ++-- .../aws-appsync/test/appsync-grant.test.ts | 4 +- .../aws-appsync/test/appsync-http.test.ts | 10 ++-- .../test/appsync-interface-type.test.ts | 4 +- .../aws-appsync/test/appsync-lambda.test.ts | 10 ++-- .../aws-appsync/test/appsync-none.test.ts | 10 ++-- .../test/appsync-object-type.test.ts | 4 +- .../test/appsync-scalar-type.test.ts | 4 +- .../aws-appsync/test/appsync-schema.test.ts | 24 +++++----- .../@aws-cdk/aws-appsync/test/appsync.test.ts | 6 +-- .../aws-appsync/test/integ.api-import.ts | 8 ++-- .../aws-appsync/test/integ.graphql-iam.ts | 8 ++-- .../aws-appsync/test/integ.graphql-schema.ts | 2 +- .../aws-appsync/test/integ.graphql.ts | 4 +- 19 files changed, 96 insertions(+), 95 deletions(-) diff --git a/packages/@aws-cdk/aws-appsync/lib/graphqlapi.ts b/packages/@aws-cdk/aws-appsync/lib/graphqlapi.ts index 052e3ecd53392..4251336f017ea 100644 --- a/packages/@aws-cdk/aws-appsync/lib/graphqlapi.ts +++ b/packages/@aws-cdk/aws-appsync/lib/graphqlapi.ts @@ -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 */ @@ -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}`, @@ -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 * @@ -362,9 +362,9 @@ export class GraphqlApi extends GraphqlApiBase { /** * the URL of the endpoint created by AppSync * - * @attribute GraphQlUrl + * @attribute */ - public readonly graphqlUrl: string; + public readonly graphQlUrl: string; /** * the name of the API @@ -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 ?? @@ -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); diff --git a/packages/@aws-cdk/aws-appsync/lib/schema.ts b/packages/@aws-cdk/aws-appsync/lib/schema.ts index 0efb28074fc27..f7751f38a3182 100644 --- a/packages/@aws-cdk/aws-appsync/lib/schema.ts +++ b/packages/@aws-cdk/aws-appsync/lib/schema.ts @@ -1,7 +1,7 @@ import { readFileSync } from 'fs'; import { Lazy } from '@aws-cdk/core'; import { CfnGraphQLSchema } from './appsync.generated'; -import { GraphqlApi } from './graphqlapi'; +import { GraphQLApi } from './graphqlapi'; import { SchemaMode, shapeAddition } from './private'; import { IIntermediateType } from './schema-base'; import { ResolvableField } from './schema-field'; @@ -72,7 +72,7 @@ export class Schema { * * @param api The binding GraphQL Api */ - public bind(api: GraphqlApi): CfnGraphQLSchema { + public bind(api: GraphQLApi): CfnGraphQLSchema { if (!this.schema) { this.schema = new CfnGraphQLSchema(api, 'Schema', { apiId: api.apiId, diff --git a/packages/@aws-cdk/aws-appsync/package.json b/packages/@aws-cdk/aws-appsync/package.json index 6726dc41c43a4..7c38409b37325 100644 --- a/packages/@aws-cdk/aws-appsync/package.json +++ b/packages/@aws-cdk/aws-appsync/package.json @@ -98,7 +98,8 @@ "no-unused-type:@aws-cdk/aws-appsync.ApiKeyConfig", "no-unused-type:@aws-cdk/aws-appsync.UserPoolConfig", "no-unused-type:@aws-cdk/aws-appsync.UserPoolDefaultAction", - "props-physical-name:@aws-cdk/aws-appsync.GraphqlApiProps" + "props-physical-name:@aws-cdk/aws-appsync.GraphQLApiProps", + "from-method:@aws-cdk/aws-appsync.GraphQLApi" ] }, "stability": "experimental", diff --git a/packages/@aws-cdk/aws-appsync/test/appsync-auth.test.ts b/packages/@aws-cdk/aws-appsync/test/appsync-auth.test.ts index 5815908198feb..fabde1d59c95e 100644 --- a/packages/@aws-cdk/aws-appsync/test/appsync-auth.test.ts +++ b/packages/@aws-cdk/aws-appsync/test/appsync-auth.test.ts @@ -13,7 +13,7 @@ beforeEach(() => { describe('AppSync API Key Authorization', () => { test('AppSync creates default api key', () => { // WHEN - new appsync.GraphqlApi(stack, 'api', { + new appsync.GraphQLApi(stack, 'api', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), }); @@ -24,7 +24,7 @@ describe('AppSync API Key Authorization', () => { test('AppSync creates api key from additionalAuthorizationModes', () => { // WHEN - new appsync.GraphqlApi(stack, 'api', { + new appsync.GraphQLApi(stack, 'api', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), authorizationConfig: { @@ -41,7 +41,7 @@ describe('AppSync API Key Authorization', () => { test('AppSync does not create unspecified api key from additionalAuthorizationModes', () => { // WHEN - new appsync.GraphqlApi(stack, 'api', { + new appsync.GraphQLApi(stack, 'api', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), authorizationConfig: { @@ -55,7 +55,7 @@ describe('AppSync API Key Authorization', () => { test('appsync does not create unspecified api key with empty additionalAuthorizationModes', () => { // WHEN - new appsync.GraphqlApi(stack, 'api', { + new appsync.GraphQLApi(stack, 'api', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), authorizationConfig: { @@ -70,7 +70,7 @@ describe('AppSync API Key Authorization', () => { test('appsync creates configured api key with additionalAuthorizationModes', () => { // WHEN - new appsync.GraphqlApi(stack, 'api', { + new appsync.GraphQLApi(stack, 'api', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), authorizationConfig: { @@ -90,7 +90,7 @@ describe('AppSync API Key Authorization', () => { test('appsync creates configured api key with additionalAuthorizationModes (not as first element)', () => { // WHEN - new appsync.GraphqlApi(stack, 'api', { + new appsync.GraphQLApi(stack, 'api', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), authorizationConfig: { @@ -117,7 +117,7 @@ describe('AppSync API Key Authorization', () => { test('appsync fails when empty default and API_KEY in additional', () => { // THEN expect(() => { - new appsync.GraphqlApi(stack, 'api', { + new appsync.GraphQLApi(stack, 'api', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), authorizationConfig: { @@ -132,7 +132,7 @@ describe('AppSync API Key Authorization', () => { test('appsync fails when multiple API_KEY auth modes', () => { // THEN expect(() => { - new appsync.GraphqlApi(stack, 'api', { + new appsync.GraphQLApi(stack, 'api', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), authorizationConfig: { @@ -148,7 +148,7 @@ describe('AppSync API Key Authorization', () => { test('appsync fails when multiple API_KEY auth modes in additionalXxx', () => { // THEN expect(() => { - new appsync.GraphqlApi(stack, 'api', { + new appsync.GraphQLApi(stack, 'api', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), authorizationConfig: { @@ -166,7 +166,7 @@ describe('AppSync API Key Authorization', () => { describe('AppSync IAM Authorization', () => { test('Iam authorization configurable in default authorization', () => { // WHEN - new appsync.GraphqlApi(stack, 'api', { + new appsync.GraphQLApi(stack, 'api', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), authorizationConfig: { @@ -182,7 +182,7 @@ describe('AppSync IAM Authorization', () => { test('Iam authorization configurable in additional authorization', () => { // WHEN - new appsync.GraphqlApi(stack, 'api', { + new appsync.GraphQLApi(stack, 'api', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), authorizationConfig: { @@ -199,7 +199,7 @@ describe('AppSync IAM Authorization', () => { test('appsync fails when multiple iam auth modes', () => { // THEN expect(() => { - new appsync.GraphqlApi(stack, 'api', { + new appsync.GraphQLApi(stack, 'api', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), authorizationConfig: { @@ -213,7 +213,7 @@ describe('AppSync IAM Authorization', () => { test('appsync fails when multiple IAM auth modes in additionalXxx', () => { // THEN expect(() => { - new appsync.GraphqlApi(stack, 'api', { + new appsync.GraphQLApi(stack, 'api', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), authorizationConfig: { @@ -234,7 +234,7 @@ describe('AppSync User Pool Authorization', () => { }); test('User Pool authorization configurable in default authorization has default configuration', () => { // WHEN - new appsync.GraphqlApi(stack, 'api', { + new appsync.GraphQLApi(stack, 'api', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), authorizationConfig: { @@ -258,7 +258,7 @@ describe('AppSync User Pool Authorization', () => { test('User Pool authorization configurable in default authorization', () => { // WHEN - new appsync.GraphqlApi(stack, 'api', { + new appsync.GraphQLApi(stack, 'api', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), authorizationConfig: { @@ -287,7 +287,7 @@ describe('AppSync User Pool Authorization', () => { test('User Pool authorization configurable in additional authorization has default configuration', () => { // WHEN - new appsync.GraphqlApi(stack, 'api', { + new appsync.GraphQLApi(stack, 'api', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), authorizationConfig: { @@ -312,7 +312,7 @@ describe('AppSync User Pool Authorization', () => { test('User Pool property defaultAction does not configure when in additional auth', () => { // WHEN - new appsync.GraphqlApi(stack, 'api', { + new appsync.GraphQLApi(stack, 'api', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), authorizationConfig: { @@ -342,7 +342,7 @@ describe('AppSync User Pool Authorization', () => { test('User Pool property defaultAction does not configure when in additional auth', () => { // WHEN - new appsync.GraphqlApi(stack, 'api', { + new appsync.GraphQLApi(stack, 'api', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), authorizationConfig: { @@ -399,7 +399,7 @@ describe('AppSync User Pool Authorization', () => { describe('AppSync OIDC Authorization', () => { test('OIDC authorization configurable in default authorization has default configuration', () => { // WHEN - new appsync.GraphqlApi(stack, 'api', { + new appsync.GraphQLApi(stack, 'api', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), authorizationConfig: { @@ -421,7 +421,7 @@ describe('AppSync OIDC Authorization', () => { test('User Pool authorization configurable in default authorization', () => { // WHEN - new appsync.GraphqlApi(stack, 'api', { + new appsync.GraphQLApi(stack, 'api', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), authorizationConfig: { @@ -451,7 +451,7 @@ describe('AppSync OIDC Authorization', () => { test('OIDC authorization configurable in additional authorization has default configuration', () => { // WHEN - new appsync.GraphqlApi(stack, 'api', { + new appsync.GraphQLApi(stack, 'api', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), authorizationConfig: { @@ -475,7 +475,7 @@ describe('AppSync OIDC Authorization', () => { test('User Pool authorization configurable in additional authorization', () => { // WHEN - new appsync.GraphqlApi(stack, 'api', { + new appsync.GraphQLApi(stack, 'api', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), authorizationConfig: { @@ -507,7 +507,7 @@ describe('AppSync OIDC Authorization', () => { test('User Pool authorization configurable in with multiple authorization', () => { // WHEN - new appsync.GraphqlApi(stack, 'api', { + new appsync.GraphQLApi(stack, 'api', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), authorizationConfig: { diff --git a/packages/@aws-cdk/aws-appsync/test/appsync-code-first.test.ts b/packages/@aws-cdk/aws-appsync/test/appsync-code-first.test.ts index 98460fd8be00d..0b39cab4c4c24 100644 --- a/packages/@aws-cdk/aws-appsync/test/appsync-code-first.test.ts +++ b/packages/@aws-cdk/aws-appsync/test/appsync-code-first.test.ts @@ -10,10 +10,10 @@ beforeEach(() => { }); describe('code-first implementation through GraphQL Api functions`', () => { - let api: appsync.GraphqlApi; + let api: appsync.GraphQLApi; beforeEach(() => { // GIVEN - api = new appsync.GraphqlApi(stack, 'api', { + api = new appsync.GraphQLApi(stack, 'api', { name: 'api', }); }); @@ -164,7 +164,7 @@ describe('code-first implementation through Schema functions`', () => { schema.addType(test); test.addField('dupid', t.dup_id); - new appsync.GraphqlApi(stack, 'api', { + new appsync.GraphQLApi(stack, 'api', { name: 'api', schema, }); @@ -190,7 +190,7 @@ describe('code-first implementation through Schema functions`', () => { schema.addType(test); test.addField('dupid', t.dup_id); - new appsync.GraphqlApi(stack, 'api', { + new appsync.GraphQLApi(stack, 'api', { name: 'api', schema, }); @@ -215,7 +215,7 @@ describe('code-first implementation through Schema functions`', () => { }, })); - new appsync.GraphqlApi(stack, 'api', { + new appsync.GraphQLApi(stack, 'api', { name: 'api', schema, }); @@ -241,7 +241,7 @@ describe('code-first implementation through Schema functions`', () => { })); test.addField('dupid', t.dup_id); - new appsync.GraphqlApi(stack, 'api', { + new appsync.GraphQLApi(stack, 'api', { name: 'api', schema, }); @@ -265,7 +265,7 @@ describe('code-first implementation through Schema functions`', () => { dupid: t.dup_id, }, })); - new appsync.GraphqlApi(stack, 'api', { + new appsync.GraphQLApi(stack, 'api', { name: 'api', schema, }); @@ -290,7 +290,7 @@ describe('code-first implementation through Schema functions`', () => { })); test.addField('dupid', t.dup_id); - new appsync.GraphqlApi(stack, 'api', { + new appsync.GraphQLApi(stack, 'api', { name: 'api', schema, }); diff --git a/packages/@aws-cdk/aws-appsync/test/appsync-dynamodb.test.ts b/packages/@aws-cdk/aws-appsync/test/appsync-dynamodb.test.ts index 07565edd1fba5..e54a9576396d1 100644 --- a/packages/@aws-cdk/aws-appsync/test/appsync-dynamodb.test.ts +++ b/packages/@aws-cdk/aws-appsync/test/appsync-dynamodb.test.ts @@ -10,10 +10,10 @@ function joined(str: string): string { // GLOBAL GIVEN let stack: cdk.Stack; -let api: appsync.GraphqlApi; +let api: appsync.GraphQLApi; beforeEach(() => { stack = new cdk.Stack(); - api = new appsync.GraphqlApi(stack, 'baseApi', { + api = new appsync.GraphQLApi(stack, 'baseApi', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), }); @@ -75,7 +75,7 @@ describe('DynamoDb Data Source configuration', () => { expect(() => { api.addDynamoDbDataSource('ds', table); api.addDynamoDbDataSource('ds', table); - }).toThrow("There is already a Construct with name 'ds' in GraphqlApi [baseApi]"); + }).toThrow("There is already a Construct with name 'ds' in GraphQLApi [baseApi]"); }); }); @@ -160,7 +160,7 @@ describe('adding DynamoDb data source from imported api', () => { test('imported api can add DynamoDbDataSource from id', () => { // WHEN - const importedApi = appsync.GraphqlApi.fromGraphqlApiAttributes(stack, 'importedApi', { + const importedApi = appsync.GraphQLApi.fromGraphqlApiAttributes(stack, 'importedApi', { graphqlApiId: api.apiId, }); importedApi.addDynamoDbDataSource('ds', table); @@ -174,7 +174,7 @@ describe('adding DynamoDb data source from imported api', () => { test('imported api can add DynamoDbDataSource from attributes', () => { // WHEN - const importedApi = appsync.GraphqlApi.fromGraphqlApiAttributes(stack, 'importedApi', { + const importedApi = appsync.GraphQLApi.fromGraphqlApiAttributes(stack, 'importedApi', { graphqlApiId: api.apiId, graphqlApiArn: api.arn, }); diff --git a/packages/@aws-cdk/aws-appsync/test/appsync-grant.test.ts b/packages/@aws-cdk/aws-appsync/test/appsync-grant.test.ts index d59b7c5d363cb..44251cd7fabee 100644 --- a/packages/@aws-cdk/aws-appsync/test/appsync-grant.test.ts +++ b/packages/@aws-cdk/aws-appsync/test/appsync-grant.test.ts @@ -6,14 +6,14 @@ import * as appsync from '../lib'; let stack: cdk.Stack; let role: iam.Role; -let api: appsync.GraphqlApi; +let api: appsync.GraphQLApi; beforeEach(() => { // GIVEN stack = new cdk.Stack(); role = new iam.Role(stack, 'Role', { assumedBy: new iam.ServicePrincipal('lambda.amazonaws.com'), }); - api = new appsync.GraphqlApi(stack, 'API', { + api = new appsync.GraphQLApi(stack, 'API', { name: 'demo', schema: appsync.Schema.fromAsset(join(__dirname, 'appsync.test.graphql')), authorizationConfig: { diff --git a/packages/@aws-cdk/aws-appsync/test/appsync-http.test.ts b/packages/@aws-cdk/aws-appsync/test/appsync-http.test.ts index 6bc237e0f5c71..899a76ebd19f4 100644 --- a/packages/@aws-cdk/aws-appsync/test/appsync-http.test.ts +++ b/packages/@aws-cdk/aws-appsync/test/appsync-http.test.ts @@ -5,11 +5,11 @@ import * as appsync from '../lib'; // GLOBAL GIVEN let stack: cdk.Stack; -let api: appsync.GraphqlApi; +let api: appsync.GraphQLApi; let endpoint: string; beforeEach(() => { stack = new cdk.Stack(); - api = new appsync.GraphqlApi(stack, 'baseApi', { + api = new appsync.GraphQLApi(stack, 'baseApi', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), }); @@ -62,14 +62,14 @@ describe('Http Data Source configuration', () => { expect(() => { api.addHttpDataSource('ds', endpoint); api.addHttpDataSource('ds', endpoint); - }).toThrow("There is already a Construct with name 'ds' in GraphqlApi [baseApi]"); + }).toThrow("There is already a Construct with name 'ds' in GraphQLApi [baseApi]"); }); }); describe('adding http data source from imported api', () => { test('imported api can add HttpDataSource from id', () => { // WHEN - const importedApi = appsync.GraphqlApi.fromGraphqlApiAttributes(stack, 'importedApi', { + const importedApi = appsync.GraphQLApi.fromGraphqlApiAttributes(stack, 'importedApi', { graphqlApiId: api.apiId, }); importedApi.addHttpDataSource('ds', endpoint); @@ -83,7 +83,7 @@ describe('adding http data source from imported api', () => { test('imported api can add HttpDataSource from attributes', () => { // WHEN - const importedApi = appsync.GraphqlApi.fromGraphqlApiAttributes(stack, 'importedApi', { + const importedApi = appsync.GraphQLApi.fromGraphqlApiAttributes(stack, 'importedApi', { graphqlApiId: api.apiId, graphqlApiArn: api.arn, }); diff --git a/packages/@aws-cdk/aws-appsync/test/appsync-interface-type.test.ts b/packages/@aws-cdk/aws-appsync/test/appsync-interface-type.test.ts index 644e7fae42354..981ec8b60a039 100644 --- a/packages/@aws-cdk/aws-appsync/test/appsync-interface-type.test.ts +++ b/packages/@aws-cdk/aws-appsync/test/appsync-interface-type.test.ts @@ -4,11 +4,11 @@ import * as appsync from '../lib'; import * as t from './scalar-type-defintions'; let stack: cdk.Stack; -let api: appsync.GraphqlApi; +let api: appsync.GraphQLApi; beforeEach(() => { // GIVEN stack = new cdk.Stack(); - api = new appsync.GraphqlApi(stack, 'api', { + api = new appsync.GraphQLApi(stack, 'api', { name: 'api', }); }); diff --git a/packages/@aws-cdk/aws-appsync/test/appsync-lambda.test.ts b/packages/@aws-cdk/aws-appsync/test/appsync-lambda.test.ts index 0cc8396382017..a67fd4b1691b7 100644 --- a/packages/@aws-cdk/aws-appsync/test/appsync-lambda.test.ts +++ b/packages/@aws-cdk/aws-appsync/test/appsync-lambda.test.ts @@ -6,10 +6,10 @@ import * as appsync from '../lib'; // GLOBAL GIVEN let stack: cdk.Stack; -let api: appsync.GraphqlApi; +let api: appsync.GraphQLApi; beforeEach(() => { stack = new cdk.Stack(); - api = new appsync.GraphqlApi(stack, 'baseApi', { + api = new appsync.GraphQLApi(stack, 'baseApi', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), }); @@ -70,7 +70,7 @@ describe('Lambda Data Source configuration', () => { expect(() => { api.addLambdaDataSource('ds', func); api.addLambdaDataSource('ds', func); - }).toThrow("There is already a Construct with name 'ds' in GraphqlApi [baseApi]"); + }).toThrow("There is already a Construct with name 'ds' in GraphQLApi [baseApi]"); }); }); @@ -86,7 +86,7 @@ describe('adding lambda data source from imported api', () => { test('imported api can add LambdaDbDataSource from id', () => { // WHEN - const importedApi = appsync.GraphqlApi.fromGraphqlApiAttributes(stack, 'importedApi', { + const importedApi = appsync.GraphQLApi.fromGraphqlApiAttributes(stack, 'importedApi', { graphqlApiId: api.apiId, }); importedApi.addLambdaDataSource('ds', func); @@ -100,7 +100,7 @@ describe('adding lambda data source from imported api', () => { test('imported api can add LambdaDataSource from attributes', () => { // WHEN - const importedApi = appsync.GraphqlApi.fromGraphqlApiAttributes(stack, 'importedApi', { + const importedApi = appsync.GraphQLApi.fromGraphqlApiAttributes(stack, 'importedApi', { graphqlApiId: api.apiId, graphqlApiArn: api.arn, }); diff --git a/packages/@aws-cdk/aws-appsync/test/appsync-none.test.ts b/packages/@aws-cdk/aws-appsync/test/appsync-none.test.ts index 3985cebc30719..f2b52c7dfba03 100644 --- a/packages/@aws-cdk/aws-appsync/test/appsync-none.test.ts +++ b/packages/@aws-cdk/aws-appsync/test/appsync-none.test.ts @@ -5,10 +5,10 @@ import * as appsync from '../lib'; // GLOBAL GIVEN let stack: cdk.Stack; -let api: appsync.GraphqlApi; +let api: appsync.GraphQLApi; beforeEach(() => { stack = new cdk.Stack(); - api = new appsync.GraphqlApi(stack, 'baseApi', { + api = new appsync.GraphQLApi(stack, 'baseApi', { name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), }); @@ -60,7 +60,7 @@ describe('None Data Source configuration', () => { expect(() => { api.addNoneDataSource('ds'); api.addNoneDataSource('ds'); - }).toThrow("There is already a Construct with name 'ds' in GraphqlApi [baseApi]"); + }).toThrow("There is already a Construct with name 'ds' in GraphQLApi [baseApi]"); }); test('appsync errors when creating multiple none data sources with same name configuration', () => { @@ -75,7 +75,7 @@ describe('None Data Source configuration', () => { describe('adding none data source from imported api', () => { test('imported api can add NoneDataSource from id', () => { // WHEN - const importedApi = appsync.GraphqlApi.fromGraphqlApiAttributes(stack, 'importedApi', { + const importedApi = appsync.GraphQLApi.fromGraphqlApiAttributes(stack, 'importedApi', { graphqlApiId: api.apiId, }); importedApi.addNoneDataSource('none'); @@ -89,7 +89,7 @@ describe('adding none data source from imported api', () => { test('imported api can add NoneDataSource from attributes', () => { // WHEN - const importedApi = appsync.GraphqlApi.fromGraphqlApiAttributes(stack, 'importedApi', { + const importedApi = appsync.GraphQLApi.fromGraphqlApiAttributes(stack, 'importedApi', { graphqlApiId: api.apiId, graphqlApiArn: api.arn, }); diff --git a/packages/@aws-cdk/aws-appsync/test/appsync-object-type.test.ts b/packages/@aws-cdk/aws-appsync/test/appsync-object-type.test.ts index 02f0d9b43ff57..a60a5242f6fe7 100644 --- a/packages/@aws-cdk/aws-appsync/test/appsync-object-type.test.ts +++ b/packages/@aws-cdk/aws-appsync/test/appsync-object-type.test.ts @@ -4,11 +4,11 @@ import * as appsync from '../lib'; import * as t from './scalar-type-defintions'; let stack: cdk.Stack; -let api: appsync.GraphqlApi; +let api: appsync.GraphQLApi; beforeEach(() => { // GIVEN stack = new cdk.Stack(); - api = new appsync.GraphqlApi(stack, 'api', { + api = new appsync.GraphQLApi(stack, 'api', { name: 'api', }); }); diff --git a/packages/@aws-cdk/aws-appsync/test/appsync-scalar-type.test.ts b/packages/@aws-cdk/aws-appsync/test/appsync-scalar-type.test.ts index 312d7a3784b98..64fddd55bc3d3 100644 --- a/packages/@aws-cdk/aws-appsync/test/appsync-scalar-type.test.ts +++ b/packages/@aws-cdk/aws-appsync/test/appsync-scalar-type.test.ts @@ -4,11 +4,11 @@ import * as appsync from '../lib'; import * as t from './scalar-type-defintions'; let stack: cdk.Stack; -let api: appsync.GraphqlApi; +let api: appsync.GraphQLApi; beforeEach(() => { // GIVEN stack = new cdk.Stack(); - api = new appsync.GraphqlApi(stack, 'api', { + api = new appsync.GraphQLApi(stack, 'api', { name: 'api', }); }); diff --git a/packages/@aws-cdk/aws-appsync/test/appsync-schema.test.ts b/packages/@aws-cdk/aws-appsync/test/appsync-schema.test.ts index 95fe1ac7c500a..f60d63f1dec5c 100644 --- a/packages/@aws-cdk/aws-appsync/test/appsync-schema.test.ts +++ b/packages/@aws-cdk/aws-appsync/test/appsync-schema.test.ts @@ -36,7 +36,7 @@ describe('basic testing schema definition mode `code`', () => { test('definition mode `code` produces empty schema definition', () => { // WHEN - new appsync.GraphqlApi(stack, 'API', { + new appsync.GraphQLApi(stack, 'API', { name: 'demo', }); @@ -48,7 +48,7 @@ describe('basic testing schema definition mode `code`', () => { test('definition mode `code` generates correct schema with addToSchema', () => { // WHEN - const api = new appsync.GraphqlApi(stack, 'API', { + const api = new appsync.GraphQLApi(stack, 'API', { name: 'demo', }); api.addType(type); @@ -63,7 +63,7 @@ describe('basic testing schema definition mode `code`', () => { test('definition mode `code` allows for api to addQuery', () => { // WHEN - const api = new appsync.GraphqlApi(stack, 'API', { + const api = new appsync.GraphQLApi(stack, 'API', { name: 'demo', }); api.addQuery('test', new appsync.ResolvableField({ @@ -79,7 +79,7 @@ describe('basic testing schema definition mode `code`', () => { test('definition mode `code` allows for schema to addQuery', () => { // WHEN const schema = new appsync.Schema(); - new appsync.GraphqlApi(stack, 'API', { + new appsync.GraphQLApi(stack, 'API', { name: 'demo', schema, }); @@ -95,7 +95,7 @@ describe('basic testing schema definition mode `code`', () => { test('definition mode `code` allows for api to addMutation', () => { // WHEN - const api = new appsync.GraphqlApi(stack, 'API', { + const api = new appsync.GraphQLApi(stack, 'API', { name: 'demo', }); api.addMutation('test', new appsync.ResolvableField({ @@ -111,7 +111,7 @@ describe('basic testing schema definition mode `code`', () => { test('definition mode `code` allows for schema to addMutation', () => { // WHEN const schema = new appsync.Schema(); - new appsync.GraphqlApi(stack, 'API', { + new appsync.GraphQLApi(stack, 'API', { name: 'demo', schema, }); @@ -130,7 +130,7 @@ describe('testing schema definition mode `file`', () => { test('definition mode `file` produces correct output', () => { // WHEN - new appsync.GraphqlApi(stack, 'API', { + new appsync.GraphQLApi(stack, 'API', { name: 'demo', schema: appsync.Schema.fromAsset(join(__dirname, 'appsync.test.graphql')), }); @@ -143,7 +143,7 @@ describe('testing schema definition mode `file`', () => { test('definition mode `file` errors when addType for object is called', () => { // WHEN - const api = new appsync.GraphqlApi(stack, 'API', { + const api = new appsync.GraphQLApi(stack, 'API', { name: 'demo', schema: appsync.Schema.fromAsset(join(__dirname, 'appsync.test.graphql')), }); @@ -158,7 +158,7 @@ describe('testing schema definition mode `file`', () => { test('definition mode `file` errors when addType for interface is called', () => { // WHEN - const api = new appsync.GraphqlApi(stack, 'API', { + const api = new appsync.GraphQLApi(stack, 'API', { name: 'demo', schema: appsync.Schema.fromAsset(join(__dirname, 'appsync.test.graphql')), }); @@ -173,7 +173,7 @@ describe('testing schema definition mode `file`', () => { test('definition mode `file` errors when addToSchema is called', () => { // WHEN - const api = new appsync.GraphqlApi(stack, 'API', { + const api = new appsync.GraphQLApi(stack, 'API', { name: 'demo', schema: appsync.Schema.fromAsset(join(__dirname, 'appsync.test.graphql')), }); @@ -186,7 +186,7 @@ describe('testing schema definition mode `file`', () => { test('definition mode `file` errors when addQuery is called', () => { // WHEN - const api = new appsync.GraphqlApi(stack, 'API', { + const api = new appsync.GraphQLApi(stack, 'API', { name: 'demo', schema: appsync.Schema.fromAsset(join(__dirname, 'appsync.test.graphql')), }); @@ -199,7 +199,7 @@ describe('testing schema definition mode `file`', () => { test('definition mode `file` errors when addMutation is called', () => { // WHEN - const api = new appsync.GraphqlApi(stack, 'API', { + const api = new appsync.GraphQLApi(stack, 'API', { name: 'demo', schema: appsync.Schema.fromAsset(join(__dirname, 'appsync.test.graphql')), }); diff --git a/packages/@aws-cdk/aws-appsync/test/appsync.test.ts b/packages/@aws-cdk/aws-appsync/test/appsync.test.ts index debdfa71ce4f0..9dc6808a672e1 100644 --- a/packages/@aws-cdk/aws-appsync/test/appsync.test.ts +++ b/packages/@aws-cdk/aws-appsync/test/appsync.test.ts @@ -4,10 +4,10 @@ import * as cdk from '@aws-cdk/core'; import * as appsync from '../lib'; let stack: cdk.Stack; -let api: appsync.GraphqlApi; +let api: appsync.GraphQLApi; beforeEach(() => { stack = new cdk.Stack(); - api = new appsync.GraphqlApi(stack, 'api', { + api = new appsync.GraphQLApi(stack, 'api', { authorizationConfig: {}, name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), @@ -61,7 +61,7 @@ test('appsync should configure resolver as unit when pipelineConfig is empty arr test('when xray is enabled should not throw an Error', () => { // WHEN - new appsync.GraphqlApi(stack, 'api-x-ray', { + new appsync.GraphQLApi(stack, 'api-x-ray', { authorizationConfig: {}, name: 'api', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), diff --git a/packages/@aws-cdk/aws-appsync/test/integ.api-import.ts b/packages/@aws-cdk/aws-appsync/test/integ.api-import.ts index 8781f83fe117e..b36c6a1bef7b1 100644 --- a/packages/@aws-cdk/aws-appsync/test/integ.api-import.ts +++ b/packages/@aws-cdk/aws-appsync/test/integ.api-import.ts @@ -11,7 +11,7 @@ import * as appsync from '../lib'; * * Stack verification steps: * Install dependencies and deploy integration test. Check if data sources are - * connected to the GraphQL Api + * connected to the graphQL Api * * -- cdk deploy --app 'node integ.api-import.js' stack -- start -- * -- aws appsync list-graphql-apis -- obtain api id -- @@ -22,13 +22,13 @@ import * as appsync from '../lib'; const app = new cdk.App(); const baseStack = new cdk.Stack(app, 'baseStack'); -const baseApi = new appsync.GraphqlApi(baseStack, 'baseApi', { +const baseApi = new appsync.GraphQLApi(baseStack, 'baseApi', { name: 'baseApi', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.test.graphql')), }); const stack = new cdk.Stack(app, 'stack'); -const api = appsync.GraphqlApi.fromGraphqlApiAttributes(stack, 'Api', { +const api = appsync.GraphQLApi.fromGraphqlApiAttributes(stack, 'Api', { graphqlApiId: `${baseApi.apiId}`, }); @@ -57,7 +57,7 @@ testDS.createResolver({ responseMappingTemplate: appsync.MappingTemplate.dynamoDbResultItem(), }); -const api2 = appsync.GraphqlApi.fromGraphqlApiAttributes(stack, 'api2', { +const api2 = appsync.GraphQLApi.fromGraphqlApiAttributes(stack, 'api2', { graphqlApiId: baseApi.apiId, graphqlApiArn: baseApi.arn, }); diff --git a/packages/@aws-cdk/aws-appsync/test/integ.graphql-iam.ts b/packages/@aws-cdk/aws-appsync/test/integ.graphql-iam.ts index 185fc8ef3e729..0d4c95a10ea3f 100644 --- a/packages/@aws-cdk/aws-appsync/test/integ.graphql-iam.ts +++ b/packages/@aws-cdk/aws-appsync/test/integ.graphql-iam.ts @@ -6,7 +6,7 @@ import { Code, Function, Runtime } from '@aws-cdk/aws-lambda'; import { App, RemovalPolicy, Stack } from '@aws-cdk/core'; import { AuthorizationType, - GraphqlApi, + GraphQLApi, MappingTemplate, PrimaryKey, UserPoolDefaultAction, @@ -36,7 +36,7 @@ const userPool = new UserPool(stack, 'Pool', { userPoolName: 'myPool', }); -const api = new GraphqlApi(stack, 'Api', { +const api = new GraphQLApi(stack, 'Api', { name: 'Integ_Test_IAM', schema: Schema.fromAsset(join(__dirname, 'integ.graphql-iam.graphql')), authorizationConfig: { @@ -98,14 +98,14 @@ new Function(stack, 'testQuery', { code: Code.fromAsset('verify'), handler: 'iam-query.handler', runtime: Runtime.NODEJS_12_X, - environment: { APPSYNC_ENDPOINT: api.graphqlUrl }, + environment: { APPSYNC_ENDPOINT: api.graphQlUrl }, role: lambdaIAM, }); new Function(stack, 'testFail', { code: Code.fromAsset('verify'), handler: 'iam-query.handler', runtime: Runtime.NODEJS_12_X, - environment: { APPSYNC_ENDPOINT: api.graphqlUrl }, + environment: { APPSYNC_ENDPOINT: api.graphQlUrl }, }); app.synth(); diff --git a/packages/@aws-cdk/aws-appsync/test/integ.graphql-schema.ts b/packages/@aws-cdk/aws-appsync/test/integ.graphql-schema.ts index 8cb3daafab11a..8bde313c6f724 100644 --- a/packages/@aws-cdk/aws-appsync/test/integ.graphql-schema.ts +++ b/packages/@aws-cdk/aws-appsync/test/integ.graphql-schema.ts @@ -29,7 +29,7 @@ const node = schema.addType(new appsync.InterfaceType('Node', { }, })); -const api = new appsync.GraphqlApi(stack, 'code-first-api', { +const api = new appsync.GraphQLApi(stack, 'code-first-api', { name: 'api', schema: schema, }); diff --git a/packages/@aws-cdk/aws-appsync/test/integ.graphql.ts b/packages/@aws-cdk/aws-appsync/test/integ.graphql.ts index 1de80995c90a0..9882fead1cf12 100644 --- a/packages/@aws-cdk/aws-appsync/test/integ.graphql.ts +++ b/packages/@aws-cdk/aws-appsync/test/integ.graphql.ts @@ -4,7 +4,7 @@ import { AttributeType, BillingMode, Table } from '@aws-cdk/aws-dynamodb'; import { App, RemovalPolicy, Stack } from '@aws-cdk/core'; import { AuthorizationType, - GraphqlApi, + GraphQLApi, KeyCondition, MappingTemplate, PrimaryKey, @@ -33,7 +33,7 @@ const userPool = new UserPool(stack, 'Pool', { userPoolName: 'myPool', }); -const api = new GraphqlApi(stack, 'Api', { +const api = new GraphQLApi(stack, 'Api', { name: 'demoapi', schema: Schema.fromAsset(join(__dirname, 'integ.graphql.graphql')), authorizationConfig: { From c61f436d2a1145abf15481a3cdf6e36903bb27c1 Mon Sep 17 00:00:00 2001 From: Bryan Pan Date: Wed, 2 Sep 2020 10:42:23 -0700 Subject: [PATCH 20/21] address suggestions --- packages/@aws-cdk/aws-appsync/lib/graphqlapi.ts | 2 +- packages/@aws-cdk/aws-appsync/test/appsync-auth.test.ts | 2 +- packages/@aws-cdk/core/lib/expiration.ts | 6 +++--- packages/@aws-cdk/core/test/test.expiration.ts | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/@aws-cdk/aws-appsync/lib/graphqlapi.ts b/packages/@aws-cdk/aws-appsync/lib/graphqlapi.ts index dcc3b1579402d..d0de41511872c 100644 --- a/packages/@aws-cdk/aws-appsync/lib/graphqlapi.ts +++ b/packages/@aws-cdk/aws-appsync/lib/graphqlapi.ts @@ -553,7 +553,7 @@ export class GraphQLApi extends GraphqlApiBase { if (config?.expires?.isBefore(Duration.days(1)) || config?.expires?.isAfter(Duration.days(365))) { throw Error('API key expiration must be between 1 and 365 days.'); } - const expires = config?.expires ? config?.expires.asEpoch() : undefined; + const expires = config?.expires ? config?.expires.toEpoch() : undefined; return new CfnApiKey(this, `${config?.name || 'Default'}ApiKey`, { expires, description: config?.description, diff --git a/packages/@aws-cdk/aws-appsync/test/appsync-auth.test.ts b/packages/@aws-cdk/aws-appsync/test/appsync-auth.test.ts index 6ba406e37e9bf..1cc1eeb30ff6a 100644 --- a/packages/@aws-cdk/aws-appsync/test/appsync-auth.test.ts +++ b/packages/@aws-cdk/aws-appsync/test/appsync-auth.test.ts @@ -89,7 +89,7 @@ describe('AppSync API Key Authorization', () => { }); test('apiKeyConfig creates default with valid expiration date', () => { - const expirationDate: number = cdk.Expiration.after(cdk.Duration.days(10)).asEpoch(); + const expirationDate: number = cdk.Expiration.after(cdk.Duration.days(10)).toEpoch(); // WHEN new appsync.GraphQLApi(stack, 'API', { diff --git a/packages/@aws-cdk/core/lib/expiration.ts b/packages/@aws-cdk/core/lib/expiration.ts index d80923ab72b26..ac3b4a8652bb6 100644 --- a/packages/@aws-cdk/core/lib/expiration.ts +++ b/packages/@aws-cdk/core/lib/expiration.ts @@ -48,14 +48,14 @@ export class Expiration { /** * Exipration Value in a formatted Unix Epoch Time in seconds */ - public asEpoch(): number { - return Math.round( this.date.getTime() / 1000); + public toEpoch(): number { + return Math.round(this.date.getTime() / 1000); } /** * Check if Exipiration expires before input * @param t the duration to check against */ - public isBefore( t: Duration ): boolean { + public isBefore(t: Duration): boolean { return this.date < new Date(Date.now() + t.toMilliseconds()); } diff --git a/packages/@aws-cdk/core/test/test.expiration.ts b/packages/@aws-cdk/core/test/test.expiration.ts index c2795e5a6cb20..bca8c36247fc2 100644 --- a/packages/@aws-cdk/core/test/test.expiration.ts +++ b/packages/@aws-cdk/core/test/test.expiration.ts @@ -26,9 +26,9 @@ export = nodeunit.testCase({ test.done(); }, - 'asEpoch returns correct value'(test: nodeunit.Test) { + 'toEpoch returns correct value'(test: nodeunit.Test) { const date = new Date('Sun, 26 Jan 2020 00:53:20 GMT'); - test.equal(Expiration.atDate(date).asEpoch(), 1580000000); + test.equal(Expiration.atDate(date).toEpoch(), 1580000000); test.done(); }, From 859c14d1710b948b507d84d27f7cf984bc20e568 Mon Sep 17 00:00:00 2001 From: Bryan Pan Date: Wed, 2 Sep 2020 10:44:43 -0700 Subject: [PATCH 21/21] fix merge conflicts --- packages/@aws-cdk/aws-appsync/test/appsync-auth.test.ts | 6 +++--- packages/@aws-cdk/aws-appsync/test/integ.auth-apikey.ts | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/@aws-cdk/aws-appsync/test/appsync-auth.test.ts b/packages/@aws-cdk/aws-appsync/test/appsync-auth.test.ts index 373236f9a90ee..fbac8fcd07350 100644 --- a/packages/@aws-cdk/aws-appsync/test/appsync-auth.test.ts +++ b/packages/@aws-cdk/aws-appsync/test/appsync-auth.test.ts @@ -92,7 +92,7 @@ describe('AppSync API Key Authorization', () => { const expirationDate: number = cdk.Expiration.after(cdk.Duration.days(10)).toEpoch(); // WHEN - new appsync.GraphQLApi(stack, 'API', { + new appsync.GraphqlApi(stack, 'API', { name: 'apiKeyUnitTest', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.auth.graphql')), authorizationConfig: { @@ -114,7 +114,7 @@ describe('AppSync API Key Authorization', () => { test('apiKeyConfig fails if expire argument less than a day', () => { // WHEN const when = () => { - new appsync.GraphQLApi(stack, 'API', { + new appsync.GraphqlApi(stack, 'API', { name: 'apiKeyUnitTest', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.auth.graphql')), authorizationConfig: { @@ -135,7 +135,7 @@ describe('AppSync API Key Authorization', () => { test('apiKeyConfig fails if expire argument greater than 365 day', () => { // WHEN const when = () => { - new appsync.GraphQLApi(stack, 'API', { + new appsync.GraphqlApi(stack, 'API', { name: 'apiKeyUnitTest', schema: appsync.Schema.fromAsset(path.join(__dirname, 'appsync.auth.graphql')), authorizationConfig: { diff --git a/packages/@aws-cdk/aws-appsync/test/integ.auth-apikey.ts b/packages/@aws-cdk/aws-appsync/test/integ.auth-apikey.ts index eec4cec5ed7cf..5ddcb9abd1dbb 100644 --- a/packages/@aws-cdk/aws-appsync/test/integ.auth-apikey.ts +++ b/packages/@aws-cdk/aws-appsync/test/integ.auth-apikey.ts @@ -1,7 +1,7 @@ import { join } from 'path'; import { AttributeType, BillingMode, Table } from '@aws-cdk/aws-dynamodb'; import { App, RemovalPolicy, Stack, Expiration } from '@aws-cdk/core'; -import { AuthorizationType, GraphQLApi, MappingTemplate, PrimaryKey, Schema, Values } from '../lib'; +import { AuthorizationType, GraphqlApi, MappingTemplate, PrimaryKey, Schema, Values } from '../lib'; /* * Creates an Appsync GraphQL API with API_KEY authorization. @@ -21,7 +21,7 @@ import { AuthorizationType, GraphQLApi, MappingTemplate, PrimaryKey, Schema, Val const app = new App(); const stack = new Stack(app, 'aws-appsync-integ'); -const api = new GraphQLApi(stack, 'Api', { +const api = new GraphqlApi(stack, 'Api', { name: 'Integ_Test_APIKey', schema: Schema.fromAsset(join(__dirname, 'appsync.auth.graphql')), authorizationConfig: {