aws-amplify / amplify-swift

A declarative library for application development using cloud services.
Apache License 2.0
455 stars 196 forks source link

Error in pluralization GraphQL Transform code or codegen #1443

Closed sebsto closed 1 year ago

sebsto commented 3 years ago

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:

  1. Create an API with schema
type NoteData
@model
@auth (rules: [ { allow: owner } ]) {
    id: ID!
    name: String!
    description: String
    image: String
}
  1. Write a function to query all notes

    Amplify.API.query(request: .list(NoteData.self)) { event in ...
  2. 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

lawmicha commented 3 years ago

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.

sebsto commented 3 years ago

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

lawmicha commented 3 years ago

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

lawmicha commented 3 years ago

related: https://github.com/aws-amplify/amplify-ios/pull/1451

lawmicha commented 3 years ago
lawmicha commented 1 year ago

Please track https://github.com/aws-amplify/amplify-swift/issues/3135

lawmicha commented 1 year ago

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