3. Add the GraphQL schema
5m

Overview

We're familiar with queries, now let's bring them into our app! 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
  • Use the Apollo Android Studio plugin or the command line to download the schema

Configuring Gradle

creates a Gradle task automatically, so that's what we'll use in our build.gradle.kts. This works with any endpoint that has enabled.

First, add the URL of the endpoint and the desired location of the schema to the Apollo Gradle configuration:

app/build.gradle.kts
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 plugin in Android Studio or using a simple terminal command.

Android Studio

In the menu bar, select:

Tools | Apollo | Download Schema

Android Studio with the Tools menu opened, highlighting "Download Schema" in the nested menu

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

files often use the extension .graphqls (""). If all went well, your project view should show your schema at app/src/main/graphql/schema.graphqls:

The Android Studio Project view showing a graphql schema file

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

Task!

Practice

Use the information from the "Sandbox Explorer" and "Add the GraphQL schema" lessons to drag and drop the right answers into the blanks.
The GraphQL 
 
 is a collection of types and fields that make up the comprehensive picture of everything we can do with the data in a GraphQL server. The schema file's extension is typically 
 
. I can fetch that file from my GraphQL API using the terminal command 
 
 or 
 
.

Drag items from this box to the blanks above

  • Vim

  • .graphql

  • .gql

  • ./gradlew :app:...

  • .graphqls

  • config

  • query

  • schema

  • apollo

Up next

Our 's in the app, ready to use! In the next lesson we'll talk through how to generate Kotlin code from this query and schema data by running code generation.

Previous

Share your questions and comments about this lesson

This course is currently in

beta
. Your feedback helps us improve! If you're stuck or confused, let us know and we'll help you out. All comments are public and must follow the Apollo Code of Conduct. Note that comments that have been resolved or addressed may be removed.

You'll need a GitHub account to post below. Don't have one? Post in our Odyssey forum instead.