How to create custom scalar type for ClosedRange when using Apollo for iOS?

39 views Asked by At

I've implemented a Swift GraphQL web service using Vapor and Graphiti which has a custom schema for ClosedRange<Double> which is encoded into an array of two Doubles [5, 8].

On the client side I'm using Apollo for iOS and have tried to implement the custom scehma decoding by conforming ClosedRange<Double> to CustomScalarType but I get the error:

Conditional conformance of type 'ClosedRange' to protocol 'CustomScalarType' does not imply conformance to inherited protocol 'AnyHashableConvertible'

// @generated
// This file was automatically generated and should not be edited.

import ApolloAPI
import Foundation

public extension ClientAPI {
  typealias DoubleClosedRange = ClosedRange<Double>
}

extension ClosedRange<Double>: CustomScalarType {
    public init(_jsonValue value: JSONValue) throws {
        guard let elements = value as? [Double] else {
            throw JSONDecodingError.couldNotConvert(value: value, to: [Double].self)
        }

        self = ClosedRange(uncheckedBounds: (lower: elements[0], upper: elements[1]))
    }

    public var _jsonValue: JSONValue {
        [lowerBound, upperBound]
    }
}

I'm not sure I really understand the error, I've created conformance for other Foundation types like URL in the same way without issues.

0

There are 0 answers