One more - apologies if that's lazyweb :sweat: Are...
# apollo-kotlin
s
One more - apologies if that's lazyweb 😓 Are there any new APIs for generating data builders in 5? I've seen this PR https://github.com/apollographql/apollo-kotlin/pull/6485 but can't really figure out where do I configure builders output (assuming that's released). It seems like data builders has stopped getting generated overall after the migration for us.
m
They are generated in the test source set by default now
s
Oh - that explains it - any way for me to push them out to testFixtures instead?
m
Maybe?
I'm not super familiar with testFixtures but you can rewire using
dataBuildersConnection
👀 1
It's
dataBuildersOutputDirConnection {}
Something like
Copy code
service("service") {
  dataBuildersOutputDirConnection {
    connectToAndroidVariant(TODO())
  }
}
Are you on Android? KMP? JVM?
Bonus question: are you using multi-module?
s
Android only - sorry for late answer. We are multi module but wanted to generate those only in the core module (which contains the schema). That module, however, is Kotlin (jvm)
m
Does Kotlin JVM has testFixtures now?
s
Huh - we enable them through
id 'java-test-fixtures'
plugin 🤔 I forgot that part. For a while I thought that maybe I could just manipulate
outputDir
but that does not seem to be the case - that would be the simplest 😄
m
Just setting the location of
outputDir
isn't enough, you need to configure task dependencies, etc...
This seems to work for me:
Copy code
apollo {
  service("service") {
    packageName.set("com.example")
    generateDataBuilders.set(true)

    dataBuildersOutputDirConnection {
      connectToKotlinSourceSet("testFixtures")
    }
  }
}
s
I see - I must have something else broken then - if I don't set up anything (no
dataBuildersOutputDirConnection
), nothing gets generated, my dataBuildersSource directory is empty:
Just to rule things out -
responseBased
vs
operationBased
generators should not matter here, right?
m
Yea, should not be an issue
I think I found the issue. Can you try disabling the multi-module stuf (remove
dependsOn()
and
generateApolloMetadata.set(true)
)
s
Haha I just opened slack to let you know that I've disabled "generateApolloMetadata = true" and it worked laugh cry face palm
m
Yea, there's a bug introduced in v5 😕 . In the multi-module path, the used coordinates of the root module are not taken into account. I'll look into this a bit later today.
Thanks for raising this
s
Thanks for staying patient with my set of issues - please let me know if there is any way for me to help out with this
m
Oh sure, this is definitely our issue here. Thanks for raising it!
s
qq - are alpha builds also released with a daily preview cadence? E.g.
5.0.0-alpha.3-2025.12.19
?
m
Yes! Although the badge has been out of date for a while. I noticed that just today: https://github.com/apollographql/apollo-kotlin/pull/6814
They are published each night with a specific "preview" workflow. You can follow there: https://github.com/apollographql/apollo-kotlin/actions/workflows/publish-preview.yml
s
Perfect, thanks! I forgot about the badge 🤦 but initially tried what I saw in the docs: https://github.com/apollographql/apollo-kotlin/pull/6817
m
Woops, sorry about that
It doesn't help that our repo doesn't allow listing the versions
s
I'm curious - is this no longer a thing with data builders?
Copy code
SomeQuery.Data {
  someNode = buildSomeNode {
    id = "1"
    user = buildPublicUserNode {
      name = "test"
    }
  }
}
It seems like generated code is now missing
public fun Data(resolver: FakeResolver = DefaultFakeResolver(__Schema.all), block: QueryBuilder.() -> Unit = {}): Data = buildData(
m
Are you in tests?
The data builder code is wired to the test source set by default now
It looks like you are, right?
s
yeah, I see it wired - just not all of it it seems? I see
buildSomeNode
and
buildPublicNode
in my schema module.
SomeQuery
is defined in the consuming module, but there is no
fun Data
present
m
Mmm good question let me check
Aaaaaaah. Of course since they are wired to the test source set of the schema module, they are not visible from the test source sets of the consuming modules....
Damn
You could wire everything to the main source set but that negates the advantage of generating only for tests
Maybe something with test fixtures could work
Quick fix:
Copy code
apollo {
  service("service") {
    packageName.set("com.example")
    generateDataBuilders.set(true)

    dataBuildersOutputDirConnection {
      connectToKotlinSourceSet("main")
    }
  }
}
I'll dig more into that but it might not be before the new year as the christmas break is coming
s
That's alright - thank you for unblocking us so fast 🙇
Just to clarify - in
feature-module
test sources I can access
schema-module
generated testFixtures. `I cannot access query builder (defined in
feature-module
) in
feature-module
tests.
m
The function should be defined as
Copy code
public fun <D : Query.Data> ExecutableDefinition<D>.Data(customScalarAdapters: CustomScalarAdapters = CustomScalarAdapters.Empty, block: QueryBuilder.() -> Unit): D = buildData(
In my sample, it's at
apollo-data-builders/schema/build/generated/dataBuildersSource/apollo/service/foo/builder/QueryBuilder.kt
The
Data
was a regular function of
SomeQuery
before and it's now an extension function that you need to import
s
So I had this within
SomeQuery
(under
feature-module
):
Copy code
public fun Data(resolver: FakeResolver = DefaultFakeResolver(__Schema.all), block: QueryBuilder.() -> Unit = {}): Data = buildData(
  CompiledQuery,
  block,
  SomeQuery_ResponseAdapter.Data,
  SomeQuerySelections.__root,
  "Query",
  resolver,
  __CustomScalarAdapters,
)
Should this now be present in
schema-module
instead? I can't seem to find it 🤔
m
Do you have something at
build/generated/dataBuildersSource/apollo/service/foo/builder/QueryBuilder.kt
?
That file should contain an extension function:
public fun <D : Query.Data> ExecutableDefinition<D>.Data(...)
Because
SomeQuery.Companion
extends
ExecutableDefinition
, you should be able to call
Data
on
SomeQuery
s
Yeah I see that! I wonder why it doesn't gets imported in my IDE
Copy code
public fun <D : Query.Data> ExecutableDefinition<D>.Data(
  resolver: FakeResolver,
  customScalarAdapters: CustomScalarAdapters = CustomScalarAdapters.Empty,
  block: QueryBuilder.() -> Unit = {},
): D = buildData(
  ADAPTER,
  customScalarAdapters,
  QueryBuilder(customScalarAdapters).apply(block).build(),
  ROOT_FIELD.selections,
  "Query",
  resolver,
)
I'll tinker with it a while more
Aaah - I now have to always manually pass a resolver, right
Ah, I think I see the other one too
Sorry for all the fuss - I'll try to make it work and will report back
m
Yea there should be one overload with the default resolver
s
I think it works! Thank you again!
m
Cool! Thanks for the feedback!
s
Can you remove this?
alwaysGenerateTypesMatching.set([])
?
So, uhm - have I effectively started generating code for entire schema by removing that line? I remember it was a part of a multi-module setup to generate only require things
m
It's complicated but if you don't have any downstream dependencies in your schema module, it will effectively generate everything
Some people publish their schema module and in that case there's no other way than either generating all the types or tracking the used types manually