Skip to content

Commit 6e8fc03

Browse files
committed
feat: add maxDepth to codegen config api
1 parent 0490776 commit 6e8fc03

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ function getCodegenConfig(projectPath) {
4343
: path.dirname(path.dirname(includeFiles));
4444

4545
const { generatedFileName } = cfg.amplifyExtension || {};
46+
const { maxDepth } = cfg.amplifyExtension || {};
4647

4748
return {
4849
getGeneratedQueriesPath: function() {
@@ -62,6 +63,12 @@ function getCodegenConfig(projectPath) {
6263
return;
6364
}
6465
return path.normalize(generatedFileName);
66+
},
67+
getQueryMaxDepth: function() {
68+
if (!maxDepth || !Number(maxDepth)) {
69+
return;
70+
}
71+
return Number(maxDepth);
6572
}
6673
}
6774
}

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ describe('get codegen configuration', () => {
5757
expect(getConfigReturn.getGeneratedFragmentsPath()).toEqual(path.join('src', 'graphql', 'fragments'));
5858
});
5959

60+
it('returns correct maxDepth as a Number', () => {
61+
fs.existsSync = jest.fn().mockReturnValue(true);
62+
graphQLConfig.getGraphQLConfig = jest.fn().mockReturnValue(MOCK_CODEGEN_CONFIG);
63+
const getConfigReturn = getCodegenConfig(MOCK_PROJECT_ROOT);
64+
expect(getConfigReturn.getQueryMaxDepth()).toEqual(4);
65+
});
66+
6067
it('uses the includes property if the generated documents path does not exist', () => {
6168
const configWithoutDocumentsPath = { ...MOCK_CODEGEN_CONFIG };
6269
delete configWithoutDocumentsPath.config.extensions.amplify.docsFilePath;
@@ -93,4 +100,13 @@ describe('get codegen configuration', () => {
93100
const getConfigReturn = getCodegenConfig(MOCK_PROJECT_ROOT);
94101
expect(getConfigReturn.getGeneratedTypesPath()).toBeUndefined();
95102
});
103+
104+
it('returns undefined if maxDepth does not exist', () => {
105+
const configWithoutMaxDepth = { ...MOCK_CODEGEN_CONFIG };
106+
delete configWithoutMaxDepth.config.extensions.amplify.maxDepth;
107+
fs.existsSync = jest.fn().mockReturnValue(true);
108+
graphQLConfig.getGraphQLConfig = jest.fn().mockReturnValue(configWithoutMaxDepth);
109+
const getConfigReturn = getCodegenConfig(MOCK_PROJECT_ROOT);
110+
expect(getConfigReturn.getQueryMaxDepth()).toBeUndefined();
111+
});
96112
});

0 commit comments

Comments
 (0)