Skip to content

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

Open
@Take111

Description

@Take111

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    apiIssues related to the API categoryfeature-requestRequest a new feature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions