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

Fix selection set value serialization when writing to cache #2778

Merged
merged 1 commit into from
Jan 14, 2023

Conversation

AnthonyMDev
Copy link
Contributor

Fixes #2775

When writing a SelectionSets data back into the cache, custom scalars need to re-encoded into their _jsonValue. Since we don't want to have to do this when writing network response data (which is already properly serialized JSON) we created a new normalizer and a factory to return the proper normalizer based on the data source.

@netlify
Copy link

netlify bot commented Jan 13, 2023

Deploy Preview for apollo-ios-docs canceled.

Name Link
🔨 Latest commit 596eb46
🔍 Latest deploy log https://app.netlify.com/sites/apollo-ios-docs/deploys/63c1cad871317d00089f78fa

struct ResultNormalizerFactory {
private init() {}

static func selectionSetDataNormalizer() -> SelectionSetDataResultNormalizer {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I decided to create separate functions rather than normalizer(for: DataSource) because this way, each function returns the concrete type (instead of BaseGraphQLResultNormalizer). This allows the generic functions in the GraphQLExecutor to still specialize the function calls, using static dispatch instead of dynamic dispatch.

Copy link
Member

@calvincestari calvincestari left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work, I think we settled on the right solution here.

@AnthonyMDev AnthonyMDev merged commit 5a06e6b into main Jan 14, 2023
@AnthonyMDev AnthonyMDev deleted the fix-enum-serialization-bug branch January 14, 2023 00:58
@calvincestari calvincestari mentioned this pull request Feb 8, 2023
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

LocalCacheMutation with an enum field fails with Invalid type in JSON write
2 participants