Overview
We're familiar with queries, now let's bring them into our app! Apollo Kotlin requires a schema to generate type-safe models and code from your queries. There are multiple ways to get a schema.
In this lesson, we will:
- Configure our Gradle build with the URL to the GraphQL schema
- Use the Apollo GraphQL Android Studio plugin or the command line to download the schema
Configuring Gradle
Apollo Kotlin creates a Gradle task automatically, so that's what we'll use in our build.gradle.kts
. This works with any GraphQL endpoint that has introspection enabled.
First, add the URL of the GraphQL endpoint and the desired location of the schema to the Apollo Gradle configuration:
apollo {service("service") {packageName.set("com.example.rocketreserver")introspection {endpointUrl.set("https://apollo-fullstack-tutorial.herokuapp.com/graphql")schemaFile.set(file("src/main/graphql/schema.graphqls"))}}}
Download the Schema
Downloading the schema to use in your project can be done using the Apollo GraphQL plugin in Android Studio or using a simple terminal command.
Android Studio
In the menu bar, select:
And that's it!
Command line
If you prefer to use the command line, navigate to the root of your project and run this command:
./gradlew :app:downloadServiceApolloSchemaFromIntrospection
Finding your schema file
GraphQL schema files often use the extension .graphqls
("GraphQL Schema"). If all went well, your project view should show your schema at app/src/main/graphql/schema.graphqls
:
Generally speaking, you won't need to open this file very often inside of an Apollo Kotlin project. The only reason we're looking at it now is to double-check that it was downloaded successfully ✅
Practice
Drag items from this box to the blanks above
Vim
.graphql
.gql
./gradlew :app:...
.graphqls
config
query
schema
apollo
Up next
Our query's in the app, ready to use! In the next lesson we'll talk through how to generate Kotlin code from this GraphQL query and schema data by running code generation.
Share your questions and comments about this lesson
This course is currently in
You'll need a GitHub account to post below. Don't have one? Post in our Odyssey forum instead.