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
If you'd like to read the Guide, and if you can afford to purchase it or if your company reimburses you for educational materials (most do 👍), we would value your support: [https://graphql.guide](https://graphql.guide).
We welcome issues and PRs. For large changes, we recommend opening an issue first to get feedback before putting in the work of a PR. Minor things like typo fixes or suggested rewordings can go directly to PRs and will usually get a quick response.
15
+
We welcome issues and PRs! For large changes, we recommend opening an issue first to get feedback before putting in the work of a PR. Minor things like typo fixes or suggested rewordings can go directly to PRs and will usually get a quick response 😊
12
16
13
17
### Setup
14
18
@@ -18,4 +22,8 @@ If you're working on gitbook-related issues or want to see how your PR will be f
18
22
npm i -g gitbook
19
23
gitbook install
20
24
mkdir out/
21
-
```
25
+
```
26
+
27
+
---
28
+
29
+
[Changelog](https://github.com/GraphQLGuide/book/releases) (we use Github releases)
First we request the users from the server, and once they’ve been returned, we request each user’s group. Once all the groups are returned, we have an array of full user objects to use. Here is the corresponding GraphQL:
646
+
First we request the users from the server, and once they’ve been returned, we request each user’s group. Once all the groups are returned, we have an array of full user objects to use. Here is the equivalent code using our GraphQL API:
647
647
648
648
```js
649
649
import { request } from'graphql-request'
@@ -751,10 +751,10 @@ In this case, we’re requesting three query fields simultaneously (getting a li
751
751
752
752
In summary, the advantages of using GraphQL for fetching multiple data types are:
753
753
754
-
- The client retains control over its data requirements. Instead of the REST endpoint dictating the queries being run and the data returned, the client can specify the queries and the desired data and get it all back in a single request.
755
-
- The server doesn’t have to attempt to permute all of the possible desired endpoints. This helps reduce the cost and surface area for the API. We don’t have to know about all the use cases or platforms that the data will eventually appear in, so the implementation becomes much simpler and easier to maintain.
756
-
- It reduces the number of distinct requests for data, and thus the burden on both the client and the server. If we were to request three different pieces of data from a REST API, it could potentially require three different endpoints and three distinct HTTP requests. With GraphQL, we’re guaranteed to have a single request and the same unchanged implementation.
757
-
- It reduces the latency in the overall request by allowing most of the data loading to be done on the server rather than the client (which has to wait for the current HTTP request to complete before initiating any other requests that depend on the current request’s response).
754
+
-**The client retains control over its data requirements:** Instead of the REST endpoint dictating the queries being run and the data returned, the client can specify the queries and the desired data and get it all back in a single request.
755
+
-**Simpler server:**The server doesn’t have to attempt to permute all of the possible desired endpoints. This helps reduce the cost and surface area for the API. We don’t have to know about all the use cases or platforms that the data will eventually appear in, so the implementation becomes much simpler and easier to maintain.
756
+
-**Fewer requests:**It reduces the number of distinct requests for data, and thus the burden on both the client and the server. If we were to request three different pieces of data from a REST API, it could potentially require three different endpoints and three distinct HTTP requests. With GraphQL, we’re guaranteed to have a single request and the same unchanged implementation.
757
+
-**Faster:**It reduces the latency in the overall request by allowing most of the data loading to be done on the server rather than the client (which has to wait for the current HTTP request to complete before initiating any other requests that depend on the current request’s response).
Copy file name to clipboardExpand all lines: text/5.md
+2-2
Original file line number
Diff line number
Diff line change
@@ -60,7 +60,7 @@ requests, including HTTP requests):
60
60
$ curl -X POST \
61
61
-H "Content-Type: application/json" \
62
62
-d '{"query": "{ githubStars }"}' \
63
-
https://graphql.guide/graphql
63
+
https://api.graphql.guide/graphql
64
64
```
65
65
66
66
*`-X` specifies which HTTP method to use—in this case POST
@@ -175,7 +175,7 @@ of constructing the HTTP POST request and parsing the response. For instance, th
175
175
176
176
## Typing
177
177
178
-
When we’re working in typed languages, we have to write our own objects types and models, and when we get JSON from a REST API, we have to convert the data into our types. With GraphQL, we know the types for everything because they’re in the schema. Which means that our client libraries can provide us with type definitions or generate typed model code for us. For instance, [`apollo-codegen`](https://github.com/apollographql/apollo-codegen) generates type definitions for Typescript, Flow, and Scala, [Apollo iOS](https://www.apollographql.com/docs/ios/) returns query-specific Swift types, and [Apollo-Android](https://github.com/apollographql/apollo-android) generates types Java models based on our queries and schema.
178
+
When we’re working in typed languages, we have to write our own object types and models, and when we get JSON from a REST API, we have to convert the data into our types. With GraphQL, we know the types for everything because they’re in the schema. Which means that our client libraries can provide us with type definitions or generate typed model code for us. For instance, [`apollo-codegen`](https://github.com/apollographql/apollo-codegen) generates type definitions for Typescript, Flow, and Scala, [Apollo iOS](https://www.apollographql.com/docs/ios/) returns query-specific Swift types, and [Apollo-Android](https://github.com/apollographql/apollo-android) generates typed Java models based on our queries and schema.
179
179
180
180
A combination of having a schema and query documents also allow for some great code editor features, such as autocomplete, go to definition, and schema validation. (See for example the [VS Code plugin](https://github.com/apollographql/vscode-graphql) and [IntelliJ/WebStorm plugin](https://github.com/jimkyndemeyer/js-graphql-intellij-plugin).)
over a WebSocket and [cached on the client](https://blog.meteor.com/announcing-meteor-1-5-b82be66571bb) (in
135
+
[IndexedDB](https://en.wikipedia.org/wiki/Indexed_Database_API)). It also does [differential bundling](https://blog.meteor.com/meteor-1-7-and-the-evergreen-dream-a8c1270b0901), further reducing bundle size for modern browsers.
136
136
137
137
## App structure
138
138
@@ -471,7 +471,7 @@ And we have a working GraphQL-backed app!
471
471
472
472
`react-apollo` provides two APIs for making queries—the `<Query>` render prop API, and the HOC ([higher-order component](https://reactjs.org/docs/higher-order-components.html)) API. Which we use is mostly a matter of preference—the one thing the render prop API can do that the HOC API can’t is use a dynamic query. The aesthetic differences are whether we’re providing querying options and child component props in JSX (render prop) or JS objects (HOC), and whether we combine multiple queries by nesting JSX or composing HOCs. Since we’ll be writing components that use multiple queries and mutations, and we have limited horizontal width in our ebook readers, we’ll avoid highly nested JSX by mostly using HOCs. Note that it’s easy to translate between the two APIs, since they have the same props and provide us with the same information. So when we learn one API, we learn both.
473
473
474
-
Here’s the same component using `react-apollo`’s [`graphql()`](https://www.apollographql.com/docs/react/api/react-apollo.html#graphql) HOC API:
474
+
Here’s the same component using `react-apollo`’s [`graphql()`](https://www.apollographql.com/docs/react/api/react-apollo.html#graphql) HOC API:
475
475
476
476
```js
477
477
import { graphql } from'react-apollo'
@@ -3063,12 +3063,12 @@ const USER_QUERY = gql`
3063
3063
}
3064
3064
```
3065
3065
3066
-
Since we’re just counting the length, we don’t need any many `Review` fields—just the `id`. Now we need to pass the user object down the component tree—first to `<Book>`:
3066
+
Since we’re just counting the length, we don’t need many `Review` fields—just the `id`. Now we need to pass the user object down the component tree—first to `<Book>`:
It’s possible that our scroll handler (which calls `loadMoreReviews`) will fire before the results from the initial reviews query has completed, in which case `reviews` will be `undefined`, and we do nothing.
4915
+
4909
4916
We also have to remove `skip` from `withAddReview` and `withDeleteMutation`, and update the query:
@@ -5041,9 +5048,8 @@ The tricky part here is that we don’t know if the list of reviews with `orderB
5041
5048
5042
5049
---
5043
5050
5044
-
That’s all we have for you for now! We’re currently working on more advanced React content and the server chapter. Please drop us a line if you have any suggestions for us 😊:
5045
-
5046
-
<authors@graphql.guide>
5051
+
That’s all we have for you for now! We’re currently working on more advanced React content and the server chapter. Please drop us a line if you have any suggestions for us 😊.
5047
5052
5048
-
[GitHub issues: book text](https://github.com/GraphQLGuide/book/issues)
We haven't gotten to this chapter yet, but most things from the [React chapter](6.md) apply to React Native. For now, here's a great [small example](https://www.apollographql.com/docs/react/recipes/simple-example.html), and a [paid course](https://www.leveluptutorials.com/tutorials/level-2-react-native-with-graphql).
3
+
We haven't gotten to this chapter yet, but most things from the [React chapter](6.md) apply to React Native. For now, here's a great [small example](https://www.apollographql.com/docs/react/recipes/simple-example.html), and a [paid course](https://www.leveluptutorials.com/tutorials/level-2-react-native-with-graphql?ref=guide).
Copy file name to clipboardExpand all lines: text/README.md
+25-10
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,16 @@
1
1
# Introduction
2
2
3
+
*[Who is this book for?](README.md#who-is-this-book-for)
4
+
*[Background](README.md#background)
5
+
*[The book](README.md#the-book)
6
+
*[The code](README.md#the-code)
7
+
*[Git](README.md#git)
8
+
*[Formatting](README.md#formatting)
9
+
*[Resources](README.md#resources)
10
+
*[Version](README.md#version)
11
+
12
+
---
13
+
3
14
# Who is this book for?
4
15
5
16
This book is for most programmers. If you write software that fetches data from a server, or you write server code that provides data to others, this book is for you. It’s particularly relevant to frontend and backend web and mobile developers. If you don’t know modern JavaScript, we recommend [learning that first](bg.md#javascript), but it’s not necessary. For example, if you only know Ruby, you can likely follow the JavaScript server code in Chapter 11 well enough to learn the important concepts of a GraphQL server, most of which will apply to using the `graphql` gem in your Ruby server code.
@@ -62,9 +73,9 @@ If you’re reading this in epub or mobi format on your phone, turning sideways
62
73
63
74
## Git
64
75
65
-
In Chapters 6–11, you’ll learn through writing an app, step-by-step. Each chapter has its own repository. Each step has a branch in that repo, for example branch `0`for the starter template, branch `1`for the code you write in the first step, etc. These branches contain the most up-to-date version of the code (and are updated through rebasing and force pushing). Snapshots of the steps are taken with tags for every release of the ebook. For instance, in the first version of the book (`the-graphql-guide-r1.pdf`, or r1), the React chapter code is at version `0.1.0`, so the code excerpts correspond exactly with tags `0_0.1.0` for step 0, `1_0.1.0` for step 1, etc. In the second revision of the book (`the-graphql-guide-r2.pdf`), if the code hasn’t changed, the tags will stay the same. In the third revision, if there are small changes to the code, the tags will be in the form `[step number]_0.1.1`.
76
+
In Chapters 6–11, you’ll learn through writing an app, step by step. Each chapter has its own repository. Each step has a branch in that repo, for example branch `0`is the starter template, branch `1`has the code you write in step 1, etc. The branches we link to in the text also have a version number, and have the format: `[step]_[version]`. When this version of the Guide was published, the version of the Chapter 6 code was `0.1.0`, so step 1 links to branch `1_0.1.0`.
66
77
67
-
So for example, if you’re on r1 (which is on `v0.1.0` of the code), and you skip the beginning of Chapter 6 and go straight to the [Listing reviews](6.md#listing-reviews) section, it says to start with step 9 (`9_0.1.0`). So we can look at the app in that state with these terminal commands:
78
+
If you skip the beginning of Chapter 6 and go straight to the [Listing reviews](6.md#listing-reviews) section, it says to start with step 9 (`9_0.1.0`). So we can look at the app in that state with these terminal commands:
@@ -122,14 +133,18 @@ Another important resource is the docs! Here they are for each library:
122
133
123
134
# Version
124
135
125
-
Book version `0.1.0`
136
+
Book version: [`r1`](https://github.com/GraphQLGuide/book/releases)
137
+
138
+
Published June 11, 2018
126
139
127
-
Published May 7, 2018
140
+
As we write more of the book, we’ll send you new versions of it (using the email address on the GitHub account you connected when you purchased the book at [graphql.guide](https://graphql.guide)).
As we write more of the book, we’ll send you new versions of it (using the email address of the GitHub account you connected when you purchased the book at [graphql.guide](https://graphql.guide)).
0 commit comments