To view this content, buy the book! 😃🙏
Or sign in if you’ve already purchased.
First we clone the starter app, which has everything but the data:
git clone https://github.com/GraphQLGuide/guide-android.git
git checkout 0_1.0.0
We can open it in Android Studio 4.1+ and see the file structure:
We’ll be working in the app/ module. In app/src/main/java/, we have the guide.graphql.toc (toc stands for table of contents) package with code for the Activity, two Fragments, and two RecyclerView Adapters. In this chapter, we’ll be:
When we run the app, we see a single chapter with no sections:
Let’s start by adding the Apollo Android library to our project:
We add the apollo-runtime and apollo-coroutines-support dependencies, apply version 2.2.2 of the plugin to our project, and tell Apollo to generate the typed models in Kotlin instead of Java.
After saving, we click the “Sync Now” link that appears in the top right.
Apollo Android needs the schema of the GraphQL server we’ll be querying. If the server has introspection enabled, we can fetch the schema file with this Gradle task:
$ mkdir -p app/src/main/graphql/guide/graphql/toc
$ ./gradlew :app:downloadApolloSchema --endpoint='https://api.graphql.guide/graphql' --schema='app/src/main/graphql/guide/graphql/toc/schema.json'
mkdir -p creates any necessary intermediate directories 😎.
If it’s blocked on Mac, we do the following:
We can check to make sure it downloaded the schema file:
$ ls app/src/main/graphql/guide/graphql/toc/