title: Inline Fragments
Apollo Android supports GraphQL inline fragments. They are not to be confused with regular fragments that are used to reused fields. Inline fragments are used to access polymorphic types:
Hero.graphql
query HeroForEpisode($ep: Episode!) {
hero(episode: $ep) {
name
... on Droid {
primaryFunction
}
... on Human {
height
}
}
}
The Hero class will contain AsDroid
and AsHuman
nested classes to access the Droid fields and human fields respectively:
println("Droid primaryFunction: ${hero.asDroid?.primaryFunction}")
println("Human height: ${hero.asHuman?.height}")