From 7bb04ed730e1cc2a1f673dc8cba5e7c8ef394336 Mon Sep 17 00:00:00 2001 From: Dane Pilcher Date: Mon, 16 Sep 2024 08:36:08 -0600 Subject: [PATCH 1/4] chore: set resolutions for fast-xml-parser scoped to test package (#876) --- package.json | 3 ++- yarn.lock | 15 ++++----------- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index 63d7422c4..14fac5779 100644 --- a/package.json +++ b/package.json @@ -132,7 +132,8 @@ "parse-url": "^8.1.0", "graphql": "15.8.0", "xml2js": "0.5.0", - "axios": "^1.7.4" + "axios": "^1.7.4", + "**/@aws-amplify/amplify-codegen-e2e-tests/**/fast-xml-parser": "^4.4.1" }, "config": { "commitizen": { diff --git a/yarn.lock b/yarn.lock index 98fa3df50..43a2d91d0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -10666,17 +10666,10 @@ fast-url-parser@^1.1.3: dependencies: punycode "^1.3.2" -fast-xml-parser@4.2.5: - version "4.2.5" - resolved "https://registry.npmjs.org/fast-xml-parser/-/fast-xml-parser-4.2.5.tgz#a6747a09296a6cb34f2ae634019bf1738f3b421f" - integrity sha512-B9/wizE4WngqQftFPmdaMYlXoJlJOYxGQOanC77fq9k8+Z0v5dDSVh+3glErdIROP//s/jgb7ZuxKfB8nVyo0g== - dependencies: - strnum "^1.0.5" - -fast-xml-parser@^4.2.5: - version "4.3.2" - resolved "https://registry.npmjs.org/fast-xml-parser/-/fast-xml-parser-4.3.2.tgz#761e641260706d6e13251c4ef8e3f5694d4b0d79" - integrity sha512-rmrXUXwbJedoXkStenj1kkljNF7ugn5ZjR9FJcwmCfcCbtOMDghPajbc+Tck6vE6F5XsDmx+Pr2le9fw8+pXBg== +fast-xml-parser@4.2.5, fast-xml-parser@^4.2.5, fast-xml-parser@^4.4.1: + version "4.5.0" + resolved "https://registry.npmjs.org/fast-xml-parser/-/fast-xml-parser-4.5.0.tgz#2882b7d01a6825dfdf909638f2de0256351def37" + integrity sha512-/PlTQCI96+fZMAOLMZK4CWG1ItCbfZ/0jx7UIJFChPNrx7tcEgerUgWbeieCM9MfHInUDyK8DWYZ+YrywDJuTg== dependencies: strnum "^1.0.5" From 8801359f5b92644e8f65dff61bdd4702253ecdfd Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 16 Sep 2024 08:36:33 -0600 Subject: [PATCH 2/4] build(deps): bump dset from 3.1.3 to 3.1.4 (#877) Bumps [dset](https://github.com/lukeed/dset) from 3.1.3 to 3.1.4. - [Release notes](https://github.com/lukeed/dset/releases) - [Commits](https://github.com/lukeed/dset/compare/v3.1.3...v3.1.4) --- updated-dependencies: - dependency-name: dset dependency-type: indirect ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- yarn.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/yarn.lock b/yarn.lock index 43a2d91d0..4bda1c49e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -9995,9 +9995,9 @@ dotenv@~10.0.0: integrity sha512-rlBi9d8jpv9Sf1klPjNfFAuWDjKLwTIJJ/VxtoTwIR6hnZxcEOQCZg2oIL3MWBYw5GpUDKOEnND7LXTbIpQ03Q== dset@^3.1.2: - version "3.1.3" - resolved "https://registry.npmjs.org/dset/-/dset-3.1.3.tgz#c194147f159841148e8e34ca41f638556d9542d2" - integrity sha512-20TuZZHCEZ2O71q9/+8BwKwZ0QtD9D8ObhrihJPr+vLLYlSuAU3/zL4cSlgbfeoGHTjCSJBa7NGcrF9/Bx/WJQ== + version "3.1.4" + resolved "https://registry.yarnpkg.com/dset/-/dset-3.1.4.tgz#f8eaf5f023f068a036d08cd07dc9ffb7d0065248" + integrity sha512-2QF/g9/zTaPDc3BjNcVTGoBbXBgYfMTTceLaYcFJ/W9kggFUkhxD/hMEeuLKbugyef9SqAx8cpgwlIP/jinUTA== duplexer@^0.1.1: version "0.1.2" From 60dd62993241df56bb4f27afe79e1e7e1956d6ff Mon Sep 17 00:00:00 2001 From: Christopher Sundersingh <83315412+sundersc@users.noreply.github.com> Date: Fri, 20 Sep 2024 14:50:18 -0700 Subject: [PATCH 3/4] fix(amplify-codegen): support multiple indexes on the same field in introspection schema (#879) --- .../src/__tests__/utils/process-index.test.ts | 72 +++++++++++++++++++ .../src/utils/fieldUtils.ts | 3 + .../src/utils/process-index.ts | 32 +++++---- 3 files changed, 94 insertions(+), 13 deletions(-) diff --git a/packages/appsync-modelgen-plugin/src/__tests__/utils/process-index.test.ts b/packages/appsync-modelgen-plugin/src/__tests__/utils/process-index.test.ts index a2c354ff0..b81aa85e5 100644 --- a/packages/appsync-modelgen-plugin/src/__tests__/utils/process-index.test.ts +++ b/packages/appsync-modelgen-plugin/src/__tests__/utils/process-index.test.ts @@ -68,6 +68,78 @@ describe('processIndex', () => { ]); }); + it('support multiple @index directives on a field', () => { + const model: CodeGenModel = { + directives: [ + { + name: 'model', + arguments: {}, + }, + ], + name: 'testModel', + type: 'model', + fields: [ + { + type: 'field', + isList: false, + isNullable: true, + name: 'connectionField', + directives: [ + { + name: 'index', + arguments: { + name: 'byItemAndSortField', + sortKeyFields: ['sortField'], + }, + }, + { + name: 'index', + arguments: { + name: 'byItemAndAnotherSortField', + sortKeyFields: ['anotherSortField'], + }, + }, + { + name: 'index', + arguments: { + name: 'byItemAndSomeOtherSortField', + sortKeyFields: ['someOtherSortField'], + }, + }, + ], + }, + ], + }; + processIndex(model); + expect(model.directives).toEqual([ + { + name: 'model', + arguments: {}, + }, + { + name: 'key', + arguments: { + name: 'byItemAndSortField', + fields: ['connectionField', 'sortField'], + }, + }, + { + name: 'key', + arguments: { + name: 'byItemAndAnotherSortField', + fields: ['connectionField', 'anotherSortField'], + }, + }, + { + name: 'key', + arguments: { + name: 'byItemAndSomeOtherSortField', + fields: ['connectionField', 'someOtherSortField'], + }, + }, + ]); + }); + it('adds simple @index directives as model key attributes', () => { const model: CodeGenModel = { directives: [ diff --git a/packages/appsync-modelgen-plugin/src/utils/fieldUtils.ts b/packages/appsync-modelgen-plugin/src/utils/fieldUtils.ts index 17232fe4a..948d7be5d 100644 --- a/packages/appsync-modelgen-plugin/src/utils/fieldUtils.ts +++ b/packages/appsync-modelgen-plugin/src/utils/fieldUtils.ts @@ -15,6 +15,9 @@ export function removeFieldFromModel(model: CodeGenModel, fieldName: string): vo export const getDirective = (fieldOrModel: CodeGenField | CodeGenModel) => (directiveName: string): CodeGenDirective | undefined => fieldOrModel.directives.find(d => d.name === directiveName); +export const getDirectives = (fieldOrModel: CodeGenField | CodeGenModel) => (directiveName: string): CodeGenDirective[] | undefined => + fieldOrModel.directives.filter(d => d.name === directiveName); + // Function matching to GraphQL transformer so that the auto-generated field export function toCamelCase(words: string[]): string { const formatted = words.map((w, i) => (i === 0 ? w.charAt(0).toLowerCase() + w.slice(1) : w.charAt(0).toUpperCase() + w.slice(1))); diff --git a/packages/appsync-modelgen-plugin/src/utils/process-index.ts b/packages/appsync-modelgen-plugin/src/utils/process-index.ts index dc00d0859..c0492afe2 100644 --- a/packages/appsync-modelgen-plugin/src/utils/process-index.ts +++ b/packages/appsync-modelgen-plugin/src/utils/process-index.ts @@ -1,5 +1,5 @@ import { CodeGenDirective, CodeGenModel } from '../visitors/appsync-visitor'; -import { getDirective } from './fieldUtils'; +import { getDirectives } from './fieldUtils'; import pluralize from 'pluralize'; import { toLower, toUpper } from './stringUtils'; @@ -9,21 +9,27 @@ import { toLower, toUpper } from './stringUtils'; */ export const processIndex = (model: CodeGenModel) => { const indexMap = model.fields.reduce((acc, field) => { - const indexDirective = getDirective(field)('index'); - if (!indexDirective) { + const indexDirectives = getDirectives(field)('index'); + if (!indexDirectives) { return acc; } - return { ...acc, [field.name]: indexDirective }; - }, {} as Record); + return { ...acc, [field.name]: indexDirectives }; + }, {} as Record); + + const keyList: CodeGenDirective[] = []; + Object.entries(indexMap).forEach(([fieldName, directives]) => { + directives.forEach(directive => { + keyList.push({ + name: 'key', + arguments: { + name: directive.arguments.name ?? generateDefaultIndexName(model.name, [fieldName].concat((directive.arguments.sortKeyFields as string[]) ?? [])), + queryField: directive.arguments.queryField, + fields: [fieldName].concat((directive.arguments.sortKeyFields as string[]) ?? []), + }, + }); + }); + }); - const keyList: CodeGenDirective[] = Object.entries(indexMap).map(([fieldName, directive]) => ({ - name: 'key', - arguments: { - name: directive.arguments.name ?? generateDefaultIndexName(model.name, [fieldName].concat((directive.arguments.sortKeyFields as string[]) ?? [])), - queryField: directive.arguments.queryField, - fields: [fieldName].concat((directive.arguments.sortKeyFields as string[]) ?? []), - }, - })); const existingIndexNames = model.directives .filter(directive => directive.name === 'key' && !!directive.arguments.name) .map(directive => directive.arguments.name); From 703307a4ae641d4bffb8b1e0345b2fd820c84b7a Mon Sep 17 00:00:00 2001 From: Dane Pilcher Date: Wed, 25 Sep 2024 15:11:33 -0600 Subject: [PATCH 4/4] docs: add e2e test run to pr checklist (#882) --- .github/PULL_REQUEST_TEMPLATE.md | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index b059683b9..f627a938f 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -29,6 +29,7 @@ List any codegen parameters changed or added. - [ ] PR description included - [ ] `yarn test` passes +- [ ] E2E test run linked - [ ] Tests are [changed or added](https://github.com/aws-amplify/amplify-codegen/blob/main/CONTRIBUTING.md#tests) - [ ] Relevant documentation is changed or added (and PR referenced) - [ ] Breaking changes to existing customers are released behind a feature flag or major version update