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 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
Edit on GitHubEditForumsDiscord

© 2024 Apollo Graph Inc.

Privacy Policy

Company