a question around data builders. We started using ...
# apollo-kotlin
a
a question around data builders. We started using them and am running into errors like
Copy code
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:
Copy code
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`:
Copy code
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?
Copy code
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
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
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
Yea not an easy problem... Having a global resolver that can be configured with this could help