Skip to content

Commit

Permalink
Remove stripping of null values from Selection Set models (apollograp…
Browse files Browse the repository at this point in the history
AnthonyMDev authored and runner committed Aug 31, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 0692633 commit b44d0b4
Showing 3 changed files with 10 additions and 8 deletions.
1 change: 0 additions & 1 deletion Sources/Apollo/ApolloStore.swift
Original file line number Diff line number Diff line change
@@ -278,7 +278,6 @@ public class ApolloStore {
withKey: key,
variables: variables,
accumulator: GraphQLSelectionSetMapper<SelectionSet>(
stripNullValues: false,
handleMissingValues: .allowForOptionalFields
)
)
13 changes: 9 additions & 4 deletions Sources/Apollo/GraphQLSelectionSetMapper.swift
Original file line number Diff line number Diff line change
@@ -7,7 +7,6 @@ final class GraphQLSelectionSetMapper<T: SelectionSet>: GraphQLResultAccumulator

let requiresCacheKeyComputation: Bool = false

let stripNullValues: Bool
let handleMissingValues: HandleMissingValues

enum HandleMissingValues {
@@ -19,10 +18,8 @@ final class GraphQLSelectionSetMapper<T: SelectionSet>: GraphQLResultAccumulator
}

init(
stripNullValues: Bool = true,
handleMissingValues: HandleMissingValues = .disallow
) {
self.stripNullValues = stripNullValues
self.handleMissingValues = handleMissingValues
}

@@ -48,7 +45,7 @@ final class GraphQLSelectionSetMapper<T: SelectionSet>: GraphQLResultAccumulator
}

func acceptNullValue(info: FieldExecutionInfo) -> AnyHashable? {
return stripNullValues ? nil : Optional<AnyHashable>.none
return DataDict.NullValue
}

func acceptMissingValue(info: FieldExecutionInfo) throws -> AnyHashable? {
@@ -89,3 +86,11 @@ final class GraphQLSelectionSetMapper<T: SelectionSet>: GraphQLResultAccumulator
return T.init(_dataDict: rootValue)
}
}

// MARK: - Null Value Definition
extension DataDict {
/// A common value used to represent a null value in a `DataDict`.
///
/// This value can be cast to `NSNull` and will bridge automatically.
static let NullValue = AnyHashable(Optional<AnyHashable>.none)
}
4 changes: 1 addition & 3 deletions Sources/ApolloAPI/DataDict.swift
Original file line number Diff line number Diff line change
@@ -126,9 +126,7 @@ public struct DataDict: Hashable {
}
}



// MARK: Value Conversion Helpers
// MARK: - Value Conversion Helpers

public protocol SelectionSetEntityValue {
/// - Warning: This function is not supported for external use.

0 comments on commit b44d0b4

Please sign in to comment.