https://kotlinlang.org logo
Title
a

agrosner

02/27/2023, 7:22 PM
a question around data builders. We started using them and am running into errors like
Don't know how to instantiate leaf URL
We have a set of scalar adapters which are correctly fed into the databuilders. in the
fakeResolver
the order of operations is such:
val leafValue = resolver.resolveLeaf(FakeResolverContext(path, id, mergedField))
          if (type is CustomScalarType) {
the
resolver
itself seems to run without any knowledge of scalars in the `DefaultFakeResolver`:
else -> {
        val type = enumTypes.find { it.name == name } ?: error("Don't know how to instantiate leaf $name")
is this expected? I could not find anything in the docs for data builders
im resorting to creating our own. which we will have to feed into all data builder instances. but this seems like a bug?
java.lang.String cannot be cast to ApiURL
"URL" -> faker.internet().url()
seems that the resolveLeaf method also requires we return the correct scalar types from the method. otherwise we get an exception
m

mbonnin

02/27/2023, 9:04 PM
im resorting to creating our own. which we will have to feed into all data builder instances.
That's the way to go, albeit you have to do it at every callsite for now. @Eduard Boloș opened this issue to make it configurable globally
this seems like a bug?
There's no way the DefaultFakeResolver knows how to create a random custom scalar. For an example
Date
or
GeoPoint
or whatnot, this has to be supplied to the lib somehow
he resolveLeaf method also requires we return the correct scalar types from the method. otherwise we get an exception
Indeed, you can use
_context.mergedField.type.rawType()_
to get the type to instantiate
a

agrosner

02/27/2023, 11:38 PM
Its interesting because it has access to the custom scalars class in the data builder which has all the scalar adapters. But yeah the adapters don’t know how to construct them.
Also they’re registered at build time, not runtime
I was going to fetch the adapter and try to pass a buffer value to the adapter method , which requires me to supply way to send different values based on type of field, but i figured it was too complicated so I just hardcoded their construction
m

mbonnin

02/28/2023, 8:57 AM
Yea not an easy problem... Having a global resolver that can be configured with this could help