Apollo iOS 1.22.0 always converts Date variables to UTC, dropping their original time zone information

Description
When I send a Date object using Apollo 1.22.0, it’s automatically converted to UTC, so we lose the client’s time zone and the backend misses that potentially useful information. We could pre-format dates as strings, but that would require an API change. I was hoping to configure Apollo to use a custom DateFormatter, but I couldn’t find any such option.

Question
Is there a way in Apollo iOS 1.22.0 to plug in a custom DateFormatter (or other hook) so that Date variables retain their original time zone when encoded? If not, what workarounds—such as custom interceptors, scalar wrappers, or codegen tweaks—are currently recommended to preserve time zone data without changing the server API?

Hi @p_lizak - when you say you “send a Date object” how are you doing that? What is the Date serialized as when it’s sent to the server?

I ask because Apollo iOS has no notion of the Date type. The library is familiar with GraphQL built-in scalars and JSON types. Anything beyond those types is for your code to ensure the correct handling and serialization.

It sounds like what you need is to implement a Custom Scalar for the Date type and values. If you’re already doing that and still having problems I recommend opening an issue on the repo and we can discuss it there.

1 Like

@calvincestari thanks for your reply! You’re right — I didn’t have the full context. The date I was referring to was just a locale-specific format we use. Indeed, the custom scalar solution is the way to go, where I can define the date formatter before converting it to a string. Thanks for pointing me in the right direction!