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

DataStore/API does not work with camelCased model names #1488

Closed
lawmicha opened this issue Oct 25, 2021 · 2 comments
Closed

DataStore/API does not work with camelCased model names #1488

lawmicha opened this issue Oct 25, 2021 · 2 comments
Labels
bug Something isn't working datastore Issues related to the DataStore category

Comments

@lawmicha
Copy link
Contributor

lawmicha commented Oct 25, 2021

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 lawmicha added bug Something isn't working api Issues related to the API category datastore Issues related to the DataStore category labels Oct 25, 2021
@lawmicha lawmicha added the p4 label Jun 8, 2022
@phantumcode phantumcode removed the api Issues related to the API category label Jul 24, 2023
@lawmicha
Copy link
Contributor Author

This has been open for awhile now and without any customer interaction. Searching for related issues, there's #274 and that has been resolved. The problem i described seems easy to work around and doesn't sound like any customer is running into this.

@jcait98
Copy link

jcait98 commented Oct 20, 2023

quick note -- I'm a customer and just ran into this today. Workaround was easy; just would have been nice to see explicit mention in docs of requiring upper case first letter model names

Was stumped by why a table randomly was throwing "Validation error of type UnknownType: Unknown type Create"; after finding this issue page, removing the table completely, running an "amplify push --allow-destructive-graphql-schema-updates
", then adding it back as ModelName and running another "amplify push" succeeded

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

3 participants