amplify-swift
amplify-swift copied to clipboard
Error in pluralization GraphQL Transform code or codegen
Describe the bug
Hello team,
I am following instructions provided by the Amplify iOS tutorial here
I am running into a strange error with the GraphQL API.
This call in the iOS app
Amplify.API.query(request: .list(NoteData.self)) { event in ...
causes this error
error GraphQL service returned a successful response containing errors: [Amplify.GraphQLError(message: "Validation error of type FieldUndefined: Field \'listNoteDatas\' in type \'Query\' is undefined @ \'listNoteDatas\'", locations: Optional([Amplify.GraphQLError.Location(line: 2, column: 3)]), path: nil, extensions: nil)]
Notice the listNoteDatas
has an extra “s” at the end. The query, as seen from AppSync console, does not have that and
it works in the console.
query MyQuery {
listNoteData {
items {
createdAt
description
id
image
name
owner
updatedAt
}
}
}
The schema is
type NoteData
@model
@auth (rules: [ { allow: owner } ]) {
id: ID!
name: String!
description: String
image: String
}
I am testing with Amplify CLI 6.1.0 on macOS I think this is a regression from Amplify 5.x
Amplify API Plugin 1.14.0
Steps To Reproduce
Steps to reproduce the behavior:
- Create an API with schema
type NoteData
@model
@auth (rules: [ { allow: owner } ]) {
id: ID!
name: String!
description: String
image: String
}
- Write a function to query all notes
Amplify.API.query(request: .list(NoteData.self)) { event in ...
- Build and Run
Expected behavior
The query should return all notes
Amplify Framework Version
1.14.0
Amplify Categories
API
Dependency manager
Cocoapods
Swift version
5.5
CLI version
6.1.0
Xcode version
13
Relevant log output
error GraphQL service returned a successful response containing errors: [Amplify.GraphQLError(message: "Validation error of type FieldUndefined: Field \'listNoteDatas\' in type \'Query\' is undefined @ \'listNoteDatas\'", locations: Optional([Amplify.GraphQLError.Location(line: 2, column: 3)]), path: nil, extensions: nil)]
Is this a regression? (i.e. was this working before a version upgrade)
Yes.
Device
iOS Simulator
iOS Version
15
Specific to simulators
No response
Additional context
No response
Hi @sebsto, thanks for opening this issue. It looks like the library is not compatible with the latest Amplify CLI provisioning of the list query. The investigation can be followed here: aws-amplify/amplify-cli#8350 The workaround right now may be to downgrade to use the provisioning done by the CLI before 5.0.2 which will generate a different list query name that the library is aligned on.
my workaround at the moment is to comment out the .pluralize()
call at line 19 here
https://github.com/aws-amplify/amplify-ios/blob/v1.14.0/AmplifyPlugins/Core/AWSPluginsCore/Model/Support/ModelSchema%2BGraphQL.swift#L19
An easier way to bypass this is to set the feature flag to false
The feature flag to turn off this pluralization is features.graphqltransformer.improvepluralization in your project's amplify/cli.json file.
https://github.com/aws-amplify/amplify-cli/issues/8350#issuecomment-933757747
related: https://github.com/aws-amplify/amplify-ios/pull/1451
- [x] https://github.com/aws-amplify/amplify-ios/pull/1451 library changes have to be released in 1.15.4
- [ ] codegen changes have to be released https://github.com/aws-amplify/amplify-codegen/pull/255 then developer needs to ugprade to the latest CLI and improvePluralization feature can be turned on
Please track https://github.com/aws-amplify/amplify-swift/issues/3135
Please use Amplify CLI 12.4.0 or greater to get the fix for the pluralization issue