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

Feature: Use improved pluralization #255

Closed
wants to merge 1 commit into from

Conversation

marcvberg
Copy link
Contributor

@marcvberg marcvberg commented Oct 7, 2021

Description of changes

Use feature flag to determine whether to set pluralName or listPluralName/syncPluralName

Issue #, if available

aws-amplify/amplify-cli#8350
fix #252

Description of how you validated changes

Unit testing

Manually tested with JS, Android, and iOS applications. Manual tests involved creating Todos through the console as well as through the app, and observing that the data was still available while offline

Checklist

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@marcvberg marcvberg requested a review from a team as a code owner October 7, 2021 21:41
@marcvberg marcvberg requested a review from a team October 7, 2021 21:41
dpilch
dpilch previously approved these changes Oct 8, 2021
@codecov-commenter
Copy link

codecov-commenter commented Oct 8, 2021

Codecov Report

Merging #255 (65e5bfa) into main (181480d) will increase coverage by 0.01%.
The diff coverage is 94.73%.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

@@            Coverage Diff             @@
##             main     #255      +/-   ##
==========================================
+ Coverage   85.69%   85.71%   +0.01%     
==========================================
  Files         148      148              
  Lines        7380     7397      +17     
  Branches     1962     1973      +11     
==========================================
+ Hits         6324     6340      +16     
- Misses        959      960       +1     
  Partials       97       97              
Impacted Files Coverage Δ
...nc-modelgen-plugin/src/visitors/appsync-visitor.ts 96.26% <ø> (ø)
...elgen-plugin/src/visitors/appsync-swift-visitor.ts 96.75% <80.00%> (-0.22%) ⬇️
packages/amplify-codegen/src/commands/models.js 87.40% <100.00%> (+0.09%) ⬆️
...delgen-plugin/src/visitors/appsync-java-visitor.ts 94.87% <100.00%> (+0.06%) ⬆️
...ugin/src/visitors/appsync-json-metadata-visitor.ts 96.07% <100.00%> (+0.20%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Contributor

@AaronZyLee AaronZyLee left a comment

Choose a reason for hiding this comment

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

The codegen logic LGTM. Still I have some concerns on each library change, which need further confirmation with library side.

  • JS(meta): the new attributes are appended instead of replacing the old one so it should not break customers

  • iOS and Android: the original plural field is replaced by two new fields, need library side release first

  • Flutter: we do not receive ticket from flutter and it usually depends on iOS and Android team, not sure if this should be included in this PR. The old plural field is also replaced and it might have impact

Also need a decision on the default feature flag value

manueliglesias
manueliglesias previously approved these changes Oct 8, 2021
Copy link

@manueliglesias manueliglesias left a comment

Choose a reason for hiding this comment

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

LGTM

JS team is OK with this change

@dcipoletti
Copy link

@manueliglesias We advise to hold off on rolling this out. Once the open CLI concerns are resolved and remedied, we will review and proceed.

@lawmicha
Copy link
Member

lawmicha commented Oct 14, 2021

Just a reminder, that codegen PR can be safely merged when the library changes are in for iOS and Android. Please track

There are flutter implications as well. Codeegn changes should be:

  1. No changes to the Flutter dart files (no impact) - do not generate syncPluralName and listPluralName until later
  2. Or generate all 3. add syncPluralName, listPluralName, and pluralName. Need to confirm with Flutter that this works
  3. Or Flutter should take on the iOS and Android changes and any other necessary changes to support the new fields, then codegen can be safely merged

@lawmicha
Copy link
Member

Are there any instructions you could provide to allow the library teams to run this change and generate the model files to make sure it works with the library before merging in the library changes? ie. install development version of the CLI which contains this codegen change so we can run amplify codegen models

@HuiSF
Copy link
Member

HuiSF commented Oct 21, 2021

Just a reminder, that codegen PR can be safely merged when the library changes are in for iOS and Android. Please track

There are flutter implications as well. Codeegn changes should be:

  1. No changes to the Flutter dart files (no impact) - do not generate syncPluralName and listPluralName until later
  2. Or generate all 3. add syncPluralName, listPluralName, and pluralName. Need to confirm with Flutter that this works
  3. Or Flutter should take on the iOS and Android changes and any other necessary changes to support the new fields, then codegen can be safely merged

For amplify-flutter, can go with option 2. Without any changes to be made into amplify-flutter, only the pluralName field will be used, which should still work as native libraries are backwards compatible.

@AaronZyLee
Copy link
Contributor

Are there any instructions you could provide to allow the library teams to run this change and generate the model files to make sure it works with the library before merging in the library changes? ie. install development version of the CLI which contains this codegen change so we can run amplify codegen models

You can follow the instruction here to pull this PR and run yarn setup-dev to build your local amplify-dev for testing. More info

@@ -610,13 +611,18 @@ export class AppSyncModelDartVisitor<
}

protected generateSchemaField(model: CodeGenModel, declarationBlock: DartDeclarationBlock): void {
const pluralFields = this.config.improvePluralization ? `modelSchemaDefinition.listPluralName = "${
Copy link
Contributor

@AaronZyLee AaronZyLee Oct 21, 2021

Choose a reason for hiding this comment

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

As mentioned in the comment, Flutter need option 1 for the change (reverting flutter changes)

Copy link
Member

Choose a reason for hiding this comment

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

Please inform once this required change is complete, I will follow up and test. Thanks!

Copy link
Member

Choose a reason for hiding this comment

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

Correction: amplify-flutter should take the option 1, the dart-visitor should not make any changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@AaronZyLee removed

@lawmicha
Copy link
Member

Are there any instructions you could provide to allow the library teams to run this change and generate the model files to make sure it works with the library before merging in the library changes? ie. install development version of the CLI which contains this codegen change so we can run amplify codegen models

You can follow the instruction here to pull this PR and run yarn setup-dev to build your local amplify-dev for testing. More info

thanks! i got this working with the following:

git remote add marcvberg https://github.com/marcvberg/amplify-codegen
git fetch marcvberg
git checkout -b improved-pluralization marcvberg/improved-pluralization
yarn setup-dev
// back over in the amplify project, run codegen model command to generate new models
cd <amplify project>
amplify-dev codegen models

@lawmicha
Copy link
Member

lawmicha commented Nov 3, 2021

Reminder this PR needs to be updated to remove the dart files changes related to Flutter (@HuiSF's comment #255 (comment))

const pluralAttributes = this.config.improvePluralization ?
{
listPluralName: plurality(model.name, this.config.improvePluralization),
syncPluralName: this.pluralizeModelName(model)
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good catch I think the java visitor needs fixed

lazpavel
lazpavel previously approved these changes Nov 18, 2021
Copy link
Contributor

@lazpavel lazpavel left a comment

Choose a reason for hiding this comment

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

LGTM

@sebsto
Copy link

sebsto commented Nov 28, 2021

hello, any chance to get this in the next CLI release ?

AaronZyLee
AaronZyLee previously approved these changes Nov 30, 2021
Copy link
Contributor

@AaronZyLee AaronZyLee left a comment

Choose a reason for hiding this comment

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

lgtm 🐰

@lawmicha
Copy link
Member

any updates on this?

@harsh62
Copy link
Member

harsh62 commented Mar 22, 2022

@marcvberg following up to see when can we expect this to be closed?

@alharris-at
Copy link
Contributor

alharris-at commented Jun 29, 2022

Hi @marcvberg could you reopen this PR against the main branch?

Nevermind, I was able to update myself. Feel free to ignore.

@alharris-at alharris-at changed the base branch from master to main June 29, 2022 00:10
@alharris-at alharris-at requested a review from a team as a code owner June 29, 2022 00:10
@alharris-at
Copy link
Contributor

@marcvberg let's create an asana task to get this released in the next sprint.

@marcvberg
Copy link
Contributor Author

@alharris-at Added to my tasks

@sebsto
Copy link

sebsto commented Jul 11, 2022

Hello, Any status when this will be merged. It blocks customer projects on this issue aws-amplify/amplify-swift#1443 (opened since Sept. 2021). This PR is open since Oct 2021. Can you help to prioritize this ?

Copy link
Contributor

@AaronZyLee AaronZyLee left a comment

Choose a reason for hiding this comment

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

The failing tests are probably due to the dependency change. You can rebase the main branch (or merge main) with the latest dependency versions and re-build the project.

Copy link
Contributor

@AaronZyLee AaronZyLee left a comment

Choose a reason for hiding this comment

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

Could you add a unit test for the schema.js generated by JS modelgen since the output is changed? Otherwise LGTM

package.json Outdated Show resolved Hide resolved
AaronZyLee
AaronZyLee previously approved these changes Aug 18, 2022
Copy link
Contributor

@AaronZyLee AaronZyLee left a comment

Choose a reason for hiding this comment

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

LGTM. This will be held until the studio CMS using the new model introspection schema as there are new fields introduced in schema.js

@sebsto
Copy link

sebsto commented Oct 13, 2022

Any chance to get this merged before re:Invent ? I am developing a workshop with Amplify. Current workshop instructions asks customer to manually modify the generated code. It would be great is this can be fixed by then. Thanks

@lgtm-com
Copy link

lgtm-com bot commented Oct 14, 2022

This pull request introduces 13 alerts when merging 5539ee5 into 00ba754 - view on LGTM.com

new alerts:

  • 13 for Syntax error

@alharris-at
Copy link
Contributor

@sebsto what platform are you writing your workshop for? We're testing this right now to verify if we're in a good place to merge, but it looks like Android/Flutter still won't have support for improvedPluralization after this PR from my current testing.

@sebsto
Copy link

sebsto commented Oct 20, 2022

@alharris-at workshop is for iOS / Swift
I currently have instructions guiding customers to modify the generated code

(and while I am at it, there is a warning about field ID being deprecated. but I should report that on another issue)

@lawmicha
Copy link
Member

lawmicha commented Oct 27, 2022

@alharris-at workshop is for iOS / Swift I currently have instructions guiding customers to modify the generated code

(and while I am at it, there is a warning about field ID being deprecated. but I should report that on another issue)

the warning about field ID being deprecated is a swift codegen warning. This is related to the new identifier field that is being created for the ability to create customizations of the primary key (renaming / composite, etc). To enable this, you can provide some instructions to the developer to toggle respectprimarykeyattributesonconnectionfield to true in the cli.json file before provisioning the backend (amplify push) and codegenerating the swift models (amplify codegen models)

For reference, the CPK feature docs is located over here aws-amplify/docs#4452

@afern247
Copy link

The last comment on this PR was on October. Is someone actively working on this? I have an open issue reported: aws-amplify/amplify-swift#2460

@sebsto
Copy link

sebsto commented Feb 22, 2023

Thank you @marcvberg for the push. What are the next steps to get this merged ?

Copy link
Contributor

@alharris-at alharris-at left a comment

Choose a reason for hiding this comment

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

Q on the interface, otherwise looks sane to me given we understand the e2e testing a bit more.

@ModelConfig(pluralName = \\"Posts\\", type = Model.Type.USER, version = 1)
@ModelConfig(listPluralName = \\"Posts\\", syncPluralName = \\"Posts\\", type = Model.Type.USER, version = 1)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this a breaking change to no longer also specify the 'pluralName'?

@@ -1845,7 +1845,7 @@ import static com.amplifyframework.core.model.query.predicate.QueryField.field;

/** This is an auto generated class representing the Post type in your schema. */
@SuppressWarnings(\\"all\\")
@ModelConfig(pluralName = \\"Posts\\")
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do some of these not have the type/version as well?

@sebsto
Copy link

sebsto commented Mar 14, 2023

@marcvberg hello Marc, any steps to move forward and review @alharris-at comments above ? Thank you

@sebsto
Copy link

sebsto commented Oct 2, 2023

Looks like this issue has been fixed by aws-amplify/amplify-swift#3135

@dpilch dpilch closed this Dec 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support older version of list query name