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.

6. Add more info to the list


In this section, you will use the Coil image-loading library to display a nice patch about the . You will also learn about .

Add more info to your query

Go back to LaunchList.graphql. Your is already fetching most of the information you want to display, but it would be nice to display both the name of the mission and an image of the patch.

Looking at the schema in GraphQL Playground, you can see that Launch has a property of mission, which allows you to get details of the mission. A mission has both a name and a missionPatch property, and the missionPatch can optionally take a parameter to specify the desired image size.

Because loading a RecyclerView with large images can impact performance, ask for the name and a SMALL mission patch. Update your query to look like the following:

app/src/main/graphql/com/example/rocketreserver/LaunchList.graphql
query LaunchList {
launches {
hasMore
cursor
launches {
id
site
mission {
name
missionPatch(size: SMALL)
}
}
}
}

When you recompile, if you look in LaunchListQuery.kt, you'll see a new nested type, Mission, with the two properties you requested.

Any GraphQL can take arguments like missionPatch above, and arguments can be of or complex types. In this case, SMALL is an enum in the . It can take a finite list of values. If you look at the Docs pane in GraphQL Playground, you will see that size is an of type PatchSize that can only take two values: SMALL and LARGE

GraphQL enums

Bind the infos

In LaunchListAdapter.kt, bind the GraphQL data to the missionName and missionPatch Views using Coil:

app/src/main/java/com/example/rocketreserver/LaunchListAdapter.kt
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val launch = launches.get(position)
holder.binding.site.text = launch.site ?: ""
holder.binding.missionName.text = launch.mission?.name
holder.binding.missionPatch.load(launch.mission?.missionPatch) {
placeholder(R.drawable.ic_placeholder)
}
}

Test your query

Build and run the application, and you will see all the information for current .

Final launch list

If you scroll down, you'll see the list includes only about 20 launches. This is because the list of launches is paginated, and you've only fetched the first page.

Next, you will use a cursor-based loading system to load the entire list of launches.

Previous
5. Connect your queries to your UI
Next
7. Paginate results
Rate articleRateEdit on GitHubEditForumsDiscord

© 2024 Apollo Graph Inc.

Privacy Policy

Company