Join us for GraphQL Summit, October 10-12 in San Diego. Use promo code ODYSSEY for $400 off your pass.
Docs
Launch GraphOS Studio
You're viewing documentation for a previous version of this software. Switch to the latest stable version.

Inline Fragments


Apollo Android supports GraphQL inline fragments. They are not to be confused with regular s that are used to reused s. 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 s and human fields respectively:

println("Droid primaryFunction: ${hero.asDroid?.primaryFunction}")
println("Human height: ${hero.asHuman?.height}")
Previous
Fragments
Next
Migration guides
Edit on GitHubEditForumsDiscord