This is a pretty major overhaul that uses a @protected fields approach to dealing with fragment/selection set inheritance.
I've broken the schema and document generators into two plugins. The schema types have protected _{Type}Fields types, which are then exposed via getters and setters by document types like so:
// fragment
mixin Home on Human {
static final String typeName = "Human";
@JsonKey(required: false, disallowNullValue: false)
String get home => fields.homePlanet;
set home(String home) => fields.homePlanet = home;
}
// selection set
@JsonSerializable()
class HeroForEpisodeHumanInlineFragment extends Human with Home {
static final String typeName = "Human";
@JsonKey(required: false, disallowNullValue: false)
double get height => fields.height;
set height(double height) => fields.height = height;
HeroForEpisodeHumanInlineFragment({
double height,
String home,
}) : super(
height: height,
homePlanet: home,
);
@protected
Set<String> get missingRequiredFields {
Set<String> missingFields = Set();
return missingFields;
}
factory HeroForEpisodeHumanInlineFragment.fromJson(
Map<String, dynamic> json) =>
_$HeroForEpisodeHumanInlineFragmentFromJson(json);
Map<String, dynamic> toJson() =>
_$HeroForEpisodeHumanInlineFragmentToJson(this)
..['__typename'] = typeName;
}
I'm thinking about writing a utility wrapper for build_runner that can call https://pub.dev/packages/gql_code_gen and generate ASTs for runtime. Kind of a hassle though
This is a pretty major overhaul that uses a
@protected fields
approach to dealing with fragment/selection set inheritance.I've broken the schema and document generators into two plugins. The schema types have protected
_{Type}Fields
types, which are then exposed via getters and setters by document types like so:The new config looks something like