Are there known issues when attempting to use the ...
# apollo-kotlin
s
Are there known issues when attempting to use the generated data builders alongside custom scalar adapters? In our case, just enabling data builders with no other project changes, the Apollo (4.3.2) generated code fails to compile in several places where scalars should be getting mapped to a
String
.
m
No known issues but that's definitely a bug
Can you share a small reproducer? We definitely have tests with data builders + custom scalars. Sounds like there is more to it
Also worth trying with
5.0.0-alpha.1
, the data builder codegen has been cleaned up there
s
Thanks, everything compiles successfully with
5.0.0-alpha.1
!
m
That's good to hear!
5.0.0
is going to be a very boring release, I don't expect lots of changes there so if you can, I'd recommend using the alphas. If it's a blocker, let me know and we can dig into this
πŸ‘ 1
5.0.0
is major mainly because we need to remove some deprecated thing
But the days when we changed a lot of things in between majors are over
s
Sorry, I'm gonna have to take that back actually – got sidetracked immediately after bumping the Apollo version, but coming back to it I wasn't connecting data builders to the right source set, and once I did I had the same same issue still. I'll try and come up with a reproducer
m
Gotcha, thanks!
s
I've made a fresh minimal project that reproduces the issue: https://github.com/sebj/apollo-kotlin-data-builders-issue-2025-08-06 For me, this fails to compile with the following error:
Copy code
apollo-kotlin-data-builders-issue-2025-08-06/app/build/generated/dataBuildersSource/apollo/service/com/example/myapplication/api/builder/NotificationBuilder.kt:33:34 Property delegate must have a 'setValue(NotificationBuilder, KMutableProperty1<NotificationBuilder, DateTime>, DateTime)' method. None of the following functions is applicable:
fun setValue(thisRef: DataBuilder<*>, property: KProperty<*>, value: String): Unit
thank you color 1
Hopefully I'm not doing something totally silly here πŸ˜…
m
Thank you for sending this! I can totally reproduce.
So it should have this instead:
Copy code
public var createdAt: String by BuilderProperty(StringAdapter)
Alright, that's not 100% it. I forgot to make data builders work with inline value classes πŸ€¦β€β™‚οΈ
That's a tough one. The data builder code isn't straightforward already...
πŸ™ 1
It might take a bit to fix. The workaround is to either not generate inline classes (
extend scalar DateTime @mapTo(builtIn: String, inline: false)
or not generate data builders)
s
Ah thanks, no worries at all! We'll be fine without data builders for now
πŸ‘ 1
Do you have any idea why I might have started getting a task compilation error for the
mapTo
usage in our schema extensions file, once I've added the normalized cache plugin (that I'd managed to forget)?
Copy code
extend schema @link(url: "<https://specs.apollo.dev/kotlin_labs/v0.5/>", import: ["@mapTo", "@typePolicy"])

extend scalar Date @mapTo(builtIn: String)
extend scalar DateTime @mapTo(builtIn: String)
extend scalar Time @mapTo(builtIn: String)

..
Copy code
Execution failed for task ':shared:api:generateServiceApolloSources'.
> A failure occurred while executing com.apollographql.apollo.gradle.internal.GenerateSources
   > e: null: (115, 1): Unexpected 'mapTo' definition. Expecting 'directive @mapTo (builtIn: BuiltIn!, inline: Boolean! = true) on SCALAR'.
m
Sounds like a bug
Adding the normalized cache plugin shouldn't make this fail...
s
I see the same issue if I add the compiler plugin lines to the Apollo service block in the gradle file of the sample project I previously shared earlier in the thread (and remove
generateDataBuilders
):
Copy code
@OptIn(ApolloExperimental::class)
plugin("com.apollographql.cache:normalized-cache-apollo-compiler-plugin:1.0.0-alpha.5") {
    argument("com.apollographql.cache.packageName", packageName.get())
}
m
Mind opening an issue? I can look more this afternoon
s
Sure thing!
m
Thanks!
s
m
Just left a message. Sorry you keep bumping into those nasty issues. At least for this one there is a quick fix
πŸ™ 1
s
No worries, getting there with this πŸ˜… One final thing, I hope, but is there any way to specify this plugin's version via our version catalog that I'm missing? It seems like I have to explicitly write it in full – neither
plugin(libs.apollo.cacheCompilerPlugin)
nor
plugin("com.apollographql.cache:normalized-cache-apollo-compiler-plugin:${libs.versions.apolloCache}")
work as part of the Apollo configuration block, unlike regular dependencies specified elsewhere
m
That's good feedback. Is it OK to ask for an issue about this? That at least sounds easier to fix than the other 2 issues
πŸ‘ 1
m
Thanks!