Skip to content

Commit a99d67c

Browse files
authored
fix(amplify-codegen): add correct error msg for flutter codegen (#140)
* fix(amplify-codegen): add correct error msg for flutter codegen * fix lint error
1 parent 2805bb6 commit a99d67c

File tree

4 files changed

+19
-3
lines changed

4 files changed

+19
-3
lines changed

packages/amplify-codegen/src/constants.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ module.exports = {
1919
PROMPT_MSG_SELECT_PROJECT: 'Choose the AppSync API',
2020
PROMPT_MSG_SELECT_REGION: 'Choose AWS Region',
2121
ERROR_CODEGEN_TARGET_NOT_SUPPORTED: 'is not supported by codegen plugin',
22+
ERROR_FLUTTER_CODEGEN_NOT_SUPPORTED: 'Flutter only supports the command $amplify codegen models. All the other codegen commands are not supported.',
2223
ERROR_CODEGEN_FRONTEND_NOT_SUPPORTED: 'The project frontend is not supported by codegen',
2324
ERROR_MSG_MAX_DEPTH: 'Depth should be a integer greater than 0',
2425
ERROR_CODEGEN_NO_API_AVAILABLE: 'There are no GraphQL APIs available.\nAdd by running $amplify api add',

packages/amplify-codegen/src/walkthrough/questions/languageTarget.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ async function askCodeGenTargetLanguage(context, target, withoutInit = false, de
1515
if (!withoutInit) {
1616
frontend = getFrontEndHandler(context);
1717
}
18+
19+
//flutter only supports modelgen but the amplify graphql codegen
20+
if (frontend === 'flutter') {
21+
throw new AmplifyCodeGenNotSupportedError(constants.ERROR_FLUTTER_CODEGEN_NOT_SUPPORTED);
22+
}
23+
1824
const isAngular =
1925
frontend === 'javascript' && getFrontEndFramework(context, withoutInit, decoupleFrontend, decoupleFramework) === 'angular';
2026
const isIonic = frontend === 'javascript' && getFrontEndFramework(context, withoutInit, decoupleFrontend, decoupleFramework) === 'ionic';

packages/amplify-codegen/tests/commands/generateStatementsAndTypes.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,9 @@ describe('command - generateStatementsAndTypes', () => {
102102

103103
it('should show a warning if there are no API metadata', async () => {
104104
getAppSyncAPIDetails.mockReturnValue([]);
105-
const codegenWithoutApiMeta = async () => generateStatementsAndTypes(MOCK_CONTEXT, false);
106-
await expect(codegenWithoutApiMeta).rejects.toBeInstanceOf(AmplifyCodeGenNoAppSyncAPIAvailableError);
107-
await expect(codegenWithoutApiMeta).rejects.toThrowErrorMatchingInlineSnapshot(
105+
const codegenWithoutApiMeta = async () => await generateStatementsAndTypes(MOCK_CONTEXT, false);
106+
expect(codegenWithoutApiMeta).rejects.toBeInstanceOf(AmplifyCodeGenNoAppSyncAPIAvailableError);
107+
expect(codegenWithoutApiMeta).rejects.toThrowErrorMatchingInlineSnapshot(
108108
`"Cannot find API metadata. Please reset codegen by running $amplify codegen remove && amplify codegen add --apiId YOUR_API_ID"`,
109109
);
110110
});

packages/amplify-codegen/tests/walkthrough/questions/languageTarget.test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,13 @@ describe('askCodegenTargetLanguage', () => {
4141
expect(questions[0].name).toEqual('target');
4242
expect(questions[0].choices).toEqual(['javascript', 'typescript', 'flow']);
4343
});
44+
45+
it('should throw error if the frontend is flutter which only supports modelgen', async () => {
46+
getFrontEndHandler.mockReturnValue('flutter');
47+
const codegenWithFlutterFrontend = async () => await askCodegenTargetLanguage(mockContext);
48+
expect(codegenWithFlutterFrontend).rejects.toBeInstanceOf(AmplifyCodeGenNotSupportedError);
49+
expect(codegenWithFlutterFrontend).rejects.toThrowErrorMatchingInlineSnapshot(
50+
`"Flutter only supports the command $amplify codegen models. All the other codegen commands are not supported."`,
51+
);
52+
});
4453
});

0 commit comments

Comments
 (0)