amplify-swift
amplify-swift copied to clipboard
Amplify API query issue for table named Activity
Describe the bug
I created a table named Activity on the amplify console.
I tried to query the data using the query API.
Got failed result with GraphQL service returned a successful response containing errors: [Amplify.GraphQLError(message: “Validation error of type FieldUndefined: Field \‘listActivitys\’ in type \‘Query\’ is undefined @ \‘listActivitys\’“, locations: Optional([Amplify.GraphQLError.Location(line: 2, column: 3)]), path: nil, extensions: nil)]
I checked the GraphQL schema. The schema has listActivities instead of listActivitys.
I worked around the issue by renaming the Activity table to Activity1 and it worked.
Steps To Reproduce
Steps to reproduce the behavior:
1. Create a table name Activity
2. Try to query a list of Activity by Amplify API
Expected behavior
The query does not throw an error.
Amplify Framework Version
1.15.4
Amplify Categories
API
Dependency manager
Swift PM
Swift version
Swift 5.5
CLI version
6.3.1
Xcode version
13
Relevant log output
[Amplify.GraphQLError(message: “Validation error of type FieldUndefined: Field \‘listActivitys\’ in type \‘Query\’ is undefined @ \‘listActivitys\’“, locations: Optional([Amplify.GraphQLError.Location(line: 2, column: 3)]), path: nil, extensions: nil)]
Is this a regression?
No
Regression additional context
No response
Device
Iphone XR
iOS Version
IOS 15
Specific to simulators
No response
Additional context
No response
Hi @muyen, do you have improvePluralization true in cli.json ? Currently we're working on releasing changes to make the codegen compatible with the new pluralization feature and CLI should have this false for new projects. If you can confirm that it is turned on, then we can provide a workaround until the CLI is released with the codegen changes necessary to remove the workaround. The workaround is to add syncPluralName and listPluralName to your Activity+Schema.swift file.
@lawmicha , where is this cli.json? There are many in the project and I didn't find the improvePluralization string in them.
@muyen you should be able to find a cli.json within the amplify folder in your project
your-project-folder/amplify/cli.json.
A cli.json file should have been created in your project amplify folder during its initialization as described here.
If it's not there, is most likely that the feature flag system and cli.json file have been introduced after you've run amplify init to create your project. The cli.json is then associated with the current cloud backend in order to provide a consistent experience across different machines and environments (i.e. dev and CI).
Yes, in my cli.json. It has "improvepluralization": true.
Hi @muyen, I see that you mentioned you are using 1.15.4 with improvepluralization set to true. This should be working since we released changes in the library to use the correct pluralization name (https://github.com/aws-amplify/amplify-ios/pull/1451#issuecomment-960112829). Can you provide us the schema you used and a snippet of the code generated Swift model file Activity+schema.swift ? With the schema, we can reproduce this and see if there's still an issue here. With the snippets, we are checking that you have run amplify codegen models on the schema with the correct output. I suspect that the output may not be correct since the codegen PR is not yet shipped: https://github.com/aws-amplify/amplify-codegen/pull/255
I believe the workaround here is to use set improvepluralization to false. New projects also have this as false since reverting the default to false here: https://github.com/aws-amplify/amplify-cli/pull/8401
Since the codegen changes haven't been released, i'm pretty sure now if you create a new project, improvePluralization is false by default and should work. However, if you want to keep the backend with improvePluralization set to true, we'll keep this issue open while tracking the completion of https://github.com/aws-amplify/amplify-codegen/pull/255
Please track https://github.com/aws-amplify/amplify-swift/issues/3135