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
Copy file name to clipboardExpand all lines: docs/source/tutorial/client.md
+8-2Lines changed: 8 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,12 +12,12 @@ While Apollo Client works with any view layer, it's most commonly used with Reac
12
12
For this half of the tutorial, we will be working in the `client/` folder of the project. You should have the project already from the server portioned, but if you don't, make sure to clone [the tutorial](https://github.com/apollographql/fullstack-tutorial/). From the root of the project, run:
13
13
14
14
```bash
15
-
cd client && npm install
15
+
cdstart/client && npm install
16
16
```
17
17
18
18
Now, our dependencies are installed. Here are the packages we will be using to build out our frontend:
19
19
20
-
-`apollo-client@next`: A complete data management solution with an intelligent cache. In this tutorial, we will be using the Apollo Client 3.0 preview since it includes local state management capabilities and sets your cache up for you.
20
+
-`apollo-client@alpha`: A complete data management solution with an intelligent cache. In this tutorial, we will be using the Apollo Client 3.0 preview since it includes local state management capabilities and sets your cache up for you.
21
21
-`react-apollo`: The view layer integration for React that exports components such as `Query` and `Mutation`
22
22
-`graphql-tag`: The tag function `gql` that we use to wrap our query strings in order to parse them into an AST
23
23
@@ -36,6 +36,12 @@ Our key is now stored under the environment variable `ENGINE_API_KEY`. Apollo VS
36
36
Next, create an Apollo config file called `apollo.config.js`. This config file is how you configure both the Apollo VSCode extension and CLI. Paste the snippet below into the file:
37
37
38
38
```js
39
+
module.exports= {
40
+
client: {
41
+
name:'Space Explorer [web]',
42
+
service:'space-explorer',
43
+
},
44
+
};
39
45
```
40
46
41
47
Great, we're all set up! Let's dive into building our first client.
Copy file name to clipboardExpand all lines: docs/source/tutorial/introduction.md
+8-3Lines changed: 8 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -24,7 +24,10 @@ Why do you need a graph? Today, one of the most difficult parts of building an a
24
24
In this tutorial, we'll build an interactive app for reserving your spot on an upcoming Space-X launch. You can think of it as an Airbnb for space travel! All of the data is real, thanks to the [SpaceX-API](https://github.com/r-spacex/SpaceX-API).
25
25
26
26
Here's what the finished app will look like:
27
-
<!-- TODO: Add screenshot -->
27
+
28
+
<divstyle="text-align:center">
29
+

30
+
</div>
28
31
29
32
The app has five screens: a login screen, a list of launches, a launch detail, a profile page, and a cart. The graph API powering our space app connects to a REST API and a SQLite database. Don't worry if you're unfamiliar with those technologies, you don't need to know how to build a REST API or SQLite database from scratch in order to complete the tutorial.
30
33
@@ -55,9 +58,11 @@ Next, in your terminal, clone this repository:
There are two folders: one for the server and one for the client. We will be working in the server folder first. If you're comfortable with building a graph API already and you want to skip to the client portion, navigate to the [last half of the tutorial](./client.html).
61
+
There are two folders: one for the starting point (`start/`) and one for the final version (`final`). Within each directory are two folders: one for the server and one for the client. We will be working in the server folder first. If you're comfortable with building a graph API already and you want to skip to the client portion, navigate to the [last half of the tutorial](./client.html).
59
62
60
-
<h3id="vscode">Configure Apollo VSCode</h3>
63
+
<!--
64
+
TODO: Add in this section after Apollo VSCode works for server development
Copy file name to clipboardExpand all lines: docs/source/tutorial/local-state.md
+19-10Lines changed: 19 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -42,9 +42,9 @@ We can also add local fields to server data by extending types from our server.
42
42
43
43
<h2id="store-initializers">Initialize the store</h2>
44
44
45
-
Now that we've created our client schema, let's learn how to initialize the store. Since queries execute as soon as the component mounts, it's important for us to warm the Apollo cache with some default state so those queries don't error out. We will need to create `storeInitializers` for both `isLoggedIn` and `cartItems` to prevent these two local queries from erroring out:
45
+
Now that we've created our client schema, let's learn how to initialize the store. Since queries execute as soon as the component mounts, it's important for us to warm the Apollo cache with some default state so those queries don't error out. We will need to create `initializers` for both `isLoggedIn` and `cartItems` to prevent these two local queries from erroring out:
46
46
47
-
Jump to `src/index.js` and specify your `storeInitializers` on the `ApolloClient` constructor:
47
+
Jump to `src/index.js` and specify your `initializers` on the `ApolloClient` constructor:
48
48
49
49
_src/index.js_
50
50
@@ -57,14 +57,14 @@ const client = new ApolloClient({
57
57
authorization:localStorage.getItem('token'),
58
58
},
59
59
}),
60
-
storeInitializers: {
60
+
initializers: {
61
61
isLoggedIn: () =>!!localStorage.getItem('token'),
62
62
cartItems: () => [],
63
63
},
64
64
});
65
65
```
66
66
67
-
These `storeInitializers` will be called as soon as `ApolloClient` is created. They will also run if the store is reset.
67
+
These `initializers` will be called as soon as `ApolloClient` is created. They will also run if the store is reset.
68
68
69
69
Now that we've added default state to the Apollo cache, let's learn how to query local data from within our React components.
70
70
@@ -138,7 +138,7 @@ export default function Cart() {
138
138
<Fragment>
139
139
<Header>My Cart</Header>
140
140
{!data.cartItems||!data.cartItems.length? (
141
-
<p>No items in your cart</p>
141
+
<p data-testid="empty-message">No items in your cart</p>
If you try to render this query, you'll notice that it returns null. This is because we need to implement our login feature first. We're going to tackle login in the next section.
@@ -393,6 +395,4 @@ Next, paste our authorization header into the HTTP Headers box at the bottom:
393
395
}
394
396
```
395
397
396
-
Then, run the mutation. You should see a success message, along with the ids of the mutations we just booked. Testing mutations manually in the playground is a good way to explore our API, but in a real-world application, we should run automated tests so we can safely refactor our code. In the next section, you'll learn all about testing your graph.
397
-
398
-
<h2id="testing">Test your graph</h2>
398
+
Then, run the mutation. You should see a success message, along with the ids of the mutations we just booked. Testing mutations manually in the playground is a good way to explore our API, but in a real-world application, we should run automated tests so we can safely refactor our code. In the next section, you'll learn all about testing your graph.
0 commit comments