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

.paginatedList() query fails with Model that has name ending in y #1707

Closed
louiss98 opened this issue Mar 24, 2022 · 3 comments
Closed

.paginatedList() query fails with Model that has name ending in y #1707

louiss98 opened this issue Mar 24, 2022 · 3 comments
Labels
bug Something isn't working datastore Issues related to the DataStore category

Comments

@louiss98
Copy link

Describe the bug

On generated Model+Schema files, model.listPluralName is never set causing an undefined field error with paginatedList queries.

Steps To Reproduce

Build api with conflict detection enabled
Create a model with name ending in y : (Story) 
Generate code.
Perform paginated list query on model. Will return error

Expected behavior

Generated Model+Schema to contain a generated listPluralName.

Amplify Framework Version

1.22.0

Amplify Categories

API

Dependency manager

Swift PM

Swift version

4.2

CLI version

7.6.25

Xcode version

13.2.1

Relevant log output

No response

Is this a regression?

No

Regression additional context

No response

Device

iPhone 8 Simulator

iOS Version

iOS 12.1

Specific to simulators

No response

Additional context

Since there is no listPluralName set the query defaults to (queryType.rawValue + name).pluralize() resulting in an invalid field when the model name ends in y. For example Storys as opposed to Stories.

/// The GraphQL directive name translated from a GraphQL query operation and model schema data
func graphQLName(queryType: GraphQLQueryType) -> String {
    let graphQLName: String
    switch queryType {
    case .list:
        if let listPluralName = listPluralName {
            graphQLName = queryType.rawValue + listPluralName
        } else {
            graphQLName = (queryType.rawValue + name).pluralize()
        }
    case .sync:
        if let syncPluralName = syncPluralName {
            graphQLName = queryType.rawValue + syncPluralName
        } else if let pluralName = pluralName {
            graphQLName = queryType.rawValue + pluralName
        } else {
            graphQLName = (queryType.rawValue + name).pluralize()
        }
    case .get:
        graphQLName = queryType.rawValue + name
    }

    return graphQLName
}

ModelSchema file generates a pluralName instead of syncPluralName and listPluralName

@harsh62 harsh62 added datastore Issues related to the DataStore category pending-triage Issue is pending triage labels Mar 24, 2022
@lawmicha
Copy link
Member

lawmicha commented Mar 25, 2022

Hi @louiss98, thank you for bringing this to our attention. I provisioned a backend with a Story model and can reproduce the issue you are seeing. There's actually a reason why the .list case does not use the pluralName in the if statement but does for .sync, the code change added here https://github.com/aws-amplify/amplify-ios/pull/1451/files#diff-421c7d70a341ab77f247ffb14cd2e2b87fdf781bf3470b684c1b6454596788e0 makes it compatible with previous versions of how the provisioning pluralizes the name. I believe V1 transform for list operation does not use the improved pluralization and sync operation does.

If we are seeing Stories in the backend without improvePluralization: true in the cli.json for the list operations then that means the code in the V2 transform that you are using ("transformerversion": 2) has the improved pluralization by default for both list and plural.

The workaround that you described is the correct workaround for now. By manually adding

// model.pluralName = "Stories" // remove this
model.listPluralName = "Stories" // add this for your use case 
model.syncPluralName = "Stories" // this will be generated as well with the fix

Once this CLI fix is released, you can upgrade to the latest CLI and it will generate those fields for you automatically.

@lawmicha lawmicha added the pending-release Code has been merged but pending release Code has been merged but pending release label Mar 25, 2022
@harsh62 harsh62 added the pending-community-response Issue is pending response from the issue requestor label Mar 28, 2022
@atierian atierian added bug Something isn't working and removed pending-community-response Issue is pending response from the issue requestor pending-triage Issue is pending triage labels Mar 28, 2022
@lawmicha lawmicha removed their assignment Oct 31, 2022
@lawmicha
Copy link
Member

Please track #3135

@github-actions github-actions bot removed the pending-release Code has been merged but pending release Code has been merged but pending release label Aug 10, 2023
@lawmicha
Copy link
Member

lawmicha commented Sep 8, 2023

Please use Amplify CLI 12.4.0 or greater to get the fix for the pluralization issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working datastore Issues related to the DataStore category
Projects
None yet
Development

No branches or pull requests

5 participants