You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -39,13 +39,25 @@ This tutorial uses `4.0.0` because it is the latest version at the time of writi
39
39
40
40
## Apply the plugin
41
41
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.
43
55
44
56
```kotlin title="app/build.gradle.kts"
45
57
plugins {
46
-
id("com.android.application")
58
+
alias(libs.plugins.android.application)
47
59
// ...
48
-
id("com.apollographql.apollo") version "4.0.0"
60
+
alias(libs.plugins.apollo)
49
61
}
50
62
```
51
63
@@ -67,12 +79,22 @@ apollo {
67
79
68
80
## Add dependencies
69
81
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.
Copy file name to clipboardExpand all lines: docs/source/tutorial/02-add-the-graphql-schema.mdx
+17-5Lines changed: 17 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -22,16 +22,28 @@ In the **Reference** tab, you can now see a list of all of the things available
22
22
23
23
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.
24
24
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:
Copy file name to clipboardExpand all lines: docs/source/tutorial/03-write-your-first-query.mdx
+15-13Lines changed: 15 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,41 +2,41 @@
2
2
title: "3. Write your first query"
3
3
---
4
4
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.
6
6
7
-
Scroll down to the `launches`query to get details about it:
7
+
Scroll down to the `launches`field to get details about it:
8
8
9
9
<imgsrc="images/launches_detail.png"class="screenshot"alt="Detail about launches query"/>
10
10
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.
12
12
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:
14
14
15
15
<imgsrc="images/open_in_explorer_launches.png"class="screenshot"alt="Open in Explorer"/>
16
16
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:
18
18
19
19
<imgsrc="images/explorer_sandbox_open.png"class="screenshot"alt="Docs open in the left sidebar"/>
20
20
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:
22
22
23
23
<imgsrc="images/explorer_add_launches_query.png"class="screenshot"alt="Click the button to add this query"/>
24
24
25
-
When the query is added, it will look like this:
25
+
When the field is added, it will look like this:
26
26
27
27
<imgsrc="images/explorer_initial_added_query.png"class="screenshot"alt="The query once it's been added to the Operations section"/>
28
28
29
29
Let's break down what you're seeing here:
30
30
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.
34
34
35
35
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`:
36
36
37
37
<imgsrc="images/explorer_launch_list_rename.png"class="screenshot"alt="Renaming the query"/>
38
38
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:
40
40
41
41
<imgsrc="images/explorer_check_cursor.png"class="screenshot"alt="After adding the cursor field."/>
42
42
@@ -48,7 +48,7 @@ However, you can also use auto-complete to help you with this. Add a newline bel
48
48
49
49
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.
50
50
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.
52
52
53
53
Run this query by pressing the "Submit Operation" button, which should now have the name of your query, `LaunchList`:
54
54
@@ -64,11 +64,13 @@ Click the button next to the `launches` field at the bottom of the left column.
64
64
65
65
<imgsrc="images/explorer_launches_drill_in.png"class="screenshot"alt="Status after adding launches field"/>
66
66
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:
Pass the `cursor` to the `LaunchListQuery`, and add a special item at the end of the list which updates the `cursor` if `hasNext` istrue. 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.
54
54
55
-
>**Note:**thisis a basic implementation of paginginCompose. In a real project you may use something more advanced, like the [JetpackPaging library](https://developer.android.com/jetpack/compose/lists#large-datasets).
55
+
>**Note:**thisis a basic implementation of paginationinCompose. In a real project you may use something more advanced, like the [JetpackPaging library](https://developer.android.com/jetpack/compose/lists#large-datasets).
isProtocolError->ErrorMessage("Oh no... A protocol error happened: ${s.exception.message}")
211
+
isSuccess->LaunchDetails(s.data)
212
+
}
213
+
```
214
+
205
215
`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.
206
216
207
217
To trigger an error, replace `LaunchDetailsQuery(launchId)` with `LaunchDetailsQuery("invalidId")`. Disable airplane mode and select a launch. The server will send this response:
Copy file name to clipboardExpand all lines: docs/source/tutorial/09-write-your-first-mutation.mdx
+5-5Lines changed: 5 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,19 +12,19 @@ A mutation is used to change data on your server. Here the login mutation will c
12
12
13
13
## Prototype your mutation in Sandbox Explorer
14
14
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:
16
16
17
17
<imgalt="The list of available mutations"class="screenshot"src="images/sandbox_schema_mutations.png"/>
18
18
19
-
Scroll down to take a look at the `login`mutation:
19
+
Scroll down to take a look at the `login`field:
20
20
21
21
<imgalt="The definition of login in the schema"class="screenshot"src="images/schema_login_definition.png"/>
22
22
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:
24
24
25
25
<imgalt="The login mutation after initially being added"class="screenshot"src="images/explorer_added_login_mutation.png"/>
26
26
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.
28
28
29
29
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).
30
30
@@ -34,7 +34,7 @@ Click the plus sign next to the `email` argument to have that argument added:
34
34
35
35
You'll also notice that Sandbox Explorer has added a variable to your "Variables" section to match the login email.
36
36
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:
38
38
39
39
<imgalt="Results of passing a null email"class="screenshot"src="images/login_mutation_null.png"/>
Copy file name to clipboardExpand all lines: docs/source/tutorial/11-subscriptions.mdx
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,13 +7,13 @@ In this section, you will use subscriptions to get notified whenever someone boo
7
7
8
8
## Write your subscription
9
9
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:
11
11
12
12
<imgalt="The definition of tripsBooked in the schema"class="screenshot"src="images/schema_tripsBooked_definition.png"/>
13
13
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.
15
15
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:
17
17
18
18
<imgalt="The initial definition of the TripsBooked subscription"class="screenshot"src="images/explorer_tripsbooked_initial.png"/>
0 commit comments