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

Xcode warnings - 'id' is deprecated: Use .primaryKey(fields:) #3219

Closed
jmhuang12 opened this issue Sep 12, 2023 · 2 comments
Closed

Xcode warnings - 'id' is deprecated: Use .primaryKey(fields:) #3219

jmhuang12 opened this issue Sep 12, 2023 · 2 comments
Labels
api Issues related to the API category question General question

Comments

@jmhuang12
Copy link

Describe the bug

I'm getting a lot of warnings such as:
Screenshot 2023-09-12 at 3 17 27 PM

For the contacts+schema.swift file generated by CLI command "Amplify codegen models".

Screenshot 2023-09-12 at 3 18 22 PM

There was a prior issue opened related to this -> #2460
and was tracked and partially resolved the "pluralName deprecation" by issue -> #3135. However, the "id" deprecation issue doesn't seem to be resolved.

I tried to set the "respectprimarykeyattributesonconnectionfield" flag in the cli.json file to true and run "Amplify push" and then "Amplify codegen models". but i got the same "'id' is deprecated: Use .primaryKey(fields:)" warning.

Screenshot 2023-09-12 at 3 29 45 PM

I also tried to manually change the "contacts+schema.swift" file, by changing ".id()" to ".primaryKey(fields:)" as the warning suggests. however, i got different errors instead.

Screenshot 2023-09-12 at 3 31 48 PM

Steps To Reproduce

Steps to reproduce the behavior:
1. define "contacts" model as below 

import Amplify
import Foundation

public struct Contacts: Model {
  public let id: String
  public var contactId: String
  public var contactName: String
  public var contactProfileImageKey: String
  public var userProfileContactsId: String?
  
  public init(id: String = UUID().uuidString,
      contactId: String,
      contactName: String,
      contactProfileImageKey: String,
      userProfileContactsId: String? = nil) {
      self.id = id
      self.contactId = contactId
      self.contactName = contactName
      self.contactProfileImageKey = contactProfileImageKey
      self.userProfileContactsId = userProfileContactsId
  }
}

2. run cli command  "amplify codegen models" to generate "contacts+schema.swift"

Expected behavior

no warnings generated

Amplify Framework Version

2.17.1

Amplify Categories

API, DataStore

Dependency manager

Swift PM

Swift version

swift 5

CLI version

12.4.0

Xcode version

14.3.1

Relevant log output

<details>
<summary>Log Messages</summary>


INSERT LOG MESSAGES HERE
```

Is this a regression?

Yes

Regression additional context

No response

Platforms

iOS

OS Version

ios 17

Device

iphone11

Specific to simulators

No response

Additional context

No response

@ruisebas
Copy link
Member

Hi @jmhuang12, thanks for opening this issue.

In order to avoid using the deprecated .id() field when generating the models, in addition to setting the feature flag you need to add the @primaryKey tag to the proper attribute in your schema.

For example:

type Contacts @model {
  id: ID! @primaryKey
  contactId: String!
  contactName: String!
  contactProfileImageKey: String!
  contactId: String
}

@ruisebas ruisebas added question General question api Issues related to the API category pending-community-response Issue is pending response from the issue requestor labels Sep 13, 2023
@jmhuang12
Copy link
Author

thank you! i added @PrimaryKey and cli told me to migrate to migrate graphql from v1 to v2, which automatically does it foro me. see https://docs.amplify.aws/cli/migration/transformer-migration/#relationship-mappingconnection-changes

@github-actions github-actions bot removed the pending-community-response Issue is pending response from the issue requestor label Sep 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api Issues related to the API category question General question
Projects
None yet
Development

No branches or pull requests

2 participants