Skip to content

Commit 88273cd

Browse files
author
Kian Khoshnoodpour
committed
docs: rename and add spacex project
1 parent 38cc79a commit 88273cd

File tree

8 files changed

+198
-170
lines changed

8 files changed

+198
-170
lines changed

internals/wiki/01-my-first-query.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ Add the missing query, using the exact same name used as in the `schema.ts` file
5454

5555
## Assignment 1.3: Run your query in the playground
5656

57-
Now you should be able to run your query in the GraphQL playground environment: <http://localhost:3000/api/graphql>.
57+
Now you should be able to run your query in the GraphQL playground environment: <http://localhost:3007/api/graphql>.
5858

5959
> The playground provides an environment to test queries. It includes auto-complete, as you start typing it will provide suggestions. Click on the `schema` button on the right to see the entire schema.
6060
@@ -141,7 +141,7 @@ const query: QueryResolvers = {
141141

142142
Now we can query the fields on type **List** from the playground, using the **lists** query.
143143

144-
<http://localhost:3000/api/graphql>:
144+
<http://localhost:3007/api/graphql>:
145145

146146
```graphql
147147
{

internals/wiki/02-calling-graphql-from-react.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ const MyPage: NextPage = () => {
122122
export default withApollo(MyPage);
123123
```
124124

125-
You can now see your page, component and hopefully your data from GraphQL at <http://localhost:3000/my-page>.
125+
You can now see your page, component and hopefully your data from GraphQL at <http://localhost:3007/my-page>.
126126

127127
# Chapter 2 - Solution: Calling GraphQL from React
128128

@@ -211,4 +211,4 @@ const ListsPage: NextPage = () => {
211211
export default withApollo(ListsPage);
212212
```
213213

214-
Now we can go to <http://localhost:3000/favorites> and see all the users favorite lists in a nice box.
214+
Now we can go to <http://localhost:3007/favorites> and see all the users favorite lists in a nice box.

internals/wiki/04-covid-app.md

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
## Chapter 4: Project - COVID app
22

33
> [Backend, Frontend]
4+
> Continue from branch `master`
45
56
In this chapter we're going to use what we learned so far to build a covid app.
67

78
We're going to implement a GraphQL API using the Novel COVID open API at https://disease.sh/docs/#/JHUCSSE/get_v2_historical
89

910
We're going to use the endpoint: `https://disease.sh/v2/historical?lastdays=10`
1011

11-
### 4.1 Assignment: Figure out what this endpoint provides
12+
### Assignment 4.1: Figure out what this endpoint provides
1213

1314
First we look in the swagger at Responses where you can find the schema/model it provides:
1415

@@ -31,15 +32,15 @@ The schema is important to think about, since you will find out you can't take i
3132

3233
Create a schema based on the swagger definition. Then place this schema in `./pages/graphql/schema.ts`. Expose it via the query name `covidHistorical` under the Query part.
3334

34-
### 4.2 Assignment: Now expose the data in the form you schematised
35+
### Assignment 4.2: Now expose the data in the form you schematised
3536

3637
Almost there, now we have to fetch the actual data and resolve this. Add the 'covidHistorical' resolver in `./pages/graphql/resolver.ts` and fetch the async data and now normalise this data so it matches your schema!
3738

3839
```js
3940
const response = await fetch('https://disease.sh/v2/historical?lastdays=10');
4041
```
4142

42-
Its time to code, and at same time maybe look at http://localhost:3000/api/graphql to debug on the fly. Its also possible to run the app in debug mode, stop current one and then run `yarn dev:inspect`.
43+
Its time to code, and at same time maybe look at http://localhost:3007/api/graphql to debug on the fly. Its also possible to run the app in debug mode, stop current one and then run `yarn dev:inspect`.
4344

4445
After you exposed the data, you will find out that not every field is how you expected it to be. Also it happens that after exposing the data the schema you defined may not be so smart (for example repetition of data). So its common you adjust in this phase. It also happens when exposing more then one consumer. Think more, less problems on the long run.
4546

@@ -54,3 +55,17 @@ When you are done, run `yarn schema:linter`
5455
The end result can be something like:
5556

5657
<img src="./img/4-result.png" width="400px" />
58+
59+
## Chapter 4 - Solution: Project - COVID app
60+
61+
### Assignment Solutions
62+
63+
For the assignment solutions see branch `chapter-4-solution`
64+
65+
### Bonus Assignment Solutions
66+
67+
For the bonus assignment solutions see branches
68+
69+
- `chapter-4-bonus-1`
70+
- `chapter-4-bonus-2`
71+
- `chapter-4-bonus-3`

internals/wiki/09-union-types.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export const resolvers: Resolvers = {
7474

7575
## Assignment 9.3: Display the list items in your frontend
7676

77-
Now you should be able to run your union query in the GraphQL playground environment: http://localhost:3000/api/graphql.
77+
Now you should be able to run your union query in the GraphQL playground environment: http://localhost:3007/api/graphql.
7878

7979
You can test it with different id's (1 = product, 3 = recipe ).
8080

internals/wiki/14-integration-testing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ This could of course also be a mutation.
2020
To illustrate using `cURL`:
2121

2222
```sh
23-
curl --location --request POST 'http://localhost:3000/api/graphql' \
23+
curl --location --request POST 'http://localhost:3007/api/graphql' \
2424
--header 'Content-Type: application/json' \
2525
--data-raw '{ "query": "query myQuery(\$id: id) { myQuery { myData } }" }'
2626
```

internals/wiki/15-spacex-app.md

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
## Final Project: Spacex App
2+
3+
> Backend | Frontend
4+
> Continue from branch `master`
5+
6+
For this exercise we are going to look at the api of `https://api.spacexdata.com/v4/launches/latest` You will start from 'master' branch.
7+
8+
### Assignment 1: Expose its ships
9+
10+
In this endpoint you will find the following data:
11+
12+
```
13+
"ships": [
14+
"5ea6ed2e080df4000697c908",
15+
"5ea6ed2e080df4000697c907",
16+
"5ea6ed2f080df4000697c90b"
17+
],
18+
```
19+
20+
Create the graphql query 'spacexShips' which returns these ship id's. Nothing more. Make sure you can query:
21+
22+
```
23+
{
24+
spacexShips {
25+
id
26+
}
27+
}
28+
```
29+
30+
### Assignment 2: Expose ship information
31+
32+
We returned the ship identification number. On the endpoint: `https://api.spacexdata.com/v4/ships/ID` you will find ship information, so an example is: `https://api.spacexdata.com/v4/ships/5ea6ed2e080df4000697c908`.
33+
34+
Now add a field 'info' to this SpacexShip and resolve with the above endpoint. Expose: 'type', 'image' and 'launches'. For the last ones only its id. Keep it simple. No need to use dataloader yet.
35+
36+
### Assignment 3: Introduce dataloader for ship information
37+
38+
We saw we did request the ship information three times. This is not optimal. We dont have the batched endpoint available yet, but we can start optimizing our endpoint so it will execute the service call only once. Sometimes our services are not optimized for batches but we can start poor mens batching on our side.
39+
40+
Add a dataloader on the context (see for context `./pages/api/graphql/index`). And consume it on the info endpoint. You will need a Promise.all and as learned from our workshop dataloader passes a collection of id's and returns the responses in the same order.
41+
42+
### Assignment 4: Introduce dataloader and add launch information to a launch
43+
44+
We have learned how to extend and resolve on field level with having a dataloader in place. We start now doing the same for launch information.
45+
46+
The endpoint is: `https://api.spacexdata.com/v4/launches/ID` and example is `https://api.spacexdata.com/v4/launches/5eb87d0dffd86e000604b35b`.
47+
48+
Only expose the images collection. You will find it in:
49+
50+
```
51+
"links": {
52+
...
53+
"flickr": {
54+
"small": [],
55+
"original": [
56+
"https://farm5.staticflickr.com/4477/38056454431_a5f40f9fd7_o.jpg",
57+
"https://farm5.staticflickr.com/4455/26280153979_b8016a829f_o.jpg",
58+
"https://farm5.staticflickr.com/4459/38056455051_79ef2b949a_o.jpg",
59+
"https://farm5.staticflickr.com/4466/26280153539_ecbc2b3fa9_o.jpg",
60+
"https://farm5.staticflickr.com/4482/26280154209_bf08d76361_o.jpg",
61+
"https://farm5.staticflickr.com/4493/38056455211_a4565a9cee_o.jpg"
62+
]
63+
]
64+
},
65+
```
66+
67+
Make sure we are able to execute the following query:
68+
69+
```
70+
{
71+
spacexShips {
72+
id
73+
info {
74+
type
75+
image
76+
launches {
77+
id
78+
images
79+
}
80+
}
81+
}
82+
}
83+
```
84+
85+
### Assignment 5: Add cacheControl in the service
86+
87+
We see that we request lots of services, but we can cache from using the CacheControl directive. Lets cache all for 5 minutes shall we?
88+
89+
Turn on cacheControl on `./pages/api/graphql/index`.
90+
91+
```
92+
cacheControl: true,
93+
plugins: [responseCachePlugin()],
94+
```
95+
96+
Now:
97+
98+
- Add cacheControl directive to schema
99+
- Add cacheControl directive to the schema types
100+
101+
Restart the server if you added all. If you did it correctly you will see no cache hint in playground and you will see no real service calls.
102+
103+
So good, when playground extension is like:
104+
105+
```
106+
"extensions": {
107+
"cacheControl": {
108+
"version": 1,
109+
"hints": []
110+
}
111+
}
112+
```
113+
114+
### Assignment 6: Expose the data in an app (FRONTEND)
115+
116+
When you followed the previous steps (or checkout mpth-spacex-5 when you didnt want to do the server part) you are able to do the following query:
117+
118+
```
119+
{
120+
spacexShips {
121+
id
122+
info {
123+
type
124+
image
125+
launches {
126+
id
127+
images
128+
}
129+
}
130+
}
131+
}
132+
```
133+
134+
Make a new component and expose it on the first page.
135+
136+
<img src="./img/mpth.png" width="400px" />
137+
138+
### Assignment 7: Reuse dataloader for retrieving sinlge ship
139+
140+
Now add a single ship query and show us how you would do it. Its simple if you have the dataloader setup in place. Dont think too hard.
141+
142+
Make sure you can do the following query as the end of your coding results
143+
144+
```
145+
{
146+
spacexShip(id:"5ea6ed2e080df4000697c908") {
147+
id
148+
info {
149+
type
150+
}
151+
}
152+
}
153+
```
154+
155+
So add the query 'spacexShip' to your schema and show us how to resolve.
156+
157+
### Bonus
158+
159+
- show the images in the frontend
160+
- make endpoint for specific launch and re-use the dataloader. You will see you dont have to code anything simply use the dataloader
161+
- make two frontend components with a different launch ID and see how it works in the frontend (batched query)
162+
- do basically anything you want, you have the api, you own the data :)
163+
164+
## Final Project - Solution: Spacex App
165+
166+
The solutions for the project can be found under the branches
167+
168+
- `spacex-solution-1`
169+
- `spacex-solution-2`
170+
- `spacex-solution-3`
171+
- `spacex-solution-4`
172+
- `spacex-solution-5`
173+
- `spacex-solution-6`
174+
- `spacex-solution-7`

internals/wiki/16-undefined-app.md

Whitespace-only changes.

0 commit comments

Comments
 (0)