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
+28-10Lines changed: 28 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -32,7 +32,7 @@ const client = new ApolloClient({
32
32
uri:"http://localhost:4000/graphql"
33
33
});
34
34
```
35
-
**Note:** The `src` directory mentioned here is not the server directory. It's a new directory that houses all the client code.
35
+
**Note:** The `src` directory mentioned here is not the server directory. It's a new directory that contains the client code.
36
36
37
37
To connect our graph API to a client, we need to import the `ApolloClient` class from `apollo-client` and pass our API URL to the client via the `uri` property of the client config object.
38
38
@@ -42,36 +42,54 @@ Now, let's fetch data with Apollo Client.
42
42
43
43
Our client is ready to start fetching data. Let's send a query with vanilla JavaScript.
44
44
45
-
With a `client.query()`function call, we can query our graph's API. Copy the code below and add it to `src/index.js`.
45
+
With a `client.query()` call, we can query our graph's API. Copy the code below and add it to `src/index.js`.
The result should be an object with a `data` property. The launch returned is attached to the `data` property.
80
+
**Note:**The `apollo-cache-inmemory` and `apollo-link-http` packages are vital to developing with Apollo Client so make sure they are installed. Run `npm install apollo-cache-inmemory apollo-link-http --save`.
67
81
68
-
Apollo Client is designed to enable fetching of graph data by anyone in the JavaScript ecosystem. No frameworks needed. However, there are view layer integrations for different frameworks that makes it easier to bind queries to UI.
82
+
The result should be an object with a `data` property. The launch returned is attached to the `data` property. You can check out the [codesandbox demo of the code above.](https://codesandbox.io/s/8xmn5j6n88)
69
83
70
-
Let's connect our client to React.
84
+
Apollo Client is designed to enable fetching of graph data by any JavaScript frontend. No frameworks needed. However, there are view layer integrations for different frameworks that makes it easier to bind queries to UI.
85
+
86
+
Now, let's connect our client to React.
71
87
72
88
<h2id="react-apollo">Connect your client to React</h2>
73
89
74
-
React is the choice of framework for our UI frontend in this tutorial. Install React using `create-react-app` via `npx`:
90
+
React is the choice of framework for our UI frontend in this tutorial.
91
+
92
+
Install React using `create-react-app` via `npx`:
75
93
76
94
```bash
77
95
npx create-react-app frontend
@@ -81,7 +99,7 @@ Now, let's connect Apollo Client to our React app.
81
99
82
100
To connect Apollo Client to React, you will need to invoke the `ApolloProvider` component exported from the `react-apollo` package. The `ApolloProvider` component is similar to React’s context provider. It wraps your React app and places the client on the context, which allows you to access it from anywhere in your component tree.
83
101
84
-
Open `src/index.js` and the update the code:
102
+
Open `src/index.js` and the update the code to be:
0 commit comments