fix(api): handle enum casting in GraphQLSelectionSet snapshot#4164
Open
Take111 wants to merge 1 commit intoaws-amplify:mainfrom
Open
fix(api): handle enum casting in GraphQLSelectionSet snapshot#4164Take111 wants to merge 1 commit intoaws-amplify:mainfrom
Take111 wants to merge 1 commit intoaws-amplify:mainfrom
Conversation
GraphQL responses with enum fields store raw String values in the snapshot dictionary, but codegen-generated property accessors cast directly (e.g. `snapshot["status"]! as! PostStatus`), causing a crash. Add convertFieldValues/convertValue helpers to GraphQLSelectionSet that use GraphQLField.type metadata to convert scalar values via JSONDecodable.init(jsonValue:), leveraging the existing RawRepresentable extension for String-to-Enum conversion.
There was a problem hiding this comment.
Pull request overview
Updates the APISwift compatibility fixtures/tests to ensure GraphQL response decoding converts enum raw String values into the expected generated enum types (avoiding runtime as! Enum cast crashes), aligned with the referenced amplify-codegen change.
Changes:
- Add
convertFieldValues/convertValuehelpers toGraphQLSelectionSet.init(from:)to coerce scalar snapshot values usingGraphQLField.typemetadata (including enums viaJSONDecodable). - Add unit tests validating enum decoding for non-optional, optional, null, nested-list, and unknown enum cases.
- Apply the same
GraphQLSelectionSetsnapshot conversion behavior across the APIHostApp generatedAPI.swiftfixtures.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| AmplifyPlugins/API/Tests/AWSAPIPluginTests/APISwiftCompatibility/APISwiftTests.swift | Adds coverage for enum decoding behavior (including unknown/null/nested list cases). |
| AmplifyPlugins/API/Tests/AWSAPIPluginTests/APISwiftCompatibility/API.swift | Enhances GraphQLSelectionSet decoding to convert scalar values (incl. enums) based on selection metadata; adds test-only enum/query types used by the new tests. |
| AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGraphQLUserPoolTests/API.swift | Mirrors the updated GraphQLSelectionSet decoding conversion logic in host app fixture. |
| AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginGraphQLIAMTests/API.swift | Mirrors the updated GraphQLSelectionSet decoding conversion logic in host app fixture. |
| AmplifyPlugins/API/Tests/APIHostApp/AWSAPIPluginFunctionalTests/API.swift | Mirrors the updated GraphQLSelectionSet decoding conversion logic in host app fixture. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Member
|
Hi @Take111, Thank you for your contribution to the AWS Amplify Library! Our team will review your PR and provide feedback soon. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue #
#3953
Related PR in amplify-codegen: aws-amplify/amplify-codegen#991
Description
GraphQL responses with enum fields store raw String values in the snapshot dictionary, but codegen-generated property accessors cast directly (e.g.
snapshot["status"]! as! PostStatus), causing a crash.Add convertFieldValues/convertValue helpers to GraphQLSelectionSet that use GraphQLField.type metadata to convert scalar values via JSONDecodable.init(jsonValue:), leveraging the existing RawRepresentable extension for String-to-Enum conversion.
General Checklist
Given When Theninline code documentation and are named accordinglytestThing_condition_expectation()By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.