Join us from October 8-10 in New York City to learn the latest tips, trends, and news about GraphQL federation and API platform engineering.Join us for GraphQL Summit 2024 in NYC
Docs
Start for Free
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 that are used to reused . 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}")
Previous
Fragments
Next
Migration guides
Rate articleRateEdit on GitHubEditForumsDiscord

© 2024 Apollo Graph Inc.

Privacy Policy

Company