joreilly / StarWars

Minimal GraphQL based Jetpack Compose, Wear Compose and SwiftUI Kotlin Multiplatform sample (using StarWars endpoint - https://graphql.org/swapi-graphql)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Use of GraphQL fragments as the domain model

yschimke opened this issue · comments

My 2c - using GraphQL directly as the domain model is very productive. Code gen works to make new data available where it needs to be, and avoids writing additional data classes + mapping functions for all these extra cases.

Is there a reason for prefering these data classes?

data class Film(val id: String, val title: String, val director: String)

fun FilmFragment.mapToModel() = Film(id, title, director)

It's a good question and I've experimented with both approaches in various repos. I created this particular project as basis for talks I was giving so had wanted initially to show how data could be mapped like this....but I agree using generated fragment data classes directly is very productive.

I'll take look later at removing those intermediate classes.

addressed by #19