diff --git a/Apollo.xcodeproj/project.pbxproj b/Apollo.xcodeproj/project.pbxproj index 3deb4baf08..46776e7be8 100644 --- a/Apollo.xcodeproj/project.pbxproj +++ b/Apollo.xcodeproj/project.pbxproj @@ -187,7 +187,6 @@ DE058610266978A100265760 /* InputValue.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9FC9A9C11E2D3CAF0023C4D5 /* InputValue.swift */; }; DE058616266978A100265760 /* GraphQLEnum.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE3C7B14260A6FCA00D2F4FF /* GraphQLEnum.swift */; }; DE05862D2669800000265760 /* Matchable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9BE071AE2368D34D00FA5952 /* Matchable.swift */; }; - DE05862F266980C200265760 /* GraphQLSelectionSet.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9FC9A9C41E2D6CE70023C4D5 /* GraphQLSelectionSet.swift */; }; DE0586332669948500265760 /* InputValue+Evaluation.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE0586322669948500265760 /* InputValue+Evaluation.swift */; }; DE0586362669957800265760 /* CacheReference.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE664ED92666DF150054DB4F /* CacheReference.swift */; }; DE0586372669958F00265760 /* GraphQLError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9FC9A9D21E2FD48B0023C4D5 /* GraphQLError.swift */; }; @@ -775,7 +774,6 @@ 9FC9A9BC1E2C271C0023C4D5 /* RecordSet.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RecordSet.swift; sourceTree = ""; }; 9FC9A9BE1E2C27FB0023C4D5 /* GraphQLResult.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GraphQLResult.swift; sourceTree = ""; }; 9FC9A9C11E2D3CAF0023C4D5 /* InputValue.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InputValue.swift; sourceTree = ""; }; - 9FC9A9C41E2D6CE70023C4D5 /* GraphQLSelectionSet.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GraphQLSelectionSet.swift; sourceTree = ""; }; 9FC9A9C71E2EFE6E0023C4D5 /* CacheKeyForFieldTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CacheKeyForFieldTests.swift; sourceTree = ""; }; 9FC9A9CB1E2FD0760023C4D5 /* Record.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Record.swift; sourceTree = ""; }; 9FC9A9D21E2FD48B0023C4D5 /* GraphQLError.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GraphQLError.swift; sourceTree = ""; }; @@ -1476,7 +1474,6 @@ 9FF90A5C1DDDEB100034C3B6 /* GraphQLExecutor.swift */, DE6B154A261505450068D642 /* GraphQLMap.swift */, 9FA6F3671E65DF4700BF8D73 /* GraphQLResultAccumulator.swift */, - 9FC9A9C41E2D6CE70023C4D5 /* GraphQLSelectionSet.swift */, DE664ED92666DF150054DB4F /* CacheReference.swift */, 9F7BA89822927A3700999B3B /* ResponsePath.swift */, DE0586322669948500265760 /* InputValue+Evaluation.swift */, @@ -2819,7 +2816,6 @@ DE6B156A261505660068D642 /* GraphQLMap.swift in Sources */, 9B554CC4247DC29A002F452A /* TaskData.swift in Sources */, 9B9BBAF524DB4F890021C30F /* AutomaticPersistedQueryInterceptor.swift in Sources */, - DE05862F266980C200265760 /* GraphQLSelectionSet.swift in Sources */, 9BA1244A22D8A8EA00BF1D24 /* JSONSerialization+Sorting.swift in Sources */, 9B260BF1245A025400562176 /* HTTPRequest.swift in Sources */, 9B708AAD2305884500604A11 /* ApolloClientProtocol.swift in Sources */, diff --git a/Sources/Apollo/GraphQLSelectionSet.swift b/Sources/Apollo/GraphQLSelectionSet.swift deleted file mode 100644 index f63e2e3955..0000000000 --- a/Sources/Apollo/GraphQLSelectionSet.swift +++ /dev/null @@ -1,164 +0,0 @@ -#if !COCOAPODS -import ApolloAPI -#endif - -public typealias ResultMap = [String: Any] - -public protocol GraphQLSelectionSet { - static var selections: [GraphQLSelection] { get } - - var resultMap: ResultMap { get } - init(unsafeResultMap: ResultMap) -} - -public extension GraphQLSelectionSet { - init(jsonObject: JSONObject, variables: GraphQLMap? = nil) throws { - self = try decode(selectionSet: Self.self, - from: jsonObject, - variables: variables) - } - - var jsonObject: JSONObject { - return resultMap.jsonObject - } -} - -extension GraphQLSelectionSet { - public init(_ selectionSet: GraphQLSelectionSet) throws { - try self.init(jsonObject: selectionSet.jsonObject) - } -} - -/// For backwards compatibility with legacy codegen. -/// The `GraphQLVariable` class has been replaced by `InputValue.variable` -public func GraphQLVariable(_ name: String) -> InputValue { - return .variable(name) -} - -public protocol GraphQLSelection { -} - -public struct GraphQLField: GraphQLSelection { - let name: String - let alias: String? - let arguments: FieldArguments? - - var responseKey: String { - return alias ?? name - } - - let type: GraphQLOutputType - - public init(_ name: String, - alias: String? = nil, - arguments: FieldArguments? = nil, - type: GraphQLOutputType) { - self.name = name - self.alias = alias - - self.arguments = arguments - - self.type = type - } - - func cacheKey(with variables: [String: JSONEncodable]?) throws -> String { - if - let argumentValues = try arguments?.evaluate(with: variables), - argumentValues.apollo.isNotEmpty { - let argumentsKey = orderIndependentKey(for: argumentValues) - return "\(name)(\(argumentsKey))" - } else { - return name - } - } -} - -public struct FieldArguments: ExpressibleByDictionaryLiteral { - let arguments: InputValue - - public init(dictionaryLiteral elements: (String, InputValue)...) { - arguments = .object(Dictionary(elements, uniquingKeysWith: { (_, last) in last })) - } - - public func evaluate(with variables: [String: JSONEncodable]?) throws -> JSONValue { - return try arguments.evaluate(with: variables) - } - - public func evaluate(with variables: [String: JSONEncodable]?) throws -> JSONObject { - return try arguments.evaluate(with: variables) as! JSONObject - } -} - -public indirect enum GraphQLOutputType { - case scalar(JSONDecodable.Type) - case object([GraphQLSelection]) - case nonNull(GraphQLOutputType) - case list(GraphQLOutputType) - - var namedType: GraphQLOutputType { - switch self { - case .nonNull(let innerType), .list(let innerType): - return innerType.namedType - case .scalar, .object: - return self - } - } -} - -private func orderIndependentKey(for object: JSONObject) -> String { - return object.sorted { $0.key < $1.key }.map { - if let object = $0.value as? JSONObject { - return "[\($0.key):\(orderIndependentKey(for: object))]" - } else if let array = $0.value as? [JSONObject] { - return "\($0.key):[\(array.map { orderIndependentKey(for: $0) }.joined(separator: ","))]" - } else { - return "\($0.key):\($0.value)" - } - }.joined(separator: ",") -} - -public struct GraphQLBooleanCondition: GraphQLSelection { - let variableName: String - let inverted: Bool - let selections: [GraphQLSelection] - - public init(variableName: String, - inverted: Bool, - selections: [GraphQLSelection]) { - self.variableName = variableName - self.inverted = inverted; - self.selections = selections; - } -} - -public struct GraphQLTypeCondition: GraphQLSelection { - let possibleTypes: [String] - let selections: [GraphQLSelection] - - public init(possibleTypes: [String], selections: [GraphQLSelection]) { - self.possibleTypes = possibleTypes - self.selections = selections; - } -} - -public struct GraphQLFragmentSpread: GraphQLSelection { - let fragment: Any.Type -// let fragment: GraphQLFragment.Type - - public init(_ fragment: Any.Type) { - self.fragment = fragment - } -// public init(_ fragment: GraphQLFragment.Type) { -// self.fragment = fragment -// } -} - -public struct GraphQLTypeCase: GraphQLSelection { - let variants: [String: [GraphQLSelection]] - let `default`: [GraphQLSelection] - - public init(variants: [String: [GraphQLSelection]], default: [GraphQLSelection]) { - self.variants = variants - self.default = `default`; - } -}