[Legacy] Remove nil values from variables
field in requestBody
#3400
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.
Summary
Fixes an issue in legacy versions of the Apollo SDK. In my testing, this only occurred in my project when working with Xcode 16 Beta. This issue did not occur with previous versions of Xcode.
Apollo version: 0.53.0 (legacy)
Issue Description
I have a GQL query which takes in an optional value as part of the request body. During serialization, I'd hit a
fatalError
in the Apollo library which readsDictionary is only JSONEncodable if Value is (and if Key is String)
(permalink). This occurred because thevariables
dictionary contained a key-value pair where the key was present and the value wasnil
. In this version of Xcode, casting anOptional<Wrapped>
value toWrapped
does not succeed.I don't believe this is an issue in v1.0+ versions of the library, however, we cannot yet upgrade the Apollo version due to this issue.
Proposed Solution
In this PR, I've changed the way that values in the
variables
dictionary are included in therequestBody
. Now, nil values invariables
are removed before serialization. Additionally, if all values invariables
arenil
,variables
won't be included in therequestBody
.