Whats the recommended way to map generated types t...
# apollo-kotlin
a
Whats the recommended way to map generated types to domain objects?
t
We used them as domain objects. That also works because you can define the query and result accordingly. After applying necessary business logic, we converted them to view layer objects.
a
Ok i've seen that before. how do you map them? Do you define extension functions? Unsure how to do this efficiently
t
Extension functions work fine.
a
Are extensions really that great? I see that I would need additional functions for each query I make. Take this one for example:
w
@André Thiele What kind of efficiency are you looking for? How to write least code? We’re keeping separate models for domain objects and yes, we have extensions for all of the types that appear in the queries. We also use fragments heavily, so if several queries reuse a fragment we only need one extension function for it
a
I thought there must be a better way since apollo knows the return type of the queries and could technically utilize default values for the fields that are not requested. But maybe I am thinking a little bit to simple.. Otherwise I think I will try to define some fragments then. Is it possible to define them somewhere in the backend and retrieve them automatically via the schema?
w
apollo knows the return type of the queries and could technically utilize default values for the fields that are not requested
Can you clarify what you’re trying to achieve? The point of GraphQL is to only fetch what’s necessary. If a type in schema has 100 fields, and in the query you only specify 5 of them, then you only get those 5. There’s no backfilling of the 95 of the remaining fields, if you need them you should request them in the queries
a
thats true, but the default values are defined in the schema and are not being fetched so it would be nice to have some sort of toggle
just some thoughts im leaving here
i appreciate the work the team is doing
w
And why would you always want default values for those undefined fields and not actually fetch the proper values from the server?
Btw can the default values be declared in the schema for the types and not only for parameters? I wasn’t aware of that
a
ahhhh thats right, yeah i think you can only define them for input parameters
👍 1
my bad