diff --git a/Sources/Apollo/GraphQLMap.swift b/Sources/Apollo/GraphQLMap.swift index 21adf543a3..62dd11b5e5 100644 --- a/Sources/Apollo/GraphQLMap.swift +++ b/Sources/Apollo/GraphQLMap.swift @@ -2,7 +2,7 @@ import ApolloAPI #endif -#warning("TODO: Delete") +#warning("TODO: Delete?") public typealias GraphQLMap = [String: JSONEncodable?] fileprivate extension Dictionary where Key == String, Value == JSONEncodable? { diff --git a/Sources/ApolloAPI/CodegenV1/GraphQLOperation.swift b/Sources/ApolloAPI/CodegenV1/GraphQLOperation.swift index 0a03324a85..be010fb6f9 100644 --- a/Sources/ApolloAPI/CodegenV1/GraphQLOperation.swift +++ b/Sources/ApolloAPI/CodegenV1/GraphQLOperation.swift @@ -13,6 +13,7 @@ public protocol GraphQLOperation: AnyObject { var queryDocument: String { get } + #warning("TODO: We need to support setting a null value AND a nil value. Considering just going back to using GraphQLMap, or else this should be [String: GraphQLOptional].") var variables: [String: InputValue]? { get } associatedtype Data: RootSelectionSet diff --git a/Sources/ApolloAPI/InputValue.swift b/Sources/ApolloAPI/InputValue.swift index 571eea7b91..dbb0ea4fa2 100644 --- a/Sources/ApolloAPI/InputValue.swift +++ b/Sources/ApolloAPI/InputValue.swift @@ -1,5 +1,6 @@ import Foundation +#warning("TODO: It might be more performant to just use the raw values like before commit: e7a9b2c27f9d01764943f1aa7ff9d759d8762bff - We should run performance tests and try reverting and see what performance is like.") /// Represents an input value to an argument on a `GraphQLField`'s `FieldArguments`. /// /// - See: [GraphQLSpec - Input Values](http://spec.graphql.org/June2018/#sec-Input-Values) @@ -27,6 +28,20 @@ public indirect enum InputValue { case none } +// MARK: - JSONEncodable + +extension InputValue: JSONEncodable { + public var jsonValue: JSONValue { + switch self { + case let .scalar(value): return value + case let .variable(variableName): return "$\(variableName)" + case let .list(values): return values.map { $0.jsonValue } + case let .object(valueObject): return valueObject.mapValues { $0.jsonValue } + case .none: return NSNull() + } + } +} + // MARK: - InputValueConvertible extension InputValue: InputValueConvertible { diff --git a/Sources/ApolloAPI/ScalarTypes.swift b/Sources/ApolloAPI/ScalarTypes.swift index 584b55e2c5..5a3d311f4b 100644 --- a/Sources/ApolloAPI/ScalarTypes.swift +++ b/Sources/ApolloAPI/ScalarTypes.swift @@ -3,6 +3,7 @@ public protocol AnyScalarType {} public protocol ScalarType: AnyScalarType, JSONDecodable, + JSONEncodable, Cacheable, InputValueConvertible {}