Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
AnthonyMDev committed Sep 21, 2021
1 parent 2a60f6e commit 85f87c5
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 90 deletions.
4 changes: 0 additions & 4 deletions Apollo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@
9FDE0731258F3AA100DC0CA5 /* SchemaLoadingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9F1A96AF258F36B200A06EEB /* SchemaLoadingTests.swift */; };
9FDE0752258F3BC200DC0CA5 /* StarWarsAPI.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9FCE2CFA1E6C213D00E34457 /* StarWarsAPI.framework */; };
9FEB050D1DB5732300DA3B44 /* JSONSerializationFormat.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9FEB050C1DB5732300DA3B44 /* JSONSerializationFormat.swift */; };
9FEC15B41E681DAD00D461B4 /* GroupedSequence.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9FEC15B31E681DAD00D461B4 /* GroupedSequence.swift */; };
9FF90A611DDDEB100034C3B6 /* GraphQLResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9FF90A5B1DDDEB100034C3B6 /* GraphQLResponse.swift */; };
9FF90A651DDDEB100034C3B6 /* GraphQLExecutor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9FF90A5C1DDDEB100034C3B6 /* GraphQLExecutor.swift */; };
9FF90A6F1DDDEB420034C3B6 /* GraphQLMapEncodingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9FF90A6A1DDDEB420034C3B6 /* GraphQLMapEncodingTests.swift */; };
Expand Down Expand Up @@ -789,7 +788,6 @@
9FD03C2D25527CE6002227DC /* StoreConcurrencyTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StoreConcurrencyTests.swift; sourceTree = "<group>"; };
9FD15199255D7F30003BDAAA /* IssuesAndCommentsForRepository.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = IssuesAndCommentsForRepository.json; sourceTree = "<group>"; };
9FEB050C1DB5732300DA3B44 /* JSONSerializationFormat.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JSONSerializationFormat.swift; sourceTree = "<group>"; };
9FEC15B31E681DAD00D461B4 /* GroupedSequence.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GroupedSequence.swift; sourceTree = "<group>"; };
9FF90A5B1DDDEB100034C3B6 /* GraphQLResponse.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GraphQLResponse.swift; sourceTree = "<group>"; };
9FF90A5C1DDDEB100034C3B6 /* GraphQLExecutor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GraphQLExecutor.swift; sourceTree = "<group>"; };
9FF90A6A1DDDEB420034C3B6 /* GraphQLMapEncodingTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GraphQLMapEncodingTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1665,7 +1663,6 @@
9B1CCDD82360F02C007C9032 /* Bundle+Helpers.swift */,
9BE071AC2368D08700FA5952 /* Collection+Helpers.swift */,
9BA3130D2302BEA5007B7FC5 /* DispatchQueue+Optional.swift */,
9FEC15B31E681DAD00D461B4 /* GroupedSequence.swift */,
9F578D8F1D8D2CB300C0EA36 /* HTTPURLResponse+Helpers.swift */,
9F33D6A32566475600A1543F /* PossiblyDeferred.swift */,
DE0586382669985000265760 /* Dictionary+Helpers.swift */,
Expand Down Expand Up @@ -2848,7 +2845,6 @@
9BEEDC2824E351E5001D1294 /* MaxRetryInterceptor.swift in Sources */,
9FC9A9CC1E2FD0760023C4D5 /* Record.swift in Sources */,
9B260BFB245A031900562176 /* NetworkFetchInterceptor.swift in Sources */,
9FEC15B41E681DAD00D461B4 /* GroupedSequence.swift in Sources */,
9F578D901D8D2CB300C0EA36 /* HTTPURLResponse+Helpers.swift in Sources */,
9B260C04245A090600562176 /* RequestChainNetworkTransport.swift in Sources */,
9F7BA89922927A3700999B3B /* ResponsePath.swift in Sources */,
Expand Down
18 changes: 3 additions & 15 deletions Sources/Apollo/ApolloStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,6 @@ import ApolloAPI
public typealias CacheKeyForObject = (_ object: JSONObject) -> JSONValue?
public typealias DidChangeKeysFunc = (Set<CacheKey>, UUID?) -> Void

#warning("TODO: change to return static root CacheReferences")
func rootCacheKey<Operation: GraphQLOperation>(for operation: Operation) -> String {
switch operation.operationType {
case .query:
return "QUERY_ROOT"
case .mutation:
return "MUTATION_ROOT"
case .subscription:
return "SUBSCRIPTION_ROOT"
}
}

protocol ApolloStoreSubscriber: AnyObject {

/// A callback that can be received by subscribers when keys are changed within the database
Expand Down Expand Up @@ -159,7 +147,7 @@ public class ApolloStore {
withinReadTransaction({ transaction in
let (data, dependentKeys) = try transaction.readObject(
ofType: Operation.Data.self,
withKey: rootCacheKey(for: query),
withKey: CacheReference.rootCacheReference(for: query).key,
variables: query.variables,
accumulator: zip(GraphQLSelectionSetMapper<Operation.Data>(),
GraphQLDependencyTracker())
Expand Down Expand Up @@ -189,7 +177,7 @@ public class ApolloStore {

public func read<Query: GraphQLQuery>(query: Query) throws -> Query.Data {
return try readObject(ofType: Query.Data.self,
withKey: rootCacheKey(for: query),
withKey: CacheReference.rootCacheReference(for: query).key,
variables: query.variables)
}

Expand All @@ -214,7 +202,7 @@ public class ApolloStore {

return try executor.execute(selectionSet: type,
on: object,
withKey: key,
withRootCacheReference: CacheReference(key),
variables: variables,
accumulator: accumulator)
}
Expand Down
26 changes: 8 additions & 18 deletions Sources/Apollo/GraphQLExecutor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,17 @@ struct ObjectExecutionInfo {
fileprivate init(
variables: [String: InputValue]?,
schema: SchemaConfiguration.Type,
rootCacheKey: CacheKey? = nil
withRootCacheReference root: CacheReference? = nil
) {
self.variables = variables
self.schema = schema
if let key = rootCacheKey {
cachePath = [String(describing: key)]
if let root = root {
cachePath = [root.key]
}
}

fileprivate mutating func resetCachePath(toCacheKey key: String) {
cachePath = [key]
fileprivate mutating func resetCachePath(toRootCacheReference root: CacheReference) {
cachePath = [root.key]
}
}

Expand Down Expand Up @@ -172,13 +172,13 @@ final class GraphQLExecutor {
func execute<Accumulator: GraphQLResultAccumulator>(
selectionSet: RootSelectionSet.Type,
on data: JSONObject,
withKey key: CacheKey? = nil,
withRootCacheReference root: CacheReference? = nil,
variables: [String: InputValue]? = nil,
accumulator: Accumulator
) throws -> Accumulator.FinalResult {
let info = ObjectExecutionInfo(variables: variables,
schema: selectionSet.schema,
rootCacheKey: key)
withRootCacheReference: root)

let rootValue = execute(selections: selectionSet.selections,
on: data,
Expand Down Expand Up @@ -441,7 +441,7 @@ final class GraphQLExecutor {
// rather than using the inherited cache path from the parent field.
if shouldComputeCachePath,
let cacheKeyForObject = fieldInfo.parentInfo.schema.cacheKey(for: object) {
childExecutionInfo.resetCachePath(toCacheKey: cacheKeyForObject.key)
childExecutionInfo.resetCachePath(toRootCacheReference: cacheKeyForObject)
}
return execute(selections: selections,
Expand All @@ -450,14 +450,4 @@ final class GraphQLExecutor {
accumulator: accumulator)
.map { try accumulator.accept(childObject: $0, info: fieldInfo) }
}
#warning("TODO: Delete - Document in migration log that CacheKey cannot be an array anymore")
// private func cacheKey(for object: JSONObject) -> String? {
// schema.cacheKey(for: object)?.key
// if let array = value as? [Any?] {
// return array.compactMap { String(describing: $0) }.joined(separator: "_")
// } else {
// return String(describing: value)
// }
// }
}
2 changes: 0 additions & 2 deletions Sources/Apollo/GraphQLMap.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,3 @@ public extension GraphQLMapConvertible {
return graphQLMap.withNilValuesRemoved.jsonValue
}
}

public typealias GraphQLID = String
6 changes: 3 additions & 3 deletions Sources/Apollo/GraphQLResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ public final class GraphQLResponse<Data: RootSelectionSet> {

public let body: JSONObject

private let rootKey: String
private let rootKey: CacheReference
private let variables: [String: InputValue]?

public init<Operation: GraphQLOperation>(operation: Operation, body: JSONObject) where Operation.Data == Data {
self.body = body
rootKey = rootCacheKey(for: operation)
rootKey = CacheReference.rootCacheReference(for: operation)
variables = operation.variables
}

Expand Down Expand Up @@ -48,7 +48,7 @@ public final class GraphQLResponse<Data: RootSelectionSet> {

return try executor.execute(selectionSet: Data.self,
on: dataEntry,
withKey: rootKey,
withRootCacheReference: rootKey,
variables: variables,
accumulator: accumulator)
}
Expand Down
43 changes: 0 additions & 43 deletions Sources/Apollo/GroupedSequence.swift

This file was deleted.

13 changes: 13 additions & 0 deletions Sources/ApolloAPI/CodegenV1/CacheReference.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,19 @@ public struct CacheReference: Hashable {
/// A CacheReference referencing the root subscription object.
public static let RootSubscription: CacheReference = CacheReference("SUBSCRIPTION_ROOT")

public static func rootCacheReference<Operation: GraphQLOperation>(
for operation: Operation
) -> CacheReference {
switch operation.operationType {
case .query:
return RootQuery
case .mutation:
return RootMutation
case .subscription:
return RootSubscription
}
}

/// The unique identifier for the referenced object.
///
/// The key for an object must be:
Expand Down
3 changes: 1 addition & 2 deletions Tests/ApolloTests/DefaultInterceptorProviderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ class DefaultInterceptorProviderTests: XCTestCase {

super.tearDown()
}

#warning("These tests may fail if we don't provide a mocked selection set with selections")

func testLoading() {
// given
class GivenSelectionSet: MockSelectionSet {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class GraphQLExecutor_ResultNormalizer_FromResponse_Tests: XCTestCase {
return try GraphQLExecutor_ResultNormalizer_FromResponse_Tests.executor.execute(
selectionSet: selectionSet,
on: object,
withKey: "QUERY_ROOT",
withRootCacheReference: CacheReference.RootQuery,
variables: variables,
accumulator: GraphQLResultNormalizer()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ class GraphQLExecutor_SelectionSetMapper_FromResponse_Tests: XCTestCase {
private func readValues<T: RootSelectionSet>(_ selectionSet: T.Type, from object: JSONObject) throws -> T {
return try GraphQLExecutor_SelectionSetMapper_FromResponse_Tests.executor.execute(
selectionSet: selectionSet,
on: object,
withKey: nil,
on: object,
variables: [:],
accumulator: GraphQLSelectionSetMapper<T>()
)
Expand Down

0 comments on commit 85f87c5

Please sign in to comment.