You're viewing documentation for a version of this software that is in development. Switch to the latest stable version
Inline Fragments
Apollo Android supports GraphQL inline fragments. They are not to be confused with named 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}")