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
  • Loading branch information
AnthonyMDev committed Sep 5, 2023
1 parent 888461d commit 18108c3
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 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
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class GraphQLExecutor_SelectionSetMapper_FromResponse_Tests: XCTestCase {
selectionSet: selectionSet,
on: object,
variables: variables,
accumulator: GraphQLSelectionSetMapper<T>(stripNullValues: true)
accumulator: GraphQLSelectionSetMapper<T>()
)
}

Expand Down

0 comments on commit 18108c3

Please sign in to comment.