Skip to content

Commit 0f01aca

Browse files
authored
Tweak tutorial wording and paths (#5924)
* Tweak tutorial wording and paths * Backport tweaks from #5975 * Adjust package name/plugin id
1 parent 4e3cb66 commit 0f01aca

9 files changed

+84
-38
lines changed

docs/source/tutorial/01-configure-project.mdx

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ In this step, you'll import the starter project and add the Apollo Kotlin SDK to
88

99
```
1010
git clone https://github.com/apollographql/apollo-kotlin-tutorial
11-
cd apollo-kotlin-tutorial/compose
11+
cd apollo-kotlin-tutorial
1212
```
1313

1414
The starter project is in the `start` folder.
@@ -39,13 +39,25 @@ This tutorial uses `4.0.0` because it is the latest version at the time of writi
3939

4040
## Apply the plugin
4141

42-
Apply the Apollo plugin in `app/build.gradle.kts`. There are two `build.gradle.kts` in the project. Make sure to use the one in the `app` directory this time. The Apollo plugin ID is `com.apollographql.apollo`.
42+
Add the Apollo plugin to the version catalog in `gradle/libs.versions.toml`. The Apollo plugin ID is `com.apollographql.apollo`:
43+
44+
```toml title="gradle/libs.versions.toml"
45+
[versions]
46+
# ...
47+
apollo = "4.0.0"
48+
49+
[plugins]
50+
# ...
51+
apollo = { id = "com.apollographql.apollo", version.ref = "apollo" }
52+
```
53+
54+
Then apply the Apollo plugin in `app/build.gradle.kts`. There are two `build.gradle.kts` in the project - make sure to use the one in the `app` directory.
4355

4456
```kotlin title="app/build.gradle.kts"
4557
plugins {
46-
id("com.android.application")
58+
alias(libs.plugins.android.application)
4759
// ...
48-
id("com.apollographql.apollo") version "4.0.0"
60+
alias(libs.plugins.apollo)
4961
}
5062
```
5163

@@ -67,12 +79,22 @@ apollo {
6779
6880
## Add dependencies
6981

70-
Now add `apollo-runtime` to the list of dependencies. This is the code that executes queries and parses responses.
82+
Now add `apollo-runtime` to the list of dependencies. This is the part of the SDK that executes queries and parses responses.
83+
84+
First add the dependency to the version catalog:
85+
86+
```toml title="gradle/libs.versions.toml"
87+
[libraries]
88+
# ...
89+
apollo-runtime = { module = "com.apollographql.apollo:apollo-runtime", version.ref = "apollo"}
90+
```
91+
92+
Then add the dependency to the `app/build.gradle.kts` file:
7193

7294
```kotlin title="app/build.gradle.kts"
7395
dependencies {
7496
// ...
75-
implementation("com.apollographql.apollo:apollo-runtime:4.0.0")
97+
implementation(libs.apollo.runtime)
7698
}
7799
```
78100

docs/source/tutorial/02-add-the-graphql-schema.mdx

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,28 @@ In the **Reference** tab, you can now see a list of all of the things available
2222

2323
Apollo Kotlin requires a schema to generate type-safe models and code from your queries. There are multiple ways to get a schema. For example, you can go to the SDL tab and download the raw SDL schema using GraphOS Studio Sandbox.
2424

25-
In this tutorial, we will use the `downloadApolloSchema` Gradle task that is created by our plugin automatically. Since GraphQL supports [introspection](https://graphql.org/learn/introspection/), this will work with any GraphQL endpoint that has introspection enabled.
25+
In this tutorial, we will use the Gradle task that is created by the Apollo plugin automatically. Since GraphQL supports [introspection](https://graphql.org/learn/introspection/), this will work with any GraphQL endpoint that has introspection enabled.
26+
27+
First, add the URL of the GraphQL endpoint and the desired location of the schena to the Apollo Gradle configuration:
28+
29+
```kotlin title="app/build.gradle.kts"
30+
apollo {
31+
service("service") {
32+
packageName.set("com.example.rocketreserver")
33+
introspection { // highlight-line
34+
endpointUrl.set("https://apollo-fullstack-tutorial.herokuapp.com/graphql") // highlight-line
35+
schemaFile.set(file("src/main/graphql/schema.graphqls")) // highlight-line
36+
} // highlight-line
37+
}
38+
}
39+
```
2640

27-
From the root of the project, run the following in Android Studio's Terminal tab:
41+
Then, from the root of the project, run this command in Android Studio's Terminal tab:
2842

2943
```shell title="(shell)"
30-
./gradlew :app:downloadApolloSchema --endpoint='https://apollo-fullstack-tutorial.herokuapp.com/graphql' --schema=app/src/main/graphql/schema.graphqls
44+
./gradlew :app:downloadServiceApolloSchemaFromIntrospection
3145
```
3246

33-
Note that the path given to `--schema` is relative to the root of the project.
34-
3547
This will download a `schema.graphqls` file from your endpoint to `app/src/main/graphql/schema.graphqls`.
3648

3749
Next, [write your first query](03-write-your-first-query) that uses this schema.

docs/source/tutorial/03-write-your-first-query.mdx

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,41 @@
22
title: "3. Write your first query"
33
---
44

5-
The most common GraphQL operation is the **query**, which requests data from your graph in a structure that conforms to your server's schema. If you return to [the Sandbox](https://studio.apollographql.com/sandbox/explorer?endpoint=https%3A%2F%2Fapollo-fullstack-tutorial.herokuapp.com%2Fgraphql) for your server, you can see available queries in the Schema Reference tab you opened earlier.
5+
The most common GraphQL operation is the **query**, which requests data from your graph in a structure that conforms to your server's schema. If you return to [the Sandbox](https://studio.apollographql.com/sandbox/explorer?endpoint=https%3A%2F%2Fapollo-fullstack-tutorial.herokuapp.com%2Fgraphql) for your server, you can see available query fields in the Schema Reference tab you opened earlier.
66

7-
Scroll down to the `launches` query to get details about it:
7+
Scroll down to the `launches` field to get details about it:
88

99
<img src="images/launches_detail.png" class="screenshot" alt="Detail about launches query"/>
1010

11-
Here, you see both the query term itself, the return type, and information about parameters that can be passed to the query. You can use this information to write a query you'll eventually add to your app.
11+
Here, you see both the field name itself, its return type, and information about parameters that can be passed to it. You can use this information to write a query you'll eventually add to your app.
1212

13-
To start working with this query in the Sandbox Explorer, select the "play" button to the right side of the information:
13+
To start working with this field in the Sandbox Explorer, select the "play" button to the right side of the information:
1414

1515
<img src="images/open_in_explorer_launches.png" class="screenshot" alt="Open in Explorer"/>
1616

17-
This brings you back into Sandbox's Explorer tab with the sidebar on the left showing documentation for the query you've selected:
17+
This brings you back into Sandbox's Explorer tab with the sidebar on the left showing documentation for the field you've selected:
1818

1919
<img src="images/explorer_sandbox_open.png" class="screenshot" alt="Docs open in the left sidebar"/>
2020

21-
Notice the small button next to the `launches` icon. Click this button to add the query to the middle "operations" panel:
21+
Notice the small plus button next to the `launches` field. Click this button to add the field to the middle "operations" panel:
2222

2323
<img src="images/explorer_add_launches_query.png" class="screenshot" alt="Click the button to add this query"/>
2424

25-
When the query is added, it will look like this:
25+
When the field is added, it will look like this:
2626

2727
<img src="images/explorer_initial_added_query.png" class="screenshot" alt="The query once it's been added to the Operations section"/>
2828

2929
Let's break down what you're seeing here:
3030

31-
- The type of the operation, `query`, followed by the name of the operation, currently `Query` (we'll make that more specific in a second), is the outermost set of brackets.
32-
- The actual query being called is the next set of brackets in. Since the `arguments` for this query both have default values, they are not automatically added to the query for you.
33-
- An error in the empty space between the brackets, which is where you'll put the list of information you want back from each launch.
31+
- The type of the operation, `query`, followed by the name of the operation, currently `Query` (we'll make that more specific in a second), is the outermost set of braces.
32+
- The actual field being selected is the next set of braces in. Since the **arguments** for this field both have default values, they are not automatically added for you.
33+
- An error in the empty space between the braces, which is where you'll put the list of information you want back from each launch.
3434

3535
The Apollo Kotlin SDK requires every query to have a name (even though this isn't required by the GraphQL spec). Since you're going to create more than one query, it's also a good idea to give this operation a specific name other than `Query`. Change the name of the operation to `LaunchList`:
3636

3737
<img src="images/explorer_launch_list_rename.png" class="screenshot" alt="Renaming the query"/>
3838

39-
Next, on the left hand side, you can select what fields you want back in the returned object. Start by clicking the button next to the `cursor` field. It will mark that field as selected, then insert it into your operations:
39+
Next, on the left hand side, you can select what fields you want back in the returned object. Start by clicking the plus button next to the `cursor` field. It will mark that field as selected, then insert it into your operations:
4040

4141
<img src="images/explorer_check_cursor.png" class="screenshot" alt="After adding the cursor field."/>
4242

@@ -48,7 +48,7 @@ However, you can also use auto-complete to help you with this. Add a newline bel
4848

4949
The Sandbox Explorer is a great tool for building and verifying queries so you don't have to repeatedly rebuild your project in Android Studio to try out changes.
5050

51-
As the schema indicates, the `launches` query returns a `LaunchConnection` object. This object includes a list of launches, along with fields related to pagination (`cursor` and `hasMore`). The query you've written so far indicates exactly which fields of this `LaunchConnection` object you want to be returned.
51+
As the schema indicates, the `launches` field returns a `LaunchConnection` object. This object includes a list of launches, along with fields related to pagination (`cursor` and `hasMore`). The query you've written so far indicates exactly which fields of this `LaunchConnection` object you want to be returned.
5252

5353
Run this query by pressing the "Submit Operation" button, which should now have the name of your query, `LaunchList`:
5454

@@ -64,11 +64,13 @@ Click the button next to the `launches` field at the bottom of the left column.
6464

6565
<img src="images/explorer_launches_drill_in.png" class="screenshot" alt="Status after adding launches field"/>
6666

67-
The fields you add in this set of brackets will be fetched for every launch in the list. Click the buttons next to `id` and `site` properties to add those two fields. When you're done, your operation should look like this:
67+
The fields you add in this set of braces will be fetched for every launch in the list. Click the buttons next to `id` and `site` properties to add those two fields. When you're done, your operation should look like this:
6868

6969
```graphql title="(Sandbox Explorer)"
7070
query LaunchList {
7171
launches {
72+
cursor
73+
hasMore
7274
launches {
7375
id
7476
site

docs/source/tutorial/05-connect-queries-to-your-ui.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
title: "5. Connect your queries to your UI"
33
---
44

5-
In this chapter, you are going to display a list of Launch Sites in a [LazyColumn](https://developer.android.com/jetpack/compose/lists#lazy).
5+
In this chapter, you are going to display a list of Launches in a [LazyColumn](https://developer.android.com/jetpack/compose/lists#lazy).
66

7-
## Configure LaunchListAdapter
7+
## Setup the LaunchList composable
88

99
In `LaunchList`, declare a list of `LaunchListQuery.Launch`, initialized as empty:
1010

docs/source/tutorial/06-add-more-info.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Any GraphQL field can take arguments like `missionPatch` above, and arguments ca
3434

3535
<img src="images/sandbox_patch_size_docs.png" alt="The patch size enum in Sandbox's Schema tab" class="screenshot"/>
3636

37-
## Bind the info
37+
## Display the fields
3838

3939
In `LaunchList.kt`, bind the GraphQL data to the mission name, site, and mission patch using Coil's `AsyncImage`:
4040

docs/source/tutorial/07-paginate-results.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ fun LaunchList(onLaunchClick: (launchId: String) -> Unit) {
5252

5353
Pass the `cursor` to the `LaunchListQuery`, and add a special item at the end of the list which updates the `cursor` if `hasNext` is true. This will trigger a new query with the new cursor whenever the user scrolls to the end of the list, and `launchList` will be concatenated with the new results.
5454

55-
> **Note:** this is a basic implementation of paging in Compose. In a real project you may use something more advanced, like the [Jetpack Paging library](https://developer.android.com/jetpack/compose/lists#large-datasets).
55+
> **Note:** this is a basic implementation of pagination in Compose. In a real project you may use something more advanced, like the [Jetpack Paging library](https://developer.android.com/jetpack/compose/lists#large-datasets).
5656

5757
The whole function should look like this:
5858
```kotlin title="app/src/main/java/com/example/rocketreserver/LaunchList.kt"

docs/source/tutorial/08-add-a-details-view.mdx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ fun LaunchDetails(launchId: String) {
158158
Now use the state to show the appropriate UI:
159159
160160
```kotlin title="app/src/main/java/com/example/rocketreserver/LaunchDetails.kt"
161-
// Use the state
161+
// Use the state
162162
when (val s = state) {
163163
Loading -> Loading()
164164
is ProtocolError -> ErrorMessage("Oh no... A protocol error happened: ${s.exception.message}")
@@ -186,7 +186,7 @@ private sealed interface LaunchDetailsState {
186186
}
187187
```
188188

189-
Then, in the `try` block, check for `response.hasErrors()` and wrap the result in the new state:
189+
Then, in the `when` block, check for `response.hasErrors()` and wrap the result in the new state:
190190

191191
```kotlin title="app/src/main/java/com/example/rocketreserver/LaunchDetails.kt"
192192
state = when {
@@ -202,6 +202,16 @@ state = when {
202202
}
203203
```
204204

205+
You should also update the conditional expression to handle the `ApplicationError` case:
206+
```kotlin title="app/src/main/java/com/example/rocketreserver/LaunchDetails.kt"
207+
when (val s = state) {
208+
Loading -> Loading()
209+
is ApplicationError -> ErrorMessage(text = s.errors.first().message) // highlight-line
210+
is ProtocolError -> ErrorMessage("Oh no... A protocol error happened: ${s.exception.message}")
211+
is Success -> LaunchDetails(s.data)
212+
}
213+
```
214+
205215
`response.errors` contains details about any errors that occurred. Note that this code also null-checks `response.data!!`. In theory, a server should not set `response.data == null` and `response.hasErrors == false` at the same time, but the type system cannot guarantee this.
206216

207217
To trigger an error, replace `LaunchDetailsQuery(launchId)` with `LaunchDetailsQuery("invalidId")`. Disable airplane mode and select a launch. The server will send this response:

docs/source/tutorial/09-write-your-first-mutation.mdx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,19 @@ A mutation is used to change data on your server. Here the login mutation will c
1212

1313
## Prototype your mutation in Sandbox Explorer
1414

15-
Open [your Sandbox Explorer](https://studio.apollographql.com/sandbox/explorer?endpoint=https%3A%2F%2Fapollo-fullstack-tutorial.herokuapp.com%2Fgraphql) and click on the plus symbol to add a new tab. Next, click on the Schema icon to get back to looking at your schema, and select "Mutation" to look at your list of mutations:
15+
Open [your Sandbox Explorer](https://studio.apollographql.com/sandbox/explorer?endpoint=https%3A%2F%2Fapollo-fullstack-tutorial.herokuapp.com%2Fgraphql) and click on the plus symbol to add a new tab. Next, click on the Schema icon to get back to looking at your schema, and select "Mutation" to look at your list of mutation fields:
1616

1717
<img alt="The list of available mutations" class="screenshot" src="images/sandbox_schema_mutations.png"/>
1818

19-
Scroll down to take a look at the `login` mutation:
19+
Scroll down to take a look at the `login` field:
2020

2121
<img alt="The definition of login in the schema" class="screenshot" src="images/schema_login_definition.png"/>
2222

23-
Click the play button to the right to open that mutation in the Explorer tab. When it opens, click the plus sign to add the operation:
23+
Click the play button to the right to open that field in the Explorer tab. When it opens, click the plus sign to add field to your operation:
2424

2525
<img alt="The login mutation after initially being added" class="screenshot" src="images/explorer_added_login_mutation.png"/>
2626

27-
Notice the red error indication - this is because the type returned by the mutation is `User`, which is not a **leaf** type: you need to choose which of the user's fields the mutation will return. For our purposes, we only need the `token` field, so add it by clicking the plus sign next to it.
27+
Notice the red error indication - this is because the type returned by the field is `User`, which is not a **leaf** type: you need to choose which of the user's fields the mutation will return. For our purposes, we only need the `token` field, so add it by clicking the plus sign next to it.
2828

2929
You'll also notice that `email` wasn't automatically added as an argument even though it doesn't seem to have a default value: that's because `email` is of type `String` - which remember, in GraphQL, means that it's **not** required (although obviously you won't get too far without it).
3030

@@ -34,7 +34,7 @@ Click the plus sign next to the `email` argument to have that argument added:
3434

3535
You'll also notice that Sandbox Explorer has added a variable to your "Variables" section to match the login email.
3636

37-
Click the Submit Operation button your mutation. You'll see that since you sent `null` for the email address, you get back `null` for the login:
37+
Click the Submit Operation button to execute your mutation. You'll see that since you sent `null` for the email address, you get back `null` for the login:
3838

3939
<img alt="Results of passing a null email" class="screenshot" src="images/login_mutation_null.png"/>
4040

docs/source/tutorial/11-subscriptions.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ In this section, you will use subscriptions to get notified whenever someone boo
77

88
## Write your subscription
99

10-
Open your [Sandbox](https://studio.apollographql.com/sandbox/explorer?endpoint=https%3A%2F%2Fapollo-fullstack-tutorial.herokuapp.com%2Fgraphql) back up, click on the Schema tab at the far left. In addition to `queries` and `mutations`, you will see a third type of operations, `subscriptions`. Click on subscriptions to see the `tripsBooked` subscription:
10+
Open your [Sandbox](https://studio.apollographql.com/sandbox/explorer?endpoint=https%3A%2F%2Fapollo-fullstack-tutorial.herokuapp.com%2Fgraphql) back up, click on the Schema tab at the far left. In addition to `queries` and `mutations`, you will see a third type of root fields, `subscriptions`. Click on subscriptions to see the `tripsBooked` field:
1111

1212
<img alt="The definition of tripsBooked in the schema" class="screenshot" src="images/schema_tripsBooked_definition.png"/>
1313

14-
This subscription doesn't take any argument and returns a single scalar named `tripsBooked`. Since you can book multiple trips at once, `tripsBooked` is an `Int`. It will contain the number of trips booked at once or -1 if a trip has been cancelled.
14+
This field doesn't take any argument and returns a single scalar named `tripsBooked`. Since you can book multiple trips at once, `tripsBooked` is an `Int`. It will contain the number of trips booked at once or -1 if a trip has been cancelled.
1515

16-
Click the play button to the left of `tripsBooked` to open the subscription in Explorer. Open a new tab, then check the `tripsBooked` button to have the subscription added:
16+
Click the play button to the left of `tripsBooked` to open the field in Explorer. Open a new tab, then check the plus button next to `tripsBooked` to have the field added:
1717

1818
<img alt="The initial definition of the TripsBooked subscription" class="screenshot" src="images/explorer_tripsbooked_initial.png"/>
1919

0 commit comments

Comments
 (0)