Hello hello! We are migrating to apollo 4 and we a...
# apollo-kotlin
m
Hello hello! We are migrating to apollo 4 and we are seeing some issues with our tests ( involving data builders and fragment builders) 🧵
val appointmentInfo = AppointmentInfoImpl.Data(KrakenFieldFakeResolver()) { buildFieldUserAppointmentType { id = "appointmentId" notes = "test-notes" assetProviderData = buildAssetProviderDataType { assetProvider = "" commsHubVariant = "" } } } val sut = appointmentInfo.assetProviderData?.assetProviderInfo() Assert.assertEquals(null, sut) This text suddenly stoped passing and for what we have inspected its because the values assigned on the blocks are not actually re values in the resulting appointmentINfo class. After some debuggin we can see that the resulting values in
buildFieldUserAppointmentType
are correct but the result of
AppointmentInfoImpl.Data(KrakenFieldFakeResolver())
is ignoring the values and using defaults
m
Let me see if I can reproduce
so
notes
is not good up there?
m
We are expecting
test-notes
right?
m
Yes, I would expect this as well
Is it still happening if you remove the
KrakenFieldFakeResolver()
?
j
we get following in that case
Copy code
Don't know how to instantiate leaf UUID
java.lang.IllegalStateException: Don't know how to instantiate leaf UUID
	at com.apollographql.apollo.api.DefaultFakeResolver.resolveLeaf(fakeResolver.kt:280)
m
Ok gotcha 👍 Looks like you’re not using the result of
buildFieldUserAppointmentType
, does that need to be set to some field?
Something like this?
Copy code
val appointmentInfo = AppointmentInfoImpl.Data(KrakenFieldFakeResolver()) {
    userAppointment = buildFieldUserAppointmentType {
        id = "appointmentId"
        notes = "test-notes"
        // ...
    }
}
j
so just tried following and it passed
Copy code
val appointmentInfo = AppointmentInfoImpl.Data(KrakenFieldFakeResolver()) {
//            buildFieldUserAppointmentType {
                id = "appointmentId"
                notes = "test-notes"
                assetProviderData = buildAssetProviderDataType {
                    assetProvider = ""
                    commsHubVariant = ""
                }
//            }
        }
buildFieldUserAppointmentType
not needed any more it seems?
m
I’m curious how come it was need before actually, the
buildFoo()
return value is really supposed to be used 🤔
j
I think change in 4.0 in way that those blocks are applied?
m
Looks like it
I’ll dig
This doesn’t happen to be a public schema by any chance?
m
Copy code
public
    fun BuilderScope.buildFieldUserAppointmentType(block: FieldUserAppointmentTypeBuilder.() -> Unit):
    FieldUserAppointmentTypeMap {
  val builder = FieldUserAppointmentTypeBuilder(customScalarAdapters)
  builder.__typename = "FieldUserAppointmentType"
  builder.block()
  return builder.build()
}
this in 3.8.4
👀 1
j
and this is in 4.0
Copy code
public
    fun BuilderScope.buildFieldUserAppointmentType(block: FieldUserAppointmentTypeBuilder.() -> Unit):
    FieldUserAppointmentTypeMap =
    FieldUserAppointmentTypeBuilder(customScalarAdapters).apply(block).build()
👀 1
m
That’s a good callout, we should have included that in the migration guide.
👍 1
🙌 1
For fragments, the top level
buildFoo {}
is not needed anymore, sorry I forgot it was like this in v3
m
yep all makes sense now! thanks!
m
Also took this opportunity to add some docs for fragments, just realized we had none
m
Ah yes! I was looking for it when trying to see if we screwed somethign with the migration and could not find it
👏