r/FlutterDev • u/graphlinkdev • Nov 02 '26
Video How do you model GraphQL queries that select only some fields in Flutter?
I'm the author of GraphLink, a schema-first code generator for typed GraphQL clients (Dart, Java, Kotlin, TypeScript, Swift), so take this with that in mind.
GraphQL lets the client pick its fields, but a lot of client code still has one model per schema type, and anything you didn't select becomes nullable or missing. For a query that selects id, title and year from Book, GraphLink generates a class with only those three fields, so non-null fields in the schema stay non-null in the client.
I know other generators do something similar for operations. I'd like to hear what works for you, and where this breaks down.
Video (Dart): https://youtu.be/gHGtCBYaj7c
2
u/kalachlegend Nov 02 '26
graphql_codegen generates per-operation classes the same way and i like it. where it gets annoying for me is reuse: the same book shape selected in two queries turns into two unrelated classes, so one BookCard widget can't take both. fragments fix that since the query types implement the fragment type, but then you end up designing fragments around widgets. how does graphlink handle fragments?
1
u/Wise_Phone_4112 Nov 02 '26
Where it breaks down for me is conditional fields. Anything under @include or @skip has to be nullable in the generated class even if the schema says non-null, because the server just leaves it out when the condition is false. Unions and interfaces are the other painful bit: with inline fragments you really want a sealed class per
__typename, plus a fallback case for types that get added to the schema after the app has shipped. How does GraphLink handle those two?1
u/[deleted] Nov 02 '26
[removed] — view removed comment