Skip to content

Commit a3c7ddd

Browse files
authored
Merge pull request #601 from aws-amplify/main
Release
2 parents a9c48c2 + b438232 commit a3c7ddd

File tree

4 files changed

+957
-870
lines changed

4 files changed

+957
-870
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,11 @@
6262
"packages/*"
6363
],
6464
"devDependencies": {
65-
"@aws-amplify/amplify-cli-core": "^4.0.4",
65+
"@aws-amplify/amplify-cli-core": "^4.0.6",
6666
"@commitlint/cli": "^17.0.3",
6767
"@commitlint/config-conventional": "^17.0.3",
6868
"@commitlint/config-lerna-scopes": "^17.0.2",
69+
"@microsoft/api-extractor": "^7.33.5",
6970
"@types/jest": "^27.0.0",
7071
"@types/js-yaml": "^4.0.0",
7172
"@typescript-eslint/eslint-plugin": "^4.0.0",
@@ -95,7 +96,6 @@
9596
"jest-junit": "^12.0.0",
9697
"js-yaml": "^4.0.0",
9798
"lnk": "1.1.0",
98-
"@microsoft/api-extractor": "^7.33.5",
9999
"prettier": "^1.19.1",
100100
"prettier-eslint": "^9.0.1",
101101
"pretty-quick": "^3.1.0",

packages/amplify-codegen/src/codegen-config/AmplifyCodeGenConfig.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
const graphQLConfig = require('graphql-config');
2-
const { isAbsolute, relative } = require('path');
2+
const { isAbsolute, relative, join } = require('path');
33
const slash = require('slash');
44
const { graphQlToAmplifyConfig } = require('./utils');
5+
const fs = require('fs-extra');
56

67
class AmplifyCodeGenConfig {
78
static configFileName = '.graphqlconfig.yml';
@@ -18,7 +19,14 @@ class AmplifyCodeGenConfig {
1819
} else {
1920
projectRoot = process.cwd();
2021
}
21-
this.gqlConfig = graphQLConfig.getGraphQLConfig(projectRoot);
22+
const configPath = join(projectRoot, '.graphqlconfig.yml');
23+
if(fs.existsSync(configPath)) {
24+
this.gqlConfig = graphQLConfig.getGraphQLConfig(projectRoot);
25+
}
26+
else {
27+
this.gqlConfig = new graphQLConfig.GraphQLConfig(null, configPath);
28+
this.gqlConfig.config = {};
29+
}
2230
} else {
2331
throw e;
2432
}

packages/amplify-codegen/tests/codegen-config/AmplifyCodegenConfig.test.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
const AmplifyCodeGenConfig = require('../../src/codegen-config/AmplifyCodeGenConfig');
2+
const fs = require('fs-extra');
3+
const graphQLConfig = require('graphql-config');
4+
5+
jest.mock('fs-extra');
6+
7+
const MOCK_PROJECT_ROOT = 'mockprojectpath';
28

39
describe('AmplifyCodeGenConfig', () => {
410
describe('normalizePath', () => {
@@ -36,4 +42,34 @@ describe('AmplifyCodeGenConfig', () => {
3642
expect(normalizedConfig.extensions.amplify.docsFilePath).toEqual('src/graphql/');
3743
});
3844
});
45+
46+
describe('graphqlconfig file existence', () => {
47+
const err = new graphQLConfig.ConfigNotFoundError('cannot find config file');
48+
49+
beforeEach(() => {
50+
jest.clearAllMocks();
51+
});
52+
53+
it('should return a default with no config file', () => {
54+
jest.spyOn(graphQLConfig, 'getGraphQLConfig').mockImplementation((rootDir) => {
55+
throw err;
56+
});
57+
const configObj = new AmplifyCodeGenConfig(MOCK_PROJECT_ROOT);
58+
expect(configObj?.gqlConfig?.config).toEqual({});
59+
expect(configObj?.getProjects()).toEqual([]);
60+
});
61+
62+
it('should read the config file is one exists instead of defaulting', () => {
63+
const MOCK_CONFIG = { config: { key: 'value' } };
64+
fs.existsSync = jest.fn().mockReturnValue(true);
65+
jest.spyOn(graphQLConfig, 'getGraphQLConfig').mockImplementation((rootDir) => {
66+
if (!rootDir) {
67+
throw err;
68+
}
69+
return MOCK_CONFIG;
70+
});
71+
const configObj = new AmplifyCodeGenConfig(MOCK_PROJECT_ROOT);
72+
expect(configObj?.gqlConfig).toEqual(MOCK_CONFIG);
73+
});
74+
});
3975
});

0 commit comments

Comments
 (0)