hey,
is it possible to instantiate objects from local json (as described here) and yet leverage the custom scalars ?
I have a custom type public typealias Timestamptz = Date
and a custom implementation
extension Date: JSONDecodable, JSONEncodable {
public init(_jsonValue value: JSONValue) throws {
...
where I parse a string into a date. This works as expected when talking to the real graphql server.
However, when I init my object directly using a local json using
let jsonObject = loadJson() // JSONObject
let myObject = MyQuery.Data(data: DataDict(jsonObject, variables: nil))
then access the date property myObject.created_at
I get the exception
Could not cast value of type 'Swift.AnyHashable' (0x10834c1a0) to 'Foundation.Date' (0x106ec74d0).
because the underlying value is indeed still a String
and not a Date
Looking at the sources, I see that this mapping to the custom scalar init is done in the GraphQLSelectionSetMapper.swift#L10-L13
So the question is, how can I parse an graphql local json response into a graphql object for testing purposes?
I know that I could use the new generated Mocks but for my usecase, using the json reponses is more convenient.
thanks for your help