apollographql / apollo-kotlin

:rocket:  A strongly-typed, caching GraphQL client for the JVM, Android, and Kotlin multiplatform.
https://www.apollographql.com/docs/kotlin
MIT License
3.76k stars 653 forks source link

Support for `DateTime` custom scalar #4736

Open martinbonnin opened 1 year ago

martinbonnin commented 1 year ago

Use case

The DateTime scalar is specified at https://scalars.graphql.org/andimarek/date-time

If the codegen schema contains such a scalar:

scalar DateTime @specifiedBy(url: "https://scalars.graphql.org/andimarek/date-time")

We could detect it at build time automatically and map it to kotlinx.datetime.DateTime

Pros:

Cons:

Questions:

BoD commented 1 year ago

pulls kotlinx-datetime in the dependencies

Because of this it would probably be preferable to keep it as an opt-in IMHO. So opt-in could be 2 steps: 1. set some flag to true 2. add the dependency(ies)

martinbonnin commented 1 year ago

Because of this it would probably be preferable to keep it as an opt-in IMHO

Just to be clear, the proposal is to pull kotlinx-datetime only if the schema contains DateTime scalars. All other users would be non-affected

martinbonnin commented 1 year ago

Just to be clear, the proposal is to pull kotlinx-datetime only if the schema contains DateTime scalars. All other users would be non-affected

Although that would require parsing the schema at Gradle configuration time which doesn't sound great. But maybe acceptable 🤷

BoD commented 3 months ago

To check: is one of the current adapters we have over here already compatible with https://scalars.graphql.org/andimarek/date-time?