Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(graphql-transformer-common): pluralization for plural types #7030

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 32 additions & 32 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1077,37 +1077,37 @@ jobs:
environment:
TEST_SUITE: src/__tests__/plugin.test.ts
CLI_REGION: ap-northeast-1
schema-iterative-update-locking-amplify_e2e_tests:
migration-node-function-amplify_e2e_tests:
working_directory: ~/repo
docker: *ref_1
resource_class: large
steps: *ref_4
environment:
TEST_SUITE: src/__tests__/schema-iterative-update-locking.test.ts
TEST_SUITE: src/__tests__/migration/node.function.test.ts
CLI_REGION: ap-southeast-1
migration-node-function-amplify_e2e_tests:
api_4-amplify_e2e_tests:
working_directory: ~/repo
docker: *ref_1
resource_class: large
steps: *ref_4
environment:
TEST_SUITE: src/__tests__/migration/node.function.test.ts
TEST_SUITE: src/__tests__/api_4.test.ts
CLI_REGION: ap-southeast-2
function_5-amplify_e2e_tests:
schema-iterative-update-locking-amplify_e2e_tests:
working_directory: ~/repo
docker: *ref_1
resource_class: large
steps: *ref_4
environment:
TEST_SUITE: src/__tests__/function_5.test.ts
TEST_SUITE: src/__tests__/schema-iterative-update-locking.test.ts
CLI_REGION: us-east-2
api_4-amplify_e2e_tests:
function_5-amplify_e2e_tests:
working_directory: ~/repo
docker: *ref_1
resource_class: large
steps: *ref_4
environment:
TEST_SUITE: src/__tests__/api_4.test.ts
TEST_SUITE: src/__tests__/function_5.test.ts
CLI_REGION: us-west-2
schema-iterative-update-4-amplify_e2e_tests_pkg_linux:
working_directory: ~/repo
Expand Down Expand Up @@ -1719,44 +1719,44 @@ jobs:
TEST_SUITE: src/__tests__/plugin.test.ts
CLI_REGION: ap-northeast-1
steps: *ref_5
schema-iterative-update-locking-amplify_e2e_tests_pkg_linux:
migration-node-function-amplify_e2e_tests_pkg_linux:
working_directory: ~/repo
docker: *ref_1
resource_class: large
environment:
AMPLIFY_DIR: /home/circleci/repo/out
AMPLIFY_PATH: /home/circleci/repo/out/amplify-pkg-linux
TEST_SUITE: src/__tests__/schema-iterative-update-locking.test.ts
TEST_SUITE: src/__tests__/migration/node.function.test.ts
CLI_REGION: ap-southeast-1
steps: *ref_5
migration-node-function-amplify_e2e_tests_pkg_linux:
api_4-amplify_e2e_tests_pkg_linux:
working_directory: ~/repo
docker: *ref_1
resource_class: large
environment:
AMPLIFY_DIR: /home/circleci/repo/out
AMPLIFY_PATH: /home/circleci/repo/out/amplify-pkg-linux
TEST_SUITE: src/__tests__/migration/node.function.test.ts
TEST_SUITE: src/__tests__/api_4.test.ts
CLI_REGION: ap-southeast-2
steps: *ref_5
function_5-amplify_e2e_tests_pkg_linux:
schema-iterative-update-locking-amplify_e2e_tests_pkg_linux:
working_directory: ~/repo
docker: *ref_1
resource_class: large
environment:
AMPLIFY_DIR: /home/circleci/repo/out
AMPLIFY_PATH: /home/circleci/repo/out/amplify-pkg-linux
TEST_SUITE: src/__tests__/function_5.test.ts
TEST_SUITE: src/__tests__/schema-iterative-update-locking.test.ts
CLI_REGION: us-east-2
steps: *ref_5
api_4-amplify_e2e_tests_pkg_linux:
function_5-amplify_e2e_tests_pkg_linux:
working_directory: ~/repo
docker: *ref_1
resource_class: large
environment:
AMPLIFY_DIR: /home/circleci/repo/out
AMPLIFY_PATH: /home/circleci/repo/out/amplify-pkg-linux
TEST_SUITE: src/__tests__/api_4.test.ts
TEST_SUITE: src/__tests__/function_5.test.ts
CLI_REGION: us-west-2
steps: *ref_5
workflows:
Expand Down Expand Up @@ -1854,11 +1854,11 @@ workflows:
- hostingPROD-amplify_e2e_tests
- amplify-app-amplify_e2e_tests
- init-amplify_e2e_tests
- function_5-amplify_e2e_tests
- schema-iterative-update-locking-amplify_e2e_tests
- predictions-amplify_e2e_tests
- schema-predictions-amplify_e2e_tests
- amplify-configure-amplify_e2e_tests
- api_4-amplify_e2e_tests
- function_5-amplify_e2e_tests
- function_3-amplify_e2e_tests
- containers-api-amplify_e2e_tests
- interactions-amplify_e2e_tests
Expand All @@ -1874,22 +1874,22 @@ workflows:
- schema-key-amplify_e2e_tests
- analytics-amplify_e2e_tests
- notifications-amplify_e2e_tests
- schema-iterative-update-locking-amplify_e2e_tests
- migration-node-function-amplify_e2e_tests
- schema-auth-10-amplify_e2e_tests
- hosting-amplify_e2e_tests
- tags-amplify_e2e_tests
- migration-node-function-amplify_e2e_tests
- api_4-amplify_e2e_tests
- done_with_pkg_linux_e2e_tests:
context: amplify-cli-ecr
requires:
- hostingPROD-amplify_e2e_tests_pkg_linux
- amplify-app-amplify_e2e_tests_pkg_linux
- init-amplify_e2e_tests_pkg_linux
- function_5-amplify_e2e_tests_pkg_linux
- schema-iterative-update-locking-amplify_e2e_tests_pkg_linux
- predictions-amplify_e2e_tests_pkg_linux
- schema-predictions-amplify_e2e_tests_pkg_linux
- amplify-configure-amplify_e2e_tests_pkg_linux
- api_4-amplify_e2e_tests_pkg_linux
- function_5-amplify_e2e_tests_pkg_linux
- function_3-amplify_e2e_tests_pkg_linux
- containers-api-amplify_e2e_tests_pkg_linux
- interactions-amplify_e2e_tests_pkg_linux
Expand All @@ -1905,11 +1905,11 @@ workflows:
- schema-key-amplify_e2e_tests_pkg_linux
- analytics-amplify_e2e_tests_pkg_linux
- notifications-amplify_e2e_tests_pkg_linux
- schema-iterative-update-locking-amplify_e2e_tests_pkg_linux
- migration-node-function-amplify_e2e_tests_pkg_linux
- schema-auth-10-amplify_e2e_tests_pkg_linux
- hosting-amplify_e2e_tests_pkg_linux
- tags-amplify_e2e_tests_pkg_linux
- migration-node-function-amplify_e2e_tests_pkg_linux
- api_4-amplify_e2e_tests_pkg_linux
- amplify_migration_tests_latest:
context: amplify-cli-ecr
filters:
Expand Down Expand Up @@ -2059,7 +2059,7 @@ workflows:
filters: *ref_8
requires:
- schema-auth-7-amplify_e2e_tests
- function_5-amplify_e2e_tests:
- schema-iterative-update-locking-amplify_e2e_tests:
context: amplify-cli-ecr
post-steps: *ref_7
filters: *ref_8
Expand Down Expand Up @@ -2119,7 +2119,7 @@ workflows:
filters: *ref_8
requires:
- auth_4-amplify_e2e_tests
- api_4-amplify_e2e_tests:
- function_5-amplify_e2e_tests:
context: amplify-cli-ecr
post-steps: *ref_7
filters: *ref_8
Expand Down Expand Up @@ -2335,7 +2335,7 @@ workflows:
filters: *ref_8
requires:
- schema-searchable-amplify_e2e_tests
- schema-iterative-update-locking-amplify_e2e_tests:
- migration-node-function-amplify_e2e_tests:
context: amplify-cli-ecr
post-steps: *ref_7
filters: *ref_8
Expand Down Expand Up @@ -2389,7 +2389,7 @@ workflows:
filters: *ref_8
requires:
- schema-auth-8-amplify_e2e_tests
- migration-node-function-amplify_e2e_tests:
- api_4-amplify_e2e_tests:
context: amplify-cli-ecr
post-steps: *ref_7
filters: *ref_8
Expand Down Expand Up @@ -2457,7 +2457,7 @@ workflows:
filters: *ref_10
requires:
- schema-auth-7-amplify_e2e_tests_pkg_linux
- function_5-amplify_e2e_tests_pkg_linux:
- schema-iterative-update-locking-amplify_e2e_tests_pkg_linux:
context: amplify-cli-ecr
post-steps: *ref_9
filters: *ref_10
Expand Down Expand Up @@ -2521,7 +2521,7 @@ workflows:
filters: *ref_10
requires:
- auth_4-amplify_e2e_tests_pkg_linux
- api_4-amplify_e2e_tests_pkg_linux:
- function_5-amplify_e2e_tests_pkg_linux:
context: amplify-cli-ecr
post-steps: *ref_9
filters: *ref_10
Expand Down Expand Up @@ -2753,7 +2753,7 @@ workflows:
filters: *ref_10
requires:
- schema-searchable-amplify_e2e_tests_pkg_linux
- schema-iterative-update-locking-amplify_e2e_tests_pkg_linux:
- migration-node-function-amplify_e2e_tests_pkg_linux:
context: amplify-cli-ecr
post-steps: *ref_9
filters: *ref_10
Expand Down Expand Up @@ -2811,7 +2811,7 @@ workflows:
filters: *ref_10
requires:
- schema-auth-8-amplify_e2e_tests_pkg_linux
- migration-node-function-amplify_e2e_tests_pkg_linux:
- api_4-amplify_e2e_tests_pkg_linux:
context: amplify-cli-ecr
post-steps: *ref_9
filters: *ref_10
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ exports[`verify generated templates 16`] = `
$utils.toJson($output[0])"
`;

exports[`verify generated templates 17`] = `"testFilePath/Query.listTomatoess.req.vtl"`;
exports[`verify generated templates 17`] = `"testFilePath/Query.listTomatoes.req.vtl"`;

exports[`verify generated templates 18`] = `
"{
Expand All @@ -104,7 +104,7 @@ exports[`verify generated templates 18`] = `
}"
`;

exports[`verify generated templates 19`] = `"testFilePath/Query.listTomatoess.res.vtl"`;
exports[`verify generated templates 19`] = `"testFilePath/Query.listTomatoes.res.vtl"`;

exports[`verify generated templates 20`] = `"$utils.toJson($utils.rds.toJsonObject($ctx.result)[0])"`;

Expand Down Expand Up @@ -203,7 +203,7 @@ exports[`verify generated templates using a Int primary key 16`] = `
$utils.toJson($output[0])"
`;

exports[`verify generated templates using a Int primary key 17`] = `"testFilePath/Query.listAppless.req.vtl"`;
exports[`verify generated templates using a Int primary key 17`] = `"testFilePath/Query.listApples.req.vtl"`;

exports[`verify generated templates using a Int primary key 18`] = `
"{
Expand All @@ -212,6 +212,6 @@ exports[`verify generated templates using a Int primary key 18`] = `
}"
`;

exports[`verify generated templates using a Int primary key 19`] = `"testFilePath/Query.listAppless.res.vtl"`;
exports[`verify generated templates using a Int primary key 19`] = `"testFilePath/Query.listApples.res.vtl"`;

exports[`verify generated templates using a Int primary key 20`] = `"$utils.toJson($utils.rds.toJsonObject($ctx.result)[0])"`;
6 changes: 4 additions & 2 deletions packages/graphql-transformer-common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@
"dependencies": {
"graphql": "^14.5.8",
"graphql-mapping-template": "4.18.1",
"md5": "^2.2.1"
"md5": "^2.2.1",
"pluralize": "^8.0.0"
},
"devDependencies": {
"@types/md5": "^2.1.33",
"@types/node": "^10.17.13"
"@types/node": "^10.17.13",
"@types/pluralize": "^0.0.29"
},
"jest": {
"transform": {
Expand Down
4 changes: 4 additions & 0 deletions packages/graphql-transformer-common/src/util.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import md5 from 'md5';
import pluralize from 'pluralize';

export function plurality(val: string): string {
if (!val.trim()) {
return '';
}
if (pluralize.isPlural(val.trim())) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this module can actually do the conversion to plural for you. Is there any reason not to use that functionality instead?

Side note: it might be worth putting val.trim() in a variable since it's called a few times now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. I am pushing the changes soon.

return val;
}
return val.concat('s');
}

Expand Down