https://kotlinlang.org logo
Title
a

André Thiele

03/21/2021, 2:52 PM
Whats the recommended way to map generated types to domain objects?
t

taso

03/21/2021, 3:00 PM
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

André Thiele

03/21/2021, 3:01 PM
Ok i've seen that before. how do you map them? Do you define extension functions? Unsure how to do this efficiently
t

taso

03/21/2021, 3:03 PM
Extension functions work fine.
a

André Thiele

03/21/2021, 5:02 PM
Are extensions really that great? I see that I would need additional functions for each query I make. Take this one for example:
w

wasyl

03/21/2021, 6:28 PM
@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

André Thiele

03/21/2021, 6:32 PM
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

wasyl

03/21/2021, 6:36 PM
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

André Thiele

03/21/2021, 6:39 PM
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

wasyl

03/21/2021, 6:49 PM
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

André Thiele

03/21/2021, 6:52 PM
ahhhh thats right, yeah i think you can only define them for input parameters
👍 1
my bad