GraphQLSwift / Graphiti

The Swift GraphQL Schema framework for macOS and Linux
MIT License
531 stars 67 forks source link

Coders with Date as Double in schema #130

Closed ZirgVoice closed 3 weeks ago

ZirgVoice commented 12 months ago

I use secondsSince1970 to decode and encode date in Coders. In Fluent the createdAt field is of type Date, so that the frontend doesn't have problems I convert it to Double in the schema, and it seems that the standard decoder/encoder deferredToDate starts to be used, because in the response to the request comes 721570737.092619 instead of 1699877937.092619. I also tried converting to String, same result.

Config coders.decoder.dateDecodingStrategy:

    coders.decoder.dateDecodingStrategy = .secondsSince1970
    coders.encoder.dateEncodingStrategy = .secondsSince1970

Field in schema:

            Field("createdAt", at: \.createdAt, as: Double?.self)
            Field("updatedAt", at: \.updatedAt, as: Double?.self)
ZirgVoice commented 3 weeks ago

I believe this is no longer relevant, as we decided not to use Double. The desire to use Double as a date arose due to the thread safety issues with DateFormatter. We've now resolved this problem and are using Date instead.