Skip to content

Commit c7d0614

Browse files
committed
Last edits from tech review
1 parent b013b06 commit c7d0614

File tree

10 files changed

+119
-90
lines changed

10 files changed

+119
-90
lines changed

README.md

+12-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1-
# The GraphQL Guide
2-
31
This repo contains the text of The GraphQL Guide.
42

53
## Supporting
64

75
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).
86

7+
## Contributors
8+
9+
[/GraphQLGuide/book/graphs/contributors](https://github.com/GraphQLGuide/book/graphs/contributors)
10+
11+
Thank you to everyone who has contributed 😃🙌
12+
913
## Contributing
1014

11-
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 😊
1216

1317
### Setup
1418

@@ -18,4 +22,8 @@ If you're working on gitbook-related issues or want to see how your PR will be f
1822
npm i -g gitbook
1923
gitbook install
2024
mkdir out/
21-
```
25+
```
26+
27+
---
28+
29+
[Changelog](https://github.com/GraphQLGuide/book/releases) (we use Github releases)

text/1.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ Thus far we’ve been retrieving data in a way that is stylistically similar to
624624

625625
The client should be in control of requesting the data they want from the server. Ideally, this should be done in a single HTTP request. With REST, we can either make multiple HTTP requests to get the different types of data we need for a page, or we can design a custom REST endpoint that returns everything all at once. GraphQL employs a different strategy: a GraphQL endpoint can return many types and execute many queries, not just one. This gives the caller the power of being able to fetch any and all data needed in a single request.
626626

627-
If we want to request multiple types of data with a basic REST APIone in which each endpoint deals with a single typeit might look something like this:
627+
If we want to request multiple types of data with a basic REST APIone in which each endpoint deals with a single typeour client code might look something like this:
628628

629629
```js
630630
const getUserWithGroup = user =>
@@ -643,7 +643,7 @@ fetch('http://localhost:3000/users')
643643
})
644644
```
645645

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 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:
647647

648648
```js
649649
import { request } from 'graphql-request'
@@ -751,10 +751,10 @@ In this case, we’re requesting three query fields simultaneously (getting a li
751751

752752
In summary, the advantages of using GraphQL for fetching multiple data types are:
753753

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).
758758

759759
# Security & error handling
760760

text/11.md

+24-24
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,30 @@
22

33
Chapter contents:
44

5-
* [Setting up node](11.md#setting-up-node)
6-
* [Writing good schemas](11.md#writing-good-schemas)
7-
* [Writing resolvers](11.md#writing-resolvers)
8-
* [Structuring the server](11.md#structuring-the-server)
9-
* [Schema](11.md#schema-server)
10-
* [Models & connectors](11.md#models-&-connectors)
11-
* [Subscriptions](11.md#subscriptions)
12-
* [Connecting data sources](11.md#connecting-data-sources)
13-
* [SQL](11.md#sql)
14-
* [MongoDB](11.md#mongodb)
15-
* [REST APIs](11.md#rest-apis)
16-
* [Prisma](11.md#prisma)
17-
* [Redis](11.md#redis)
18-
* [Elasticsearch](11.md#elasticsearch)
19-
* [RethinkDB](11.md#rethinkdb)
20-
* [Security](11.md#security)
21-
* [Authentication](11.md#authentication-server)
22-
* [Authorization](11.md#authorization)
23-
* [Denial of service](11.md#denial-of-service)
24-
* [Extended topics](11.md#extended-topics)
25-
* [Caching](11.md#caching-server)
26-
* [Batching](11.md#batching)
27-
* [Prepared queries](11.md#prepared-queries)
28-
* [Testing](11.md#testing)
5+
* Setting up node
6+
* Writing good schemas
7+
* Writing resolvers
8+
* Structuring the server
9+
* Schema
10+
* Models & connectors
11+
* Subscriptions
12+
* Connecting data sources
13+
* SQL
14+
* MongoDB
15+
* REST APIs
16+
* Prisma
17+
* Redis
18+
* Elasticsearch
19+
* RethinkDB
20+
* Security
21+
* Authentication
22+
* Authorization
23+
* Denial of service
24+
* Extended topics
25+
* Caching
26+
* Batching
27+
* Prepared queries
28+
* Testing
2929

3030
---
3131

text/5.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ requests, including HTTP requests):
6060
$ curl -X POST \
6161
-H "Content-Type: application/json" \
6262
-d '{"query": "{ githubStars }"}' \
63-
https://graphql.guide/graphql
63+
https://api.graphql.guide/graphql
6464
```
6565

6666
* `-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
175175

176176
## Typing
177177

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.
179179

180180
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).)
181181

text/6.md

+19-13
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,11 @@ meteor
128128

129129
[Meteor](https://www.meteor.com) is similar to Next in that it is not only the
130130
build tool but also the production server. Unlike CRA and Next, it does not use
131-
Webpack—it has its own build system that is blissfully
131+
Webpack—it has its own advanced build system that is blissfully
132132
configuration-free. It does not have built-in SSR like Next does, but it does
133133
have dynamic imports, and all dynamically imported modules are fetched quickly
134-
over a WebSocket and cached on the client (in
135-
[IndexedDB](https://en.wikipedia.org/wiki/Indexed_Database_API)).
134+
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.
136136

137137
## App structure
138138

@@ -471,7 +471,7 @@ And we have a working GraphQL-backed app!
471471

472472
`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.
473473

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:
475475

476476
```js
477477
import { graphql } from 'react-apollo'
@@ -3063,12 +3063,12 @@ const USER_QUERY = gql`
30633063
}
30643064
```
30653065

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>`:
30673067

30683068
[`src/components/App.js`](https://github.com/GraphQLGuide/guide/compare/10_0.0.3...11_0.0.3)
30693069

30703070
```js
3071-
<Route render={() => <Book user={this.props.user} />} />
3071+
<Route render={() => <Book user={this.props.user} />} />
30723072
```
30733073

30743074
And then to `<Reviews>`:
@@ -3133,6 +3133,7 @@ import remove from 'lodash/remove'
31333133
const READ_USER_FAVORITES = gql`
31343134
query ReadUserFavorites {
31353135
currentUser {
3136+
id
31363137
favoriteReviews {
31373138
id
31383139
}
@@ -4214,7 +4215,7 @@ Review.propTypes = {
42144215
}
42154216
```
42164217

4217-
![Hidden review icons](/imp/hidden-review-icons.png)
4218+
![Hidden review icons](/img/hidden-review-icons.png)
42184219

42194220
## Editing reviews
42204221

@@ -4901,11 +4902,17 @@ const withReviews = graphql(REVIEWS_QUERY, {
49014902
reviews,
49024903
networkStatus,
49034904
loadMoreReviews: () => {
4904-
const lastId = reviews && reviews[reviews.length - 1].id
4905+
if (!reviews) {
4906+
return
4907+
}
4908+
4909+
const lastId = reviews[reviews.length - 1].id
49054910
return fetchMore({
49064911
variables: { after: lastId },
49074912
```
49084913

4914+
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+
49094916
We also have to remove `skip` from `withAddReview` and `withDeleteMutation`, and update the query:
49104917

49114918
[`src/graphql/Review.js`](https://github.com/GraphQLGuide/guide/compare/17_0.0.3...18_0.0.3)
@@ -5041,9 +5048,8 @@ The tricky part here is that we don’t know if the list of reviews with `orderB
50415048

50425049
---
50435050

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 😊.
50475052

5048-
[GitHub issues: book text](https://github.com/GraphQLGuide/book/issues)
5049-
[GitHub issues: code](https://github.com/GraphQLGuide/guide/issues)
5053+
- <authors@graphql.guide>
5054+
- [GitHub issues: book text](https://github.com/GraphQLGuide/book/issues)
5055+
- [GitHub issues: code](https://github.com/GraphQLGuide/guide/issues)

text/8.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Chapter 8: React Native
22

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).
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).

text/README.md

+25-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
# Introduction
22

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+
314
# Who is this book for?
415

516
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
6273

6374
## Git
6475

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`.
6677

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:
6879

6980
```sh
7081
git clone [email protected]:GraphQLGuide/guide.git
@@ -76,7 +87,7 @@ npm start
7687

7788
> Check out the [git](bg.md#git) and [npm](bg.md#npm) background sections if you’re unfamiliar with these commands.
7889
79-
If we get stuck, we can look at the difference between step 9 and step 10 with GitHub’s compare feature:
90+
If we get stuck, we can look at the diff between step 9 and step 10 with GitHub’s compare feature:
8091

8192
`github.com/[repository]/compare/[tag 1]...[tag 2]`
8293

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

123134
# Version
124135

125-
Book version `0.1.0`
136+
Book version: [`r1`](https://github.com/GraphQLGuide/book/releases)
137+
138+
Published June 11, 2018
126139

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)).
141+
142+
## Chapter 6
143+
144+
Code version: [`0.1.0`](https://github.com/GraphQLGuide/guide/blob/master/CHANGELOG.md)
128145

129146
```
130-
graphql @ 0.13
131-
react-apollo @ 2.1
132-
react @ 16.3
147+
react-apollo 2.1
148+
graphql 0.13
149+
react 16.3
133150
```
134-
135-
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

Comments
 (0)