amplify-swift icon indicating copy to clipboard operation
amplify-swift copied to clipboard

DataStore/API does not work with camelCased model names

Open lawmicha opened this issue 4 years ago • 0 comments

Describe the bug

DataStore and API does not function properly with model names that start with lower case. For example, DataStore's subscriptions fail to be established, API's .create mutation helper fails.

Steps To Reproduce

  1. Use an input schema where blog is lowercased
type Post @model{
  id: ID!
  title: String!
  description: String
  storageKey: String!
}

type blog @model  {
  id: ID!
  title: String!
  description: String
  storageKey: String!
}
  1. provision the API w/ conflict resolution to test against DataStore and API. (you can without conflict resolution to test against API only- some API GraphQL Builders will only work without conflict resolution enabled since update mutations requires version to be added to the request)

func createBlogAPI() {
        let blog1 = blog(title: "title", description: "description", storageKey: "key")
        
        Amplify.API.mutate(request: .create(blog1)) { event in
            switch event {
            case .success(let result):
                switch result {
                case .success(let blog1):
                    print("Successfully created blog1: \(blog1)")
                case .failure(let error):
                    print("Got failed result with \(error.errorDescription)")
                }
            case .failure(let error):
                print("Got failed event with error \(error)")
            }
        }
    }

Will fail with

Got failed result with GraphQL service returned a successful response containing errors: [Amplify.GraphQLError(message: "Validation error of type UnknownType: Unknown type CreateblogInput", locations: Optional([Amplify.GraphQLError.Location(line: 1, column: 29)]), path: nil, extensions: nil), Amplify.GraphQLError(message: "Validation error of type FieldUndefined: Field \'createblog\' in type \'Mutation\' is undefined @ \'createblog\'", locations: Optional([Amplify.GraphQLError.Location(line: 2, column: 3)]), path: nil, extensions: nil)]
  1. Starting DataStore will fail with
GraphQLResponseError<MutationSync<AnyModel>>: GraphQL service returned a successful response containing errors: [Amplify.GraphQLError(message: "Validation error of type FieldUndefined: Field \'onUpdateblog\' in type \'Subscription\' is undefined @ \'onUpdateblog\'", locations: nil, path: nil, extensions: nil)]


Expected behavior

The name should be capitalized in many different places here:

  1. For queries, the name should be capitalized: https://github.com/aws-amplify/amplify-ios/blob/main/AmplifyPlugins/Core/AWSPluginsCore/Model/Support/ModelSchema+GraphQL.swift#L15

  2. For Mutations as well https://github.com/aws-amplify/amplify-ios/blob/main/AmplifyPlugins/Core/AWSPluginsCore/Model/Support/ModelSchema+GraphQL.swift#L40

  3. for Subscriptions as well https://github.com/aws-amplify/amplify-ios/blob/main/AmplifyPlugins/Core/AWSPluginsCore/Model/Support/ModelSchema+GraphQL.swift#L35

Amplify Framework Version

main

Amplify Categories

DataStore

Dependency manager

Cocoapods

Swift version

N/A

CLI version

N/A

Xcode version

12 / 13

Relevant log output

No response

Is this a regression? (i.e. was this working before a version upgrade)

No response

Device

N/A

iOS Version

N/A

Specific to simulators

No response

Additional context

No response

lawmicha avatar Oct 25 '21 19:10 lawmicha