Skip to content

Commit

Permalink
Remove stripping of null values from Selection Set models (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
AnthonyMDev authored and runner committed Aug 31, 2023
1 parent 0692633 commit b44d0b4
Show file tree
Hide file tree
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
Expand Up @@ -278,7 +278,6 @@ public class ApolloStore {
withKey: key,
variables: variables,
accumulator: GraphQLSelectionSetMapper<SelectionSet>(
stripNullValues: false,
handleMissingValues: .allowForOptionalFields
)
)
Expand Down
13 changes: 9 additions & 4 deletions Sources/Apollo/GraphQLSelectionSetMapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ final class GraphQLSelectionSetMapper<T: SelectionSet>: GraphQLResultAccumulator

let requiresCacheKeyComputation: Bool = false

let stripNullValues: Bool
let handleMissingValues: HandleMissingValues

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

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

Expand All @@ -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? {
Expand Down Expand Up @@ -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
Expand Up @@ -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.
Expand Down

0 comments on commit b44d0b4

Please sign in to comment.