Skip to content

Commit 7fceb4f

Browse files
authored
Merge pull request #707 from aws-amplify/main
Release Codegen Plugin
2 parents 74eefdd + 8279f35 commit 7fceb4f

Some content is hidden

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

41 files changed

+3315
-413
lines changed

.codebuild/e2e_workflow.yml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,15 +120,27 @@ batch:
120120
CLI_REGION: ap-northeast-1
121121
depend-on:
122122
- publish_to_local_registry
123-
- identifier: build_app_ts
123+
- identifier: >-
124+
build_app_ts_uninitialized_project_codegen_js_uninitialized_project_modelgen_android_uninitialized_project_modelgen_flutter
124125
buildspec: .codebuild/run_e2e_tests.yml
125126
env:
126127
compute-type: BUILD_GENERAL1_LARGE
127128
variables:
128-
TEST_SUITE: src/__tests__/build-app-ts.test.ts
129+
TEST_SUITE: >-
130+
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
129131
CLI_REGION: ap-southeast-1
130132
depend-on:
131133
- publish_to_local_registry
134+
- identifier: uninitialized_project_modelgen_ios_uninitialized_project_modelgen_js
135+
buildspec: .codebuild/run_e2e_tests.yml
136+
env:
137+
compute-type: BUILD_GENERAL1_LARGE
138+
variables:
139+
TEST_SUITE: >-
140+
src/__tests__/uninitialized-project-modelgen-ios.test.ts|src/__tests__/uninitialized-project-modelgen-js.test.ts
141+
CLI_REGION: ap-southeast-2
142+
depend-on:
143+
- publish_to_local_registry
132144
- identifier: cleanup_e2e_resources
133145
buildspec: .codebuild/cleanup_e2e_resources.yml
134146
env:

packages/amplify-codegen-e2e-core/src/categories/codegen.ts

Lines changed: 94 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,50 @@ export function generateModels(cwd: string, outputDir?: string, settings: { errM
2020
});
2121
}
2222

23-
export function generateStatementsAndTypes(cwd: string) : Promise<void> {
23+
export const generateModelsWithOptions = (cwd: string, options: Record<string, any>): Promise<void> => new Promise((resolve, reject) => {
24+
spawn(getCLIPath(), ['codegen', 'models', ...(Object.entries(options).flat())], { cwd, stripColors: true }).run((err: Error) => {
25+
if (!err) {
26+
resolve();
27+
} else {
28+
reject(err);
29+
}
30+
});
31+
});
32+
33+
export function generateStatementsAndTypes(cwd: string, errorMessage?: string) : Promise<void> {
34+
return new Promise((resolve, reject) => {
35+
const chain = spawn(getCLIPath(), ['codegen'], { cwd, stripColors: true })
36+
37+
if (errorMessage) {
38+
chain.wait(errorMessage);
39+
}
40+
41+
return chain.run((err: Error) => {
42+
if (!err) {
43+
resolve();
44+
} else {
45+
reject(err);
46+
}
47+
})
48+
});
49+
}
50+
51+
export function generateStatements(cwd: string) : Promise<void> {
2452
return new Promise((resolve, reject) => {
25-
spawn(getCLIPath(), ['codegen'], { cwd, stripColors: true })
53+
spawn(getCLIPath(), ['codegen', 'statements'], { cwd, stripColors: true })
54+
.run((err: Error) => {
55+
if (!err) {
56+
resolve();
57+
} else {
58+
reject(err);
59+
}
60+
})
61+
});
62+
}
63+
64+
export function generateTypes(cwd: string) : Promise<void> {
65+
return new Promise((resolve, reject) => {
66+
spawn(getCLIPath(), ['codegen', 'types'], { cwd, stripColors: true })
2667
.run((err: Error) => {
2768
if (!err) {
2869
resolve();
@@ -36,7 +77,10 @@ export function generateStatementsAndTypes(cwd: string) : Promise<void> {
3677
// CLI workflow to add codegen to Amplify project
3778
export function addCodegen(cwd: string, settings: any = {}): Promise<void> {
3879
return new Promise((resolve, reject) => {
39-
const chain = spawn(getCLIPath(), ['codegen', 'add'], { cwd, stripColors: true });
80+
const params = settings.params
81+
? ['codegen', 'add', ...settings.params]
82+
: ['codegen', 'add'];
83+
const chain = spawn(getCLIPath(), params, { cwd, stripColors: true });
4084
if (settings.isAPINotAdded) {
4185
chain.wait("There are no GraphQL APIs available.");
4286
chain.wait("Add by running $amplify api add");
@@ -156,22 +200,26 @@ export function generateModelIntrospection(cwd: string, settings: { outputDir?:
156200
}
157201

158202
// CLI workflow to add codegen to non-Amplify JS project
159-
export function addCodegenNonAmplifyJS(cwd: string): Promise<void> {
203+
export function addCodegenNonAmplifyJS(cwd: string, params: Array<string>, initialFailureMessage?: string): Promise<void> {
160204
return new Promise((resolve, reject) => {
161-
const cmdOptions = ['codegen', 'add', '--apiId', 'mockapiid'];
162-
const chain = spawn(getCLIPath(), cmdOptions, { cwd, stripColors: true });
163-
chain
164-
.wait("Choose the type of app that you're building")
165-
.sendCarriageReturn()
166-
.wait('What javascript framework are you using')
167-
.sendCarriageReturn()
168-
.wait('Choose the code generation language target').sendCarriageReturn()
169-
.wait('Enter the file name pattern of graphql queries, mutations and subscriptions')
170-
.sendCarriageReturn()
171-
.wait('Do you want to generate/update all possible GraphQL operations')
172-
.sendLine('y')
173-
.wait('Enter maximum statement depth [increase from default if your schema is deeply')
174-
.sendCarriageReturn();
205+
const chain = spawn(getCLIPath(), ['codegen', 'add', ...params], { cwd, stripColors: true });
206+
207+
if (initialFailureMessage) {
208+
chain.wait(initialFailureMessage)
209+
} else {
210+
chain
211+
.wait("Choose the type of app that you're building")
212+
.sendCarriageReturn()
213+
.wait('What javascript framework are you using')
214+
.sendCarriageReturn()
215+
.wait('Choose the code generation language target').sendCarriageReturn()
216+
.wait('Enter the file name pattern of graphql queries, mutations and subscriptions')
217+
.sendCarriageReturn()
218+
.wait('Do you want to generate/update all possible GraphQL operations')
219+
.sendLine('y')
220+
.wait('Enter maximum statement depth [increase from default if your schema is deeply')
221+
.sendCarriageReturn();
222+
}
175223

176224
chain.run((err: Error) => {
177225
if (!err) {
@@ -182,3 +230,31 @@ export function addCodegenNonAmplifyJS(cwd: string): Promise<void> {
182230
});
183231
});
184232
}
233+
234+
export function addCodegenNonAmplifyTS(cwd: string, params: Array<string>, initialFailureMessage?: string): Promise<void> {
235+
return new Promise((resolve, reject) => {
236+
const chain = spawn(getCLIPath(), ['codegen', 'add', ...params], { cwd, stripColors: true });
237+
238+
if (initialFailureMessage) {
239+
chain.wait(initialFailureMessage)
240+
} else {
241+
chain
242+
.wait("Choose the type of app that you're building").sendCarriageReturn()
243+
.wait('What javascript framework are you using').sendCarriageReturn()
244+
.wait('Choose the code generation language target').sendKeyDown().sendCarriageReturn()
245+
.wait('Enter the file name pattern of graphql queries, mutations and subscriptions').sendCarriageReturn()
246+
.wait('Do you want to generate/update all possible GraphQL operations').sendLine('y')
247+
.wait('Enter maximum statement depth [increase from default if your schema is deeply').sendCarriageReturn()
248+
.wait('Enter the file name for the generated code').sendCarriageReturn()
249+
.wait('Do you want to generate code for your newly created GraphQL API').sendCarriageReturn();
250+
}
251+
252+
chain.run((err: Error) => {
253+
if (!err) {
254+
resolve();
255+
} else {
256+
reject(err);
257+
}
258+
});
259+
});
260+
}

packages/amplify-codegen-e2e-core/src/utils/frontend-config-helper.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export enum AmplifyFrontend {
22
javascript = 'javascript',
3+
typescript = 'typescript',
34
ios = 'ios',
45
android = 'android',
56
flutter = 'flutter'
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
type Query {
2+
echo: String
3+
}
4+
5+
type Mutation {
6+
mymutation: String
7+
}
8+
9+
type Subscription {
10+
mysub: String
11+
}

0 commit comments

Comments
 (0)