Skip to content

Commit bc1cefb

Browse files
authored
Merge pull request #886 from aws-amplify/palpatim.chore.prep-release
chore: prep release
2 parents 359533d + 703307a commit bc1cefb

File tree

6 files changed

+104
-28
lines changed

6 files changed

+104
-28
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ List any codegen parameters changed or added.
2929

3030
- [ ] PR description included
3131
- [ ] `yarn test` passes
32+
- [ ] E2E test run linked
3233
- [ ] Tests are [changed or added](https://github.com/aws-amplify/amplify-codegen/blob/main/CONTRIBUTING.md#tests)
3334
- [ ] Relevant documentation is changed or added (and PR referenced)
3435
- [ ] Breaking changes to existing customers are released behind a feature flag or major version update

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@
132132
"parse-url": "^8.1.0",
133133
"graphql": "15.8.0",
134134
"xml2js": "0.5.0",
135-
"axios": "^1.7.4"
135+
"axios": "^1.7.4",
136+
"**/@aws-amplify/amplify-codegen-e2e-tests/**/fast-xml-parser": "^4.4.1"
136137
},
137138
"config": {
138139
"commitizen": {

packages/appsync-modelgen-plugin/src/__tests__/utils/process-index.test.ts

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,78 @@ describe('processIndex', () => {
6868
]);
6969
});
7070

71+
it('support multiple @index directives on a field', () => {
72+
const model: CodeGenModel = {
73+
directives: [
74+
{
75+
name: 'model',
76+
arguments: {},
77+
},
78+
],
79+
name: 'testModel',
80+
type: 'model',
81+
fields: [
82+
{
83+
type: 'field',
84+
isList: false,
85+
isNullable: true,
86+
name: 'connectionField',
87+
directives: [
88+
{
89+
name: 'index',
90+
arguments: {
91+
name: 'byItemAndSortField',
92+
sortKeyFields: ['sortField'],
93+
},
94+
},
95+
{
96+
name: 'index',
97+
arguments: {
98+
name: 'byItemAndAnotherSortField',
99+
sortKeyFields: ['anotherSortField'],
100+
},
101+
},
102+
{
103+
name: 'index',
104+
arguments: {
105+
name: 'byItemAndSomeOtherSortField',
106+
sortKeyFields: ['someOtherSortField'],
107+
},
108+
},
109+
],
110+
},
111+
],
112+
};
113+
processIndex(model);
114+
expect(model.directives).toEqual([
115+
{
116+
name: 'model',
117+
arguments: {},
118+
},
119+
{
120+
name: 'key',
121+
arguments: {
122+
name: 'byItemAndSortField',
123+
fields: ['connectionField', 'sortField'],
124+
},
125+
},
126+
{
127+
name: 'key',
128+
arguments: {
129+
name: 'byItemAndAnotherSortField',
130+
fields: ['connectionField', 'anotherSortField'],
131+
},
132+
},
133+
{
134+
name: 'key',
135+
arguments: {
136+
name: 'byItemAndSomeOtherSortField',
137+
fields: ['connectionField', 'someOtherSortField'],
138+
},
139+
},
140+
]);
141+
});
142+
71143
it('adds simple @index directives as model key attributes', () => {
72144
const model: CodeGenModel = {
73145
directives: [

packages/appsync-modelgen-plugin/src/utils/fieldUtils.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ export function removeFieldFromModel(model: CodeGenModel, fieldName: string): vo
1515
export const getDirective = (fieldOrModel: CodeGenField | CodeGenModel) => (directiveName: string): CodeGenDirective | undefined =>
1616
fieldOrModel.directives.find(d => d.name === directiveName);
1717

18+
export const getDirectives = (fieldOrModel: CodeGenField | CodeGenModel) => (directiveName: string): CodeGenDirective[] | undefined =>
19+
fieldOrModel.directives.filter(d => d.name === directiveName);
20+
1821
// Function matching to GraphQL transformer so that the auto-generated field
1922
export function toCamelCase(words: string[]): string {
2023
const formatted = words.map((w, i) => (i === 0 ? w.charAt(0).toLowerCase() + w.slice(1) : w.charAt(0).toUpperCase() + w.slice(1)));

packages/appsync-modelgen-plugin/src/utils/process-index.ts

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { CodeGenDirective, CodeGenModel } from '../visitors/appsync-visitor';
2-
import { getDirective } from './fieldUtils';
2+
import { getDirectives } from './fieldUtils';
33
import pluralize from 'pluralize';
44
import { toLower, toUpper } from './stringUtils';
55

@@ -9,21 +9,27 @@ import { toLower, toUpper } from './stringUtils';
99
*/
1010
export const processIndex = (model: CodeGenModel) => {
1111
const indexMap = model.fields.reduce((acc, field) => {
12-
const indexDirective = getDirective(field)('index');
13-
if (!indexDirective) {
12+
const indexDirectives = getDirectives(field)('index');
13+
if (!indexDirectives) {
1414
return acc;
1515
}
16-
return { ...acc, [field.name]: indexDirective };
17-
}, {} as Record<string, CodeGenDirective>);
16+
return { ...acc, [field.name]: indexDirectives };
17+
}, {} as Record<string, CodeGenDirective[]>);
18+
19+
const keyList: CodeGenDirective[] = [];
20+
Object.entries(indexMap).forEach(([fieldName, directives]) => {
21+
directives.forEach(directive => {
22+
keyList.push({
23+
name: 'key',
24+
arguments: {
25+
name: directive.arguments.name ?? generateDefaultIndexName(model.name, [fieldName].concat((directive.arguments.sortKeyFields as string[]) ?? [])),
26+
queryField: directive.arguments.queryField,
27+
fields: [fieldName].concat((directive.arguments.sortKeyFields as string[]) ?? []),
28+
},
29+
});
30+
});
31+
});
1832

19-
const keyList: CodeGenDirective[] = Object.entries(indexMap).map(([fieldName, directive]) => ({
20-
name: 'key',
21-
arguments: {
22-
name: directive.arguments.name ?? generateDefaultIndexName(model.name, [fieldName].concat((directive.arguments.sortKeyFields as string[]) ?? [])),
23-
queryField: directive.arguments.queryField,
24-
fields: [fieldName].concat((directive.arguments.sortKeyFields as string[]) ?? []),
25-
},
26-
}));
2733
const existingIndexNames = model.directives
2834
.filter(directive => directive.name === 'key' && !!directive.arguments.name)
2935
.map(directive => directive.arguments.name);

yarn.lock

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9995,9 +9995,9 @@ dotenv@~10.0.0:
99959995
integrity sha512-rlBi9d8jpv9Sf1klPjNfFAuWDjKLwTIJJ/VxtoTwIR6hnZxcEOQCZg2oIL3MWBYw5GpUDKOEnND7LXTbIpQ03Q==
99969996

99979997
dset@^3.1.2:
9998-
version "3.1.3"
9999-
resolved "https://registry.npmjs.org/dset/-/dset-3.1.3.tgz#c194147f159841148e8e34ca41f638556d9542d2"
10000-
integrity sha512-20TuZZHCEZ2O71q9/+8BwKwZ0QtD9D8ObhrihJPr+vLLYlSuAU3/zL4cSlgbfeoGHTjCSJBa7NGcrF9/Bx/WJQ==
9998+
version "3.1.4"
9999+
resolved "https://registry.yarnpkg.com/dset/-/dset-3.1.4.tgz#f8eaf5f023f068a036d08cd07dc9ffb7d0065248"
10000+
integrity sha512-2QF/g9/zTaPDc3BjNcVTGoBbXBgYfMTTceLaYcFJ/W9kggFUkhxD/hMEeuLKbugyef9SqAx8cpgwlIP/jinUTA==
1000110001

1000210002
duplexer@^0.1.1:
1000310003
version "0.1.2"
@@ -10666,17 +10666,10 @@ fast-url-parser@^1.1.3:
1066610666
dependencies:
1066710667
punycode "^1.3.2"
1066810668

10669-
10670-
version "4.2.5"
10671-
resolved "https://registry.npmjs.org/fast-xml-parser/-/fast-xml-parser-4.2.5.tgz#a6747a09296a6cb34f2ae634019bf1738f3b421f"
10672-
integrity sha512-B9/wizE4WngqQftFPmdaMYlXoJlJOYxGQOanC77fq9k8+Z0v5dDSVh+3glErdIROP//s/jgb7ZuxKfB8nVyo0g==
10673-
dependencies:
10674-
strnum "^1.0.5"
10675-
10676-
fast-xml-parser@^4.2.5:
10677-
version "4.3.2"
10678-
resolved "https://registry.npmjs.org/fast-xml-parser/-/fast-xml-parser-4.3.2.tgz#761e641260706d6e13251c4ef8e3f5694d4b0d79"
10679-
integrity sha512-rmrXUXwbJedoXkStenj1kkljNF7ugn5ZjR9FJcwmCfcCbtOMDghPajbc+Tck6vE6F5XsDmx+Pr2le9fw8+pXBg==
10669+
[email protected], fast-xml-parser@^4.2.5, fast-xml-parser@^4.4.1:
10670+
version "4.5.0"
10671+
resolved "https://registry.npmjs.org/fast-xml-parser/-/fast-xml-parser-4.5.0.tgz#2882b7d01a6825dfdf909638f2de0256351def37"
10672+
integrity sha512-/PlTQCI96+fZMAOLMZK4CWG1ItCbfZ/0jx7UIJFChPNrx7tcEgerUgWbeieCM9MfHInUDyK8DWYZ+YrywDJuTg==
1068010673
dependencies:
1068110674
strnum "^1.0.5"
1068210675

0 commit comments

Comments
 (0)