Skip to content

Commit f3a7185

Browse files
committed
Release r3
1 parent bab5522 commit f3a7185

File tree

7 files changed

+405
-262
lines changed

7 files changed

+405
-262
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@ We welcome issues and PRs! For large changes, we recommend opening an issue firs
2323
If you're working on gitbook-related issues or want to see how your PR will be formatted, follow these steps to get set up after cloning:
2424

2525
```sh
26-
npm i -g gitbook
26+
npm i -g gitbook-cli
2727
gitbook install
2828
mkdir out/
29+
./build.sh
2930
```
3031

3132
---

text/1.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Why use GraphQL? It turns out that GraphQL is amazingly useful—it combines a n
2525

2626
- **Flexible, explicit queries:** GraphQL puts the consumer of the API in full control over what data they receive. Instead of a REST endpoint that returns all the properties you could possibly want (and often links to more), you only get the properties you ask for.
2727
- **Type-safe, self-documenting API:** GraphQL APIs are type-safe and self-documenting: the schema you define is exposed as interactive documentation for private or public consumption.
28-
- **No more API endpoint sprawl:** Backend engineers also love GraphQL. Once you write the code for accessing a data type, you won’t have to re-implement it. You don’t have to make a new endpoint for each view—you can leave that work up to the client and the GraphQL execution model, which is implemented by your GraphQL server library.
28+
- **No more API endpoint sprawl:** Backend engineers also love GraphQL. Once you write the code for accessing a data type, you won’t have to re-implement it. You don’t have to make a new endpoint for each view—you can leave that work up to the client and the GraphQL execution model, which is implemented by your GraphQL server library. And you don’t have to make a new API for each new app—you can have a single GraphQL API that covers all your business data.
2929
- **Query consolidation:** A request for multiple data types can be combined into a single query that is executed in parallel on the server.
3030
- **Static query analysis:** GraphQL schemas allow you to statically analyze the queries in your codebase and guarantee that you’ll never break them.
3131

text/6.md

+331-228
Large diffs are not rendered by default.

text/README.md

+28-21
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,17 @@ This book is for most programmers. If you write software that fetches data from
1717

1818
This book will be especially poignant to these groups of people:
1919

20-
- Backend devs who work on REST APIs and write a lot of similar data-fetching code, or who maintain view-specific endpoints.
21-
- Frontend devs of medium- or large-sized apps who either: A) don’t use a caching library, and manually keep track of what data has already been fetched from the server, or B) use a cache, and write a lot of code to fetch data over REST and put it in the cache (we’re looking at you, Reduxers 👀😄).
20+
- Backend devs who work on REST APIs and who:
21+
- write a lot of similar code to fetch data and format it into JSON,
22+
- maintain view- or device-specific endpoints, or
23+
- have multiple APIs that use overlapping business data.
24+
- Frontend devs who either:
25+
- don’t use a caching library, and manually keep track of what data has already been fetched from the server, or
26+
- use a cache, and write a lot of code to fetch data over REST and put it in the cache (we’re looking at you, Reduxers 👀😄).
2227

2328
# Background
2429

25-
We have a [Background](bg.md) section that provides concise introductions to various background topics. You’re welcome to either look through them now or individually as you go along—at the beginning of a section, you’ll find a list of topics it assumes knowledge of, like the [Anywhere: HTTP](5.md#anywhere-http) section, which has two listed:
30+
We have a [Background](bg.md) chapter that provides concise introductions to various background topics. You’re welcome to either look through them now or individually as you go along—at the beginning of a section, you’ll find a list of topics it assumes knowledge of, like the [Anywhere: HTTP](5.md#anywhere-http) section, which has two listed:
2631

2732
> Background: [HTTP](bg.md#http), [JSON](bg.md#json)
2833
@@ -37,9 +42,11 @@ Here’s a full list of the topics:
3742
* [SSR](bg.md#ssr)
3843
* [Latency](bg.md#latency)
3944
* [Webhooks](bg.md#webhooks)
45+
* [Continuous integration](bg.md#continuous-integration)
4046
* [Authentication](bg.md#authentication)
4147
* [Tokens vs. sessions](bg.md#tokens-vs-sessions)
42-
* [localStorage vs. cookies](bg.md#localstorage-vs-cookies)
48+
* [localStorage vs. cookies](bg.md#localstorage-vs-cookies)
49+
* [Browser performance](bg.md#browser-performance)
4350

4451
Some, like *Git* and *Node*, are necessary for following along with the coding. Others, like *Tokens vs. sessions*, are nice to know, but not necessary.
4552

@@ -65,22 +72,22 @@ Chapters [2](2.md) and [3](3.md) explain the language itself and its type system
6572

6673
# The code
6774

68-
We intersperse blocks of code throughout the text. When we add code to a file that we’ve shown previously, we often just display the additions and some context, with ellipses () in place of existing code. These additions will be clearest if you read the book with the code open in another window. Further, we believe people tend to learn better if they write things out themselves, so we encourage you to write out the code for each step, and get it working on your computer before moving on to the next step.
75+
We intersperse blocks of code throughout the text. When we add code to a file that we’ve shown previously, we often just display the additions and some context, with ellipses (`...`) in place of existing code. These additions will be clearest if you read the book with the code open in another window. Further, we believe humans usually learn better if they write things out themselves, so we encourage you to write out the code for each step, and get it working on your computer before moving on to the next step.
6976

70-
We recommend the Chrome browser and the [VS Code](https://code.visualstudio.com/) editor.
77+
We recommend using Chrome and [VS Code](https://code.visualstudio.com/).
7178

72-
If you’re reading this in epub or mobi format on your phone, turning sideways into landscape mode will help reduce code snippet wrapping.
79+
Code snippets are better formatted and sized in the PDF version of the book. If you’re reading this in EPUB or MOBI format on your phone, turning sideways into landscape mode will help reduce code snippet wrapping.
7380

7481
## Git
7582

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`.
83+
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 linked to branch `1_0.1.0`. The current version of the code is `0.2.0`, so step 1 links to `1_0.2.0`.
7784

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:
85+
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.2.0`). So we can look at the app in that state with these terminal commands:
7986

8087
```sh
8188
git clone https://github.com/GraphQLGuide/guide.git
8289
cd guide/
83-
git checkout 9_0.1.0
90+
git checkout 9_0.2.0
8491
npm install
8592
npm start
8693
```
@@ -93,12 +100,12 @@ If we get stuck, we can look at the diff between step 9 and step 10 with GitHub
93100

94101
which in our case would be:
95102

96-
[`github.com/GraphQLGuide/guide/compare/9_0.1.0...10_0.1.0`](https://github.com/GraphQLGuide/guide/compare/9_0.1.0...10_0.1.0)
103+
[`github.com/GraphQLGuide/guide/compare/9_0.2.0...10_0.2.0`](https://github.com/GraphQLGuide/guide/compare/9_0.2.0...10_0.2.0)
97104

98105
We can also see the solution to the current step by checking out the next step:
99106

100107
```sh
101-
git checkout 10_0.1.0
108+
git checkout 10_0.2.0
102109
npm start
103110
```
104111

@@ -119,9 +126,9 @@ Which means `'` instead of `"` for string literals and no unnecessary semicolons
119126

120127
If you run into issues, we recommend posting to Stack Overflow with the relevant tag, for instance [`react-apollo`](https://stackoverflow.com/questions/ask?tags=react-apollo) for Chapter 6. If you have the Full edition, you can also ask the community in the #support Slack channel or email the technical support address we gave you.
121128

122-
If the issue is with our code, please search the repository’s issues to see if it’s an existing bug, and if it’s new, submit it! 🙏🙌
129+
If the issue is with our code, please search the repository’s issues to see if it’s an existing bug, and if it’s new, submit it! 🙏 🙌
123130

124-
[React repo issues](https://github.com/GraphQLGuide/guide/issues)
131+
[github.com/GraphQLGuide/guide/issues](https://github.com/GraphQLGuide/guide/issues)
125132

126133
Another important resource is the docs! Here they are for each library:
127134

@@ -133,18 +140,18 @@ Another important resource is the docs! Here they are for each library:
133140

134141
# Version
135142

136-
Book version: [`r2`](https://github.com/GraphQLGuide/book/releases)
143+
Book version: `r3` ([changelog](https://github.com/GraphQLGuide/book/releases))
137144

138-
Published June 27, 2018
145+
Published April 10, 2019
139146

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)).
147+
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 from [graphql.guide](https://graphql.guide)).
141148

142149
## Chapter 6
143150

144-
Code version: [`0.1.0`](https://github.com/GraphQLGuide/guide/blob/master/CHANGELOG.md)
151+
Code version: `0.2.0` ([changelog](https://github.com/GraphQLGuide/guide/blob/master/CHANGELOG.md))
145152

146153
```
147-
react-apollo 2.1
148-
graphql 0.13
149-
react 16.3
154+
react-apollo 2.5
155+
graphql 0.14
156+
react 16.8
150157
```

text/SUMMARY.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@
121121
* [Add new reviews](6.md#add-new-reviews)
122122
* [Update on edit and delete](6.md#update-on-edit-and-delete)
123123
* [Prefetching](6.md#prefetching)
124-
* [On mouse over](6.md#on-mouse-over)
124+
* [On mouseover](6.md#on-mouseover)
125125
* [Cache redirects](6.md#cache-redirects)
126126
* [Batching](6.md#batching)
127127
* [Persisting](6.md#persisting)

text/bg.md

+40-8
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ Chapter contents:
1717
* [localStorage vs. cookies](bg.md#localstorage-vs-cookies)
1818
* [Browser performance](bg.md#browser-performance)
1919

20-
2120
---
2221

2322
This chapter provides concise introductions to various background topics. You’re welcome to either read them all up front or individually as you go along—at the beginning of a section, you’ll find a list of topics it assumes knowledge of, like the [Anywhere: HTTP](5.md#anywhere-http) section, which has two listed:
@@ -202,7 +201,40 @@ graphql(schema, query).then(result => {
202201

203202
# HTTP
204203

205-
HTTP is a format for sending messages over the Internet. It is used on top of two other message formats—IP (which has an *IP address* and routes the message to the right machine) and TCP (which has a port number and resends any messages that are lost in transit). An HTTP message adds a *method* (like `GET` or `POST`), a path (like `/graphql`), headers (like the `Bearer` header we use for [authentication](#authentication)), and a body (where GraphQL queries and responses go).
204+
HTTP is a format for sending messages over the Internet. It is used on top of two other message formats—IP (which has an *IP address* and routes the message to the right machine) and TCP (which has a port number and resends any messages that are lost in transit). An HTTP message adds a *method* (like `GET` or `POST`), a path (like `/graphql`), headers (like the `Bearer` header we use for [authentication](#authentication)), and a body (where GraphQL queries and responses go).
205+
206+
When we enter a URL like `http://graphql.guide/` into our browser, it goes through these steps:
207+
208+
1. Browser asks DNS server what the IP address of `graphql.guide` is.
209+
2. DNS server responds with `104.27.191.39`.
210+
211+
We can see for ourselves what the DNS server says using the `nslookup` command:
212+
213+
```sh
214+
$ nslookup graphql.guide
215+
Server: 8.8.4.4
216+
Address: 8.8.4.4#53
217+
218+
Non-authoritative answer:
219+
Name: graphql.guide
220+
Address: 104.27.191.39
221+
```
222+
223+
3. Browser sends out a message to the Internet that looks like this:
224+
225+
```
226+
IP to 104.27.191.39
227+
TCP to port 80
228+
HTTP GET /
229+
```
230+
231+
4. Internet routers look at the IP part, see it is addressed to `104.27.191.39`, and pass it off to a router that is closer to `104.27.191.39`.
232+
233+
5. The message arrives at `104.27.191.39` (the IP address of the Guide server), which opens the message, sees that it's trying to connect to port 80, and passes the message to whatever server program (in this case a Node.js process) is listening at the port.
234+
235+
6. The server process sees that the client wants to GET /, the root path, and sends back an `index.html` to the client.
236+
237+
> This process is a little simplified—it actually takes a separate round-trip message to set up the TCP connection, and for `graphql.guide`, the client is actually redirected to HTTPS at the beginning, which uses port 443 and sets up an SSL connection before sending HTTP GET /.
206238
207239
# SPA
208240

@@ -263,7 +295,7 @@ Then our server parses the JSON to figure out what happened. In this case, the `
263295

264296
# Continuous integration
265297

266-
While continuous integration (CI) technically means merging to master frequently, in modern web development it usually means the process of tests being run automatically on each commit. It's often done with a service like [CircleCI](https://circleci.com/) that monitors our commits on Github, runs the tests on their servers, and provides a webpage for each commit where we can view the test output. We can also set it up to do something after the test, such as:
298+
While continuous integration (CI) technically means merging to master frequently, in modern web development it usually means the process of tests being run automatically on each commit. It's often done with a service like [CircleCI](https://circleci.com/) that monitors our commits on GitHub, runs the tests, and provides a webpage for each commit where we can view the test output. We can also set it up to do something after the test, such as:
267299

268300
- Mark a pull request as passing or failing the tests.
269301
- Mark that commit as passing or failing by adding a red X or green checkmark next to the commit in the repository's history.
@@ -311,18 +343,18 @@ While the XSS issue is a serious concern, a common mitigation is setting short e
311343

312344
# Browser performance
313345

314-
Users notice when sites are slow, and they don't like it 😄. So if we want our users to feel good using our site, we want things in the browser to happen at a certain speed.
346+
Users notice when sites are slow, and they don't like it 😄. So if we want our users to feel good using our site, we want different things in the browser to happen at certain speeds.
315347

316348
First let's go over how the browser works. Because JavaScript is single-threaded, it can only run on a single CPU core. We can have particular pieces of JS run in [Web Workers](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers), which can run on different cores, but most of our JS runs on one core, in the browser's **main thread**. The browser also needs to do most of its page **rendering** (parsing HTML and CSS, laying out elements, painting pixels into images, etc) in the main thread.
317349

318350
> **Composition**, in which the pixel images are positioned, happens on the GPU.
319351
320352
A CPU core has a limited speed—it can only do a certain amount of work each millisecond. And because both JS and rendering happen on the same core, every millisecond our JS takes up is another millisecond the browser rendering has to wait before it can run. And the user won't see the page update until the browser has a chance to render.
321353

322-
Now that we know what's going on, let's think about different situations the user is in, and how fast our site should be in each:
354+
Now that we know what's going on, let's think about different situations the user is in and how fast our site should be in each:
323355

324356
- **Page load:** The faster the better, but good targets are under 5 seconds *time to interactive* (the page is interactive when content has been displayed and the page is interactable—it can be scrolled, things can be clicked on, etc.) for the first visit and under 2 seconds for subsequent visits.
325-
- **Response:** When humans take an action like clicking a button, and the page changes within 100 milliseconds, they generally perceive the response as immediate. If the response takes over 100ms, humans perceive a delay. If our event handler runs code that takes 100ms on slow devices, then we want to break the code into two pieces: the minimum amount that will trigger the desired UI change, and the rest. And we schedule the rest to be done later:
357+
- **Response:** When humans take an action like clicking a button, and the page changes within 100 milliseconds, they generally perceive the response as immediate. If the response takes over 100ms, humans perceive a delay. If our click event handler runs code that takes 100ms on slow devices, then we want to break the code into two pieces: the minimum amount that will trigger the desired UI change, and the rest. And we schedule the rest to be done later:
326358

327359
```js
328360
button.onclick = () => {
@@ -342,6 +374,6 @@ class Foo extends Component {
342374
}
343375
```
344376

345-
[requestIdleCallback()](https://developer.mozilla.org/en-US/docs/Web/API/Window/requestIdleCallback) runs the given function when the browser is idle, after it has finished rendering the changes triggered by `updateUI()`.
377+
[requestIdleCallback()](https://developer.mozilla.org/en-US/docs/Web/API/Window/requestIdleCallback) runs the given function when the browser is idle, after it has finished rendering the changes triggered by `updateUI()`/`this.setState()`.
346378

347-
- **Animation:** Humans perceive a motion as smooth at 60 fps—when 60 frames are rendered per second. If we take 1000 milliseconds and divide by 60, we get 16. So while something is moving on the page, we want the browser to be able to render every 16ms. The browser needs 6ms to paint, which gives us 10ms left to run JS in. "Something moving" includes visual animations like entrances/exits and loading indicators, scrolling, and dragging.
379+
- **Animation:** Humans perceive a motion as smooth at 60 fps—when 60 frames are rendered per second. If we take 1000 milliseconds and divide by 60, we get 16. So while something is moving on the page, we want the browser to be able to render every 16ms. The browser needs 6ms to paint, which gives us 10ms left to run JS in. "Something moving" includes visual animations like entrances/exits and loading indicators, scrolling, and dragging.

0 commit comments

Comments
 (0)