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

How to Handle Enums in Amplify SDK (Issue with snapshot Casting)? #3953

Open
Take111 opened this issue Jan 27, 2025 · 2 comments
Open

How to Handle Enums in Amplify SDK (Issue with snapshot Casting)? #3953

Take111 opened this issue Jan 27, 2025 · 2 comments
Labels
api Issues related to the API category feature-request Request a new feature

Comments

@Take111
Copy link

Take111 commented Jan 27, 2025

Description

I am updating from the AppSync SDK and using the Swift files generated by the Amplify CLI. However, I am encountering an issue where the parsing of enums fails.

public var status: HogeStatus {
    get {
        return snapshot["status"]! as! HogeStatus // <- fails
    }
    set {
        snapshot.updateValue(newValue, forKey: "status")
    }
}
Error:

Could not cast value of type ‘__NSCFString’ to ‘HogeStatus’.

It seems that snapshot["status"] is being interpreted as a String. In the AppSync SDK, the value is retrieved as an enum, but in Amplify, it becomes a String.

Is there any way to handle this in Amplify to avoid this issue?

In the AppSync SDK, there was logic to handle enums in GraphQLSelectionSetMapper, but I couldn't find a similar feature in Amplify.

Environments

Amplify CLI 12.13.1
Amplify 2.45.4

@github-actions github-actions bot added pending-triage Issue is pending triage pending-maintainer-response Issue is pending response from an Amplify team member labels Jan 27, 2025
@harsh62
Copy link
Member

harsh62 commented Jan 27, 2025

Thank you for raising the feature request with our team. We will take this in our backlog and see if we can prioritize and work on it.

@github-actions github-actions bot removed the pending-maintainer-response Issue is pending response from an Amplify team member label Jan 27, 2025
@harsh62 harsh62 added api Issues related to the API category pending-maintainer-response Issue is pending response from an Amplify team member feature-request Request a new feature and removed pending-triage Issue is pending triage pending-maintainer-response Issue is pending response from an Amplify team member labels Jan 27, 2025
Copy link
Contributor

This has been identified as a feature request. If this feature is important to you, we strongly encourage you to give a 👍 reaction on the request. This helps us prioritize new features most important to you. Thank you!

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 feature-request Request a new feature
Projects
None yet
Development

No branches or pull requests

2 participants