Skip to content

Commit f9a4a60

Browse files
author
Dane Pilcher
authored
Merge pull request #802 from aws-amplify/main
Release
2 parents 71e1dea + 73e4520 commit f9a4a60

File tree

56 files changed

+3876
-636
lines changed

Some content is hidden

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

56 files changed

+3876
-636
lines changed

.codebuild/e2e_workflow.yml

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -145,24 +145,25 @@ batch:
145145
depend-on:
146146
- publish_to_local_registry
147147
- identifier: >-
148-
l_build_app_ts_uninitialized_project_codegen_js_uninitialized_project_modelgen_android_uninitialized_project_modelgen_flutter
148+
l_build_app_ts_push_codegen_admin_modelgen_uninitialized_project_codegen_js_uninitialized_project_modelgen_android
149149
buildspec: .codebuild/run_e2e_tests.yml
150150
env:
151151
compute-type: BUILD_GENERAL1_LARGE
152152
variables:
153153
TEST_SUITE: >-
154-
src/__tests__/build-app-ts.test.ts|src/__tests__/uninitialized-project-codegen-js.test.ts|src/__tests__/uninitialized-project-modelgen-android.test.ts|src/__tests__/uninitialized-project-modelgen-flutter.test.ts
154+
src/__tests__/build-app-ts.test.ts|src/__tests__/push-codegen-admin-modelgen.test.ts|src/__tests__/uninitialized-project-codegen-js.test.ts|src/__tests__/uninitialized-project-modelgen-android.test.ts
155155
CLI_REGION: ap-southeast-1
156156
DISABLE_ESLINT_PLUGIN: true
157157
depend-on:
158158
- publish_to_local_registry
159-
- identifier: l_uninitialized_project_modelgen_ios_uninitialized_project_modelgen_js
159+
- identifier: >-
160+
l_uninitialized_project_modelgen_flutter_uninitialized_project_modelgen_ios_uninitialized_project_modelgen_js
160161
buildspec: .codebuild/run_e2e_tests.yml
161162
env:
162163
compute-type: BUILD_GENERAL1_LARGE
163164
variables:
164165
TEST_SUITE: >-
165-
src/__tests__/uninitialized-project-modelgen-ios.test.ts|src/__tests__/uninitialized-project-modelgen-js.test.ts
166+
src/__tests__/uninitialized-project-modelgen-flutter.test.ts|src/__tests__/uninitialized-project-modelgen-ios.test.ts|src/__tests__/uninitialized-project-modelgen-js.test.ts
166167
CLI_REGION: ap-southeast-2
167168
depend-on:
168169
- publish_to_local_registry
@@ -251,29 +252,30 @@ batch:
251252
- publish_to_local_registry
252253
- build_windows
253254
- identifier: >-
254-
w_build_app_ts_uninitialized_project_codegen_js_uninitialized_project_modelgen_android_uninitialized_project_modelgen_flutter
255+
w_build_app_ts_push_codegen_admin_modelgen_uninitialized_project_codegen_js_uninitialized_project_modelgen_android
255256
buildspec: .codebuild/run_e2e_tests_windows.yml
256257
env:
257258
compute-type: BUILD_GENERAL1_LARGE
258259
image: $WINDOWS_IMAGE_2019
259260
type: WINDOWS_SERVER_2019_CONTAINER
260261
variables:
261262
TEST_SUITE: >-
262-
src/__tests__/build-app-ts.test.ts|src/__tests__/uninitialized-project-codegen-js.test.ts|src/__tests__/uninitialized-project-modelgen-android.test.ts|src/__tests__/uninitialized-project-modelgen-flutter.test.ts
263+
src/__tests__/build-app-ts.test.ts|src/__tests__/push-codegen-admin-modelgen.test.ts|src/__tests__/uninitialized-project-codegen-js.test.ts|src/__tests__/uninitialized-project-modelgen-android.test.ts
263264
CLI_REGION: us-east-1
264265
DISABLE_ESLINT_PLUGIN: true
265266
depend-on:
266267
- publish_to_local_registry
267268
- build_windows
268-
- identifier: w_uninitialized_project_modelgen_ios_uninitialized_project_modelgen_js
269+
- identifier: >-
270+
w_uninitialized_project_modelgen_flutter_uninitialized_project_modelgen_ios_uninitialized_project_modelgen_js
269271
buildspec: .codebuild/run_e2e_tests_windows.yml
270272
env:
271273
compute-type: BUILD_GENERAL1_LARGE
272274
image: $WINDOWS_IMAGE_2019
273275
type: WINDOWS_SERVER_2019_CONTAINER
274276
variables:
275277
TEST_SUITE: >-
276-
src/__tests__/uninitialized-project-modelgen-ios.test.ts|src/__tests__/uninitialized-project-modelgen-js.test.ts
278+
src/__tests__/uninitialized-project-modelgen-flutter.test.ts|src/__tests__/uninitialized-project-modelgen-ios.test.ts|src/__tests__/uninitialized-project-modelgen-js.test.ts
277279
CLI_REGION: us-east-1
278280
depend-on:
279281
- publish_to_local_registry
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: Closed Issue Message
2+
on:
3+
issues:
4+
types: [closed]
5+
jobs:
6+
auto_comment:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: aws-actions/closed-issue-message@v1
10+
with:
11+
# These inputs are both required
12+
repo-token: '${{ secrets.GITHUB_TOKEN }}'
13+
message: |
14+
This issue is now closed. Comments on closed issues are hard for our team to see.
15+
If you need more assistance, please open a new issue that references this one.

dependency_licenses.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,7 @@ Apache License
684684

685685
-----
686686

687-
The following software may be included in this product: @aws-amplify/graphql-schema-test-library, @aws-amplify/graphql-transformer-interfaces, graphql-mapping-template, graphql-transformer-common, graphql-transformer-core. A copy of the source code may be downloaded from https://github.com/aws-amplify/amplify-category-api.git (@aws-amplify/graphql-schema-test-library), https://github.com/aws-amplify/amplify-category-api.git (@aws-amplify/graphql-transformer-interfaces), https://github.com/aws-amplify/amplify-category-api.git (graphql-mapping-template), https://github.com/aws-amplify/amplify-category-api.git (graphql-transformer-common), https://github.com/aws-amplify/amplify-category-api.git (graphql-transformer-core). This software contains the following license and notice below:
687+
The following software may be included in this product: @aws-amplify/graphql-directives, @aws-amplify/graphql-schema-test-library, @aws-amplify/graphql-transformer-interfaces, graphql-mapping-template, graphql-transformer-common, graphql-transformer-core. A copy of the source code may be downloaded from https://github.com/aws-amplify/amplify-category-api.git (@aws-amplify/graphql-directives), https://github.com/aws-amplify/amplify-category-api.git (@aws-amplify/graphql-schema-test-library), https://github.com/aws-amplify/amplify-category-api.git (@aws-amplify/graphql-transformer-interfaces), https://github.com/aws-amplify/amplify-category-api.git (graphql-mapping-template), https://github.com/aws-amplify/amplify-category-api.git (graphql-transformer-common), https://github.com/aws-amplify/amplify-category-api.git (graphql-transformer-core). This software contains the following license and notice below:
688688

689689
Apache License
690690
Version 2.0, January 2004

packages/amplify-codegen-e2e-core/src/utils/sdk-calls.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
AmplifyBackend,
1515
} from 'aws-sdk';
1616
import _ from 'lodash';
17+
import { getProjectMeta } from './projectMeta';
1718

1819
export const getDDBTable = async (tableName: string, region: string) => {
1920
const service = new DynamoDB({ region });
@@ -42,6 +43,19 @@ export const bucketNotExists = async (bucket: string) => {
4243
}
4344
};
4445

46+
export const getDeploymentBucketObject = async (projectRoot: string, objectKey: string) => {
47+
const meta = getProjectMeta(projectRoot);
48+
const deploymentBucket = meta.providers.awscloudformation.DeploymentBucketName;
49+
const s3 = new S3();
50+
const result = await s3
51+
.getObject({
52+
Bucket: deploymentBucket,
53+
Key: objectKey,
54+
})
55+
.promise();
56+
return result.Body.toLocaleString();
57+
};
58+
4559
export const deleteS3Bucket = async (bucket: string, providedS3Client: S3 | undefined = undefined) => {
4660
const s3 = providedS3Client ? providedS3Client : new S3();
4761
let continuationToken: Required<Pick<S3.ListObjectVersionsOutput, 'KeyMarker' | 'VersionIdMarker'>> = undefined;
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
input AMPLIFY { globalAuthRule: AuthRule = { allow: public } } # FOR TESTING ONLY!
2+
3+
type Todo @model {
4+
id: ID!
5+
name: String!
6+
description: String
7+
phone: Phone
8+
}
9+
type Phone {
10+
number: String
11+
}
12+
enum BillingSource {
13+
CLIENT
14+
PROJECT
15+
}
16+
input CustomInput {
17+
customField1: String!
18+
customField2: BillingSource
19+
customField3: NestedInput!
20+
}
21+
input NestedInput {
22+
content: String! = "hello"
23+
}
24+
interface ICustom {
25+
firstName: String!
26+
lastName: String
27+
birthdays: [INestedCustom!]!
28+
}
29+
interface INestedCustom {
30+
birthDay: AWSDate!
31+
}
32+
# The member types of a Union type must all be Object base types.
33+
union CustomUnion = Todo | Phone
34+
35+
type Query {
36+
getAllTodo(msg: String, input: CustomInput): String @function(name: "echofunction-${env}")
37+
echo(msg: String!): String
38+
echo2(todoId: ID!): Todo
39+
echo3: [Todo!]!
40+
echo4(number: String): Phone
41+
echo5: [CustomUnion!]!
42+
echo6(customInput: CustomInput): String!
43+
echo7: [ICustom]!
44+
echo8(msg: [Float], msg2: [Int!], enumType: BillingSource, enumList: [BillingSource], inputType: [CustomInput]): [String]
45+
echo9(msg: [Float]!, msg2: [Int!]!, enumType: BillingSource!, enumList: [BillingSource!]!, inputType: [CustomInput!]!): [String!]!
46+
47+
}
48+
type Mutation {
49+
mutate(msg: [String!]!): Todo
50+
}
51+
type Subscription {
52+
onMutate(msg: String): [Todo!]
53+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { DEFAULT_JS_CONFIG, createNewProjectDir } from "@aws-amplify/amplify-codegen-e2e-core";
2+
import { deleteAmplifyProject, testPushAdminModelgen, testPushCodegen } from "../codegen-tests-base";
3+
4+
const schema = 'admin-modelgen.graphql';
5+
6+
describe('Amplify push with codegen tests - admin modelgen', () => {
7+
let projectRoot: string;
8+
beforeEach(async () => {
9+
projectRoot = await createNewProjectDir('pushCodegenAdminModelgen');
10+
});
11+
12+
afterEach(async () => {
13+
await deleteAmplifyProject(projectRoot);
14+
});
15+
16+
it(`should not throw error for executing the admin modelgen step required by studio CMS usage post push given the schema with input, union and interface types`, async () => {
17+
await testPushAdminModelgen(DEFAULT_JS_CONFIG, projectRoot, schema);
18+
});
19+
});

packages/amplify-codegen-e2e-tests/src/cleanup-e2e-resources.ts

Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ type AmplifyAppInfo = {
4545

4646
type S3BucketInfo = {
4747
name: string;
48+
region: string;
4849
jobId?: string;
4950
cbInfo?: CodeBuild.Build;
5051
};
@@ -118,7 +119,16 @@ const getOrphanS3TestBuckets = async (account: AWSAccountInfo): Promise<S3Bucket
118119
const s3Client = new aws.S3(getAWSConfig(account));
119120
const listBucketResponse = await s3Client.listBuckets().promise();
120121
const staleBuckets = listBucketResponse.Buckets.filter(testBucketStalenessFilter);
121-
return staleBuckets.map(it => ({ name: it.Name }));
122+
const bucketInfos = await Promise.all(
123+
staleBuckets.map(async (staleBucket): Promise<S3BucketInfo> => {
124+
const region = await getBucketRegion(account, staleBucket.Name);
125+
return {
126+
name: staleBucket.Name,
127+
region,
128+
};
129+
}),
130+
);
131+
return bucketInfos;
122132
};
123133

124134
/**
@@ -276,27 +286,52 @@ const getJobCodeBuildDetails = async (jobIds: string[]): Promise<CodeBuild.Build
276286
}
277287
};
278288

289+
const getBucketRegion = async (account: AWSAccountInfo, bucketName: string): Promise<string> => {
290+
const awsConfig = getAWSConfig(account);
291+
const s3Client = new aws.S3(awsConfig);
292+
const location = await s3Client.getBucketLocation({ Bucket: bucketName }).promise();
293+
const region = location.LocationConstraint ?? 'us-east-1';
294+
return region;
295+
};
296+
279297
const getS3Buckets = async (account: AWSAccountInfo): Promise<S3BucketInfo[]> => {
280-
const s3Client = new aws.S3(getAWSConfig(account));
298+
const awsConfig = getAWSConfig(account);
299+
const s3Client = new aws.S3(awsConfig);
281300
const buckets = await s3Client.listBuckets().promise();
282301
const result: S3BucketInfo[] = [];
283302
for (const bucket of buckets.Buckets) {
303+
let region: string | undefined;
284304
try {
285-
const bucketDetails = await s3Client.getBucketTagging({ Bucket: bucket.Name }).promise();
305+
region = await getBucketRegion(account, bucket.Name);
306+
// Operations on buckets created in opt-in regions appear to require region-specific clients
307+
const regionalizedClient = new aws.S3({
308+
region,
309+
...(awsConfig as object),
310+
});
311+
const bucketDetails = await regionalizedClient.getBucketTagging({ Bucket: bucket.Name }).promise();
286312
const jobId = getJobId(bucketDetails.TagSet);
287313
if (jobId) {
288314
result.push({
289315
name: bucket.Name,
316+
region,
290317
jobId
291318
});
292319
}
293320
} catch (e) {
294-
if (e.code !== 'NoSuchTagSet' && e.code !== 'NoSuchBucket') {
321+
// TODO: Why do we process the bucket even with these particular errors?
322+
if (e.code === 'NoSuchTagSet' || e.code === 'NoSuchBucket') {
323+
result.push({
324+
name: bucket.Name,
325+
region: region ?? 'us-east-1',
326+
});
327+
} else if (e.code === 'InvalidToken') {
328+
// We see some buckets in some accounts that were somehow created in an opt-in region different from the one to which the account is
329+
// actually opted in. We don't quite know how this happened, but for now, we'll make a note of the inconsistency and continue
330+
// processing the rest of the buckets.
331+
console.error(`Skipping processing ${account.accountId}, bucket ${bucket.Name}`, e);
332+
} else {
295333
throw e;
296334
}
297-
result.push({
298-
name: bucket.Name,
299-
});
300335
}
301336
}
302337
return result;
@@ -516,8 +551,12 @@ const deleteBucket = async (account: AWSAccountInfo, accountIndex: number, bucke
516551
const { name } = bucket;
517552
try {
518553
console.log(`${generateAccountInfo(account, accountIndex)} Deleting S3 Bucket ${name}`);
519-
const s3 = new aws.S3(getAWSConfig(account));
520-
await deleteS3Bucket(name, s3);
554+
const awsConfig = getAWSConfig(account);
555+
const regionalizedS3Client = new aws.S3({
556+
region: bucket.region,
557+
...(awsConfig as object),
558+
});
559+
await deleteS3Bucket(name, regionalizedS3Client);
521560
} catch (e) {
522561
console.log(`${generateAccountInfo(account, accountIndex)} Deleting bucket ${name} failed with error ${e.message}`);
523562
if (e.code === 'ExpiredTokenException') {

packages/amplify-codegen-e2e-tests/src/codegen-tests-base/push-codegen.ts

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ import {
66
amplifyPushWithCodegenAdd,
77
AmplifyFrontendConfig,
88
amplifyPushWithCodegenUpdate,
9-
updateAPIWithResolutionStrategyWithModels
9+
updateAPIWithResolutionStrategyWithModels,
10+
getProjectMeta,
11+
getDeploymentBucketObject,
12+
amplifyPush
1013
} from "@aws-amplify/amplify-codegen-e2e-core";
1114
import { existsSync } from "fs";
1215
import path from 'path';
@@ -38,3 +41,38 @@ export async function testPushCodegen(config: AmplifyFrontendConfig, projectRoot
3841
expect(existsSync(userSourceCodePath)).toBe(true);
3942
expect(isNotEmptyDir(path.join(projectRoot, config.modelgenDir))).toBe(true);
4043
}
44+
45+
export async function testPushAdminModelgen(config: AmplifyFrontendConfig, projectRoot: string, schema: string) {
46+
// init project and add API category
47+
await initProjectWithProfile(projectRoot, { ...config, disableAmplifyAppCreation: false, });
48+
const {
49+
DeploymentBucketName: bucketName,
50+
Region: region,
51+
AmplifyAppId: appId,
52+
} = getProjectMeta(projectRoot).providers.awscloudformation;
53+
54+
expect(bucketName).toBeDefined()
55+
expect(region).toBeDefined();
56+
expect(appId).toBeDefined();
57+
58+
const projectName = createRandomName();
59+
await addApiWithoutSchema(projectRoot, { apiName: projectName });
60+
await updateApiSchema(projectRoot, projectName, schema);
61+
// add codegen succeeds
62+
await amplifyPush(projectRoot);
63+
64+
/**
65+
* Source code from
66+
* https://github.com/aws-amplify/amplify-cli/blob/1da5de70c57b15a76f02c92364af4889d1585229/packages/amplify-provider-awscloudformation/src/admin-modelgen.ts#L85-L93
67+
*/
68+
const s3ApiModelsPrefix = `models/${projectName}/`;
69+
const cmsArtifactLocalToS3Keys = [
70+
`${s3ApiModelsPrefix}schema.graphql`,
71+
`${s3ApiModelsPrefix}schema.js`,
72+
`${s3ApiModelsPrefix}modelIntrospection.json`,
73+
];
74+
// expect CMS assets to be present in S3
75+
cmsArtifactLocalToS3Keys.forEach(async (key) => {
76+
await expect(getDeploymentBucketObject(projectRoot, key)).resolves.not.toThrow();
77+
});
78+
}

packages/amplify-codegen/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"extract-api": "ts-node ../../scripts/extract-api.ts"
2222
},
2323
"dependencies": {
24+
"@aws-amplify/graphql-directives": "^1.0.1",
2425
"@aws-amplify/graphql-docs-generator": "4.2.1",
2526
"@aws-amplify/graphql-generator": "0.2.4",
2627
"@aws-amplify/graphql-types-generator": "3.4.6",

packages/amplify-codegen/src/commands/add.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ async function add(context, apiId = null, region = 'us-east-1') {
145145
apiId,
146146
...(withoutInit ? { frontend } : {}),
147147
...(withoutInit && frontend === 'javascript' ? { framework } : {}),
148+
// The default Amplify JS lib version is set for 6 for angular codegen
149+
...(answer.target === 'angular' ? { amplifyJsLibraryVersion: 6 } : {}),
148150
},
149151
};
150152

0 commit comments

Comments
 (0)