mirror of
https://github.com/kou029w/intro-to-graphql.git
synced 2025-02-01 14:48:42 +00:00
Compare commits
5 commits
a33bccb916
...
0d345f7c3a
Author | SHA1 | Date | |
---|---|---|---|
0d345f7c3a | |||
5c52d1c4ff | |||
c55a4de62b | |||
f7d6ae1d7e | |||
50d7364e51 |
5 changed files with 40 additions and 130 deletions
4
.github/workflows/github-pages.yml
vendored
4
.github/workflows/github-pages.yml
vendored
|
@ -11,8 +11,8 @@ jobs:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- run: npx @marp-team/marp-cli README.md -o pages/index.html
|
- run: make build
|
||||||
- uses: actions/upload-pages-artifact@v1
|
- uses: actions/upload-pages-artifact@v1
|
||||||
with:
|
with:
|
||||||
path: pages
|
path: dist
|
||||||
- uses: actions/deploy-pages@v1
|
- uses: actions/deploy-pages@v1
|
||||||
|
|
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
dist
|
4
Makefile
Normal file
4
Makefile
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
.PHONY: build
|
||||||
|
build:
|
||||||
|
npx @marp-team/marp-cli README.md -o dist/index.html
|
||||||
|
rsync -av assets/ dist/assets/
|
161
README.md
161
README.md
|
@ -6,7 +6,7 @@ paginate: true
|
||||||
|
|
||||||
# GraphQL 概論
|
# GraphQL 概論
|
||||||
|
|
||||||
WebDINO Japan エンジニア
|
WebDINO Japan シニアエンジニア
|
||||||
[渡邉浩平](https://github.com/kou029w)
|
[渡邉浩平](https://github.com/kou029w)
|
||||||
![w:200](https://github.com/kou029w.png)
|
![w:200](https://github.com/kou029w.png)
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ WebDINO Japan エンジニア
|
||||||
|
|
||||||
## 人気の技術
|
## 人気の技術
|
||||||
|
|
||||||
![bg right:72% State of JS 2020](https://stateofx-images.netlify.app/captures/js2020/en-US/datalayer_experience_ranking.png)
|
![bg right:72% State of JS 2020](./assets/datalayer-experience-ranking.png)
|
||||||
|
|
||||||
データ層分野
|
データ層分野
|
||||||
|
|
||||||
|
@ -75,7 +75,7 @@ https://graphql-pokemon2.vercel.app
|
||||||
- 2019 年 [GraphQL Foundation](https://graphql.org/foundation/) に移管
|
- 2019 年 [GraphQL Foundation](https://graphql.org/foundation/) に移管
|
||||||
|
|
||||||
Facebook が GraphQL を開発した理由は、[モバイルネイティブアプリ対応のため](https://reactjs.org/blog/2015/05/01/graphql-introduction.html)
|
Facebook が GraphQL を開発した理由は、[モバイルネイティブアプリ対応のため](https://reactjs.org/blog/2015/05/01/graphql-introduction.html)
|
||||||
スマホの普及に伴う低速、省電力なデバイスの利用の増加が背景
|
スマートフォン普及に伴うプラットフォームの多様化が背景
|
||||||
|
|
||||||
現在はオープンソースな仕様になっており、自由に貢献できる
|
現在はオープンソースな仕様になっており、自由に貢献できる
|
||||||
https://github.com/graphql/graphql-spec
|
https://github.com/graphql/graphql-spec
|
||||||
|
@ -236,7 +236,6 @@ apollo.fetch(query: pokemonQuery) { result in
|
||||||
#### 便利なツールの紹介
|
#### 便利なツールの紹介
|
||||||
|
|
||||||
- GraphiQL … GraphQL の開発環境
|
- GraphiQL … GraphQL の開発環境
|
||||||
- GraphQL Playground … より強力な GraphQL の開発環境
|
|
||||||
- Public GraphQL APIs … 公開されている GraphQL API の一覧
|
- Public GraphQL APIs … 公開されている GraphQL API の一覧
|
||||||
- GraphQL Code Generator … 自動コード生成
|
- GraphQL Code Generator … 自動コード生成
|
||||||
- Hasura … GraphQL サーバー
|
- Hasura … GraphQL サーバー
|
||||||
|
@ -251,14 +250,6 @@ apollo.fetch(query: pokemonQuery) { result in
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
#### GraphQL Playground
|
|
||||||
|
|
||||||
![h:600 GraphQL Playground](https://i.imgur.com/AE5W6OW.png)
|
|
||||||
|
|
||||||
<!-- _footer: https://github.com/graphql/graphql-playground -->
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
#### Public GraphQL APIs
|
#### Public GraphQL APIs
|
||||||
|
|
||||||
公開されている GraphQL API 一覧の紹介
|
公開されている GraphQL API 一覧の紹介
|
||||||
|
@ -474,15 +465,11 @@ query {
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
### 子孫関係の取得例
|
### 子孫関係
|
||||||
|
|
||||||
```text
|
フィールドにフィールドを追加することで子孫関係を取得できる
|
||||||
https://graphql-pokemon2.vercel.app/?query=query%20%7B%0A%20%20pokemon(name%3A%20%22Pikachu%22)%20%7B%0A%20%20%20%20classification%0A%20%20%20%20height%20%7B%0A%20%20%20%20%20%20minimum%0A%20%20%20%20%20%20maximum%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D
|
|
||||||
```
|
|
||||||
|
|
||||||
[この URL にアクセス](<https://graphql-pokemon2.vercel.app/?query=query%20%7B%0A%20%20pokemon(name%3A%20%22Pikachu%22)%20%7B%0A%20%20%20%20classification%0A%20%20%20%20height%20%7B%0A%20%20%20%20%20%20minimum%0A%20%20%20%20%20%20maximum%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D>)
|
[子孫関係の例](<https://graphql-pokemon2.vercel.app/?query=query%20%7B%0A%20%20pokemon(name%3A%20%22Pikachu%22)%20%7B%0A%20%20%20%20classification%0A%20%20%20%20height%20%7B%0A%20%20%20%20%20%20minimum%0A%20%20%20%20%20%20maximum%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D>)
|
||||||
|
|
||||||
または
|
|
||||||
|
|
||||||
```graphql
|
```graphql
|
||||||
query {
|
query {
|
||||||
|
@ -490,25 +477,7 @@ query {
|
||||||
classification
|
classification
|
||||||
height {
|
height {
|
||||||
minimum # <=
|
minimum # <=
|
||||||
maximum # <= これらのフィールドが加わる
|
maximum # <= これらのフィールド
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
### 子孫関係
|
|
||||||
|
|
||||||
フィールドにフィールドを追加することで子孫関係を取得できる
|
|
||||||
|
|
||||||
```graphql
|
|
||||||
query {
|
|
||||||
pokemon(name: "Pikachu") {
|
|
||||||
classification
|
|
||||||
height {
|
|
||||||
minimum
|
|
||||||
maximum
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -534,15 +503,11 @@ https://graphql-pokemon2.vercel.app
|
||||||
|
|
||||||
### 発展的な構文
|
### 発展的な構文
|
||||||
|
|
||||||
---
|
- 変数 … Query を再利用できる
|
||||||
|
- 操作名 … 複数の操作を識別できる
|
||||||
### 変数の使用例
|
- エイリアス … フィールドに名前を付ける
|
||||||
|
- フラグメント … いくつかのフィールドをまとめる
|
||||||
```text
|
- ディレクティブ … Query を修飾できる
|
||||||
https://graphql-pokemon2.vercel.app/?query=query%20(%24name%3A%20String!)%20%7B%0A%20%20pokemon(name%3A%20%24name)%20%7B%0A%20%20%20%20classification%0A%20%20%20%20height%20%7B%0A%20%20%20%20%20%20minimum%0A%20%20%20%20%20%20maximum%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D&variables=%7B%0A%20%20%22name%22%3A%20%22Pikachu%22%0A%7D
|
|
||||||
```
|
|
||||||
|
|
||||||
[この URL にアクセス](<https://graphql-pokemon2.vercel.app/?query=query%20(%24name%3A%20String!)%20%7B%0A%20%20pokemon(name%3A%20%24name)%20%7B%0A%20%20%20%20classification%0A%20%20%20%20height%20%7B%0A%20%20%20%20%20%20minimum%0A%20%20%20%20%20%20maximum%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D&variables=%7B%0A%20%20%22name%22%3A%20%22Pikachu%22%0A%7D>)
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
@ -550,6 +515,8 @@ https://graphql-pokemon2.vercel.app/?query=query%20(%24name%3A%20String!)%20%7B%
|
||||||
|
|
||||||
変数を使うことで Query を再利用できる
|
変数を使うことで Query を再利用できる
|
||||||
|
|
||||||
|
[変数の使用例](<https://graphql-pokemon2.vercel.app/?query=query%20(%24name%3A%20String!)%20%7B%0A%20%20pokemon(name%3A%20%24name)%20%7B%0A%20%20%20%20classification%0A%20%20%20%20height%20%7B%0A%20%20%20%20%20%20minimum%0A%20%20%20%20%20%20maximum%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D&variables=%7B%0A%20%20%22name%22%3A%20%22Pikachu%22%0A%7D>)
|
||||||
|
|
||||||
<!-- prettier-ignore-start -->
|
<!-- prettier-ignore-start -->
|
||||||
```graphql
|
```graphql
|
||||||
query ($name: String!) { # <= 変数の定義
|
query ($name: String!) { # <= 変数の定義
|
||||||
|
@ -569,13 +536,11 @@ query ($name: String!) { # <= 変数の定義
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
### 操作名の使用例
|
### 操作名
|
||||||
|
|
||||||
```text
|
操作に名前を付けることで複数の操作を識別できる
|
||||||
https://graphql-pokemon2.vercel.app/?query=query%20fetchPokemonNames%20%7B%0A%20%20pokemons(first%3A%20151)%20%7B%0A%20%20%20%20name%0A%20%20%7D%0A%7D%0A%0Aquery%20fetchPikachu%20%7B%0A%20%20pokemon(name%3A%20%22Pikachu%22)%20%7B%0A%20%20%20%20classification%0A%20%20%7D%0A%7D&operationName=fetchPokemonNames
|
|
||||||
```
|
|
||||||
|
|
||||||
[この URL にアクセス](<https://graphql-pokemon2.vercel.app/?query=query%20fetchPokemonNames%20%7B%0A%20%20pokemons(first%3A%20151)%20%7B%0A%20%20%20%20name%0A%20%20%7D%0A%7D%0A%0Aquery%20fetchPikachu%20%7B%0A%20%20pokemon(name%3A%20%22Pikachu%22)%20%7B%0A%20%20%20%20classification%0A%20%20%7D%0A%7D&operationName=fetchPokemonNames>)
|
[操作名の使用例](<https://graphql-pokemon2.vercel.app/?query=query%20fetchPokemonNames%20%7B%0A%20%20pokemons(first%3A%20151)%20%7B%0A%20%20%20%20name%0A%20%20%7D%0A%7D%0A%0Aquery%20fetchPikachu%20%7B%0A%20%20pokemon(name%3A%20%22Pikachu%22)%20%7B%0A%20%20%20%20classification%0A%20%20%7D%0A%7D&operationName=fetchPokemonNames>)
|
||||||
|
|
||||||
<!-- prettier-ignore-start -->
|
<!-- prettier-ignore-start -->
|
||||||
```graphql
|
```graphql
|
||||||
|
@ -593,39 +558,15 @@ query fetchPikachu { # <= 操作に名前を付ける
|
||||||
```
|
```
|
||||||
<!-- prettier-ignore-end -->
|
<!-- prettier-ignore-end -->
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
### 操作名
|
|
||||||
|
|
||||||
操作に名前を付けることで複数の操作を識別できる
|
|
||||||
|
|
||||||
```graphql
|
|
||||||
query fetchPokemonNames {
|
|
||||||
pokemons(first: 151) {
|
|
||||||
name
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
query fetchPikachu {
|
|
||||||
pokemon(name: "Pikachu") {
|
|
||||||
classification
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
`fetchPokemonNames`, `fetchPikachu` … 操作名
|
`fetchPokemonNames`, `fetchPikachu` … 操作名
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
### エイリアスの使用例
|
### エイリアス
|
||||||
|
|
||||||
```text
|
フィールドに名前を付ける
|
||||||
https://graphql-pokemon2.vercel.app/?query=query%20%7B%0A%20%20pikachu%3A%20pokemon(name%3A%20%22Pikachu%22)%20%7B%0A%20%20%20%20classification%0A%20%20%7D%0A%7D&variables=
|
|
||||||
```
|
|
||||||
|
|
||||||
[この URL にアクセス](<https://graphql-pokemon2.vercel.app/?query=query%20%7B%0A%20%20pikachu%3A%20pokemon(name%3A%20%22Pikachu%22)%20%7B%0A%20%20%20%20classification%0A%20%20%7D%0A%7D>)
|
[エイリアスの使用例](<https://graphql-pokemon2.vercel.app/?query=query%20%7B%0A%20%20pikachu%3A%20pokemon(name%3A%20%22Pikachu%22)%20%7B%0A%20%20%20%20classification%0A%20%20%7D%0A%7D>)
|
||||||
|
|
||||||
または
|
|
||||||
|
|
||||||
<!-- prettier-ignore-start -->
|
<!-- prettier-ignore-start -->
|
||||||
```graphql
|
```graphql
|
||||||
|
@ -637,9 +578,7 @@ query {
|
||||||
```
|
```
|
||||||
<!-- prettier-ignore-end -->
|
<!-- prettier-ignore-end -->
|
||||||
|
|
||||||
---
|
取得結果
|
||||||
|
|
||||||
#### 取得結果
|
|
||||||
|
|
||||||
<!-- prettier-ignore-start -->
|
<!-- prettier-ignore-start -->
|
||||||
```json
|
```json
|
||||||
|
@ -655,37 +594,14 @@ query {
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
### エイリアス
|
|
||||||
|
|
||||||
フィールドに名前を付ける
|
|
||||||
|
|
||||||
```graphql
|
|
||||||
query {
|
|
||||||
pikachu: pokemon(name: "Pikachu") {
|
|
||||||
classification
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
`pikachu` … エイリアス
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
### フラグメントの使用例
|
|
||||||
|
|
||||||
```text
|
|
||||||
https://graphql-pokemon2.vercel.app/?query=fragment%20dimension%20on%20PokemonDimension%20%7B%0A%20%20minimum%0A%20%20maximum%0A%7D%0A%0Aquery%20%7B%0A%20%20pokemon(name%3A%20%22Pikachu%22)%20%7B%0A%20%20%20%20classification%0A%20%20%20%20height%20%7B%0A%20%20%20%20%20%20...dimension%0A%20%20%20%20%7D%0A%20%20%20%20weight%20%7B%0A%20%20%20%20%20%20...dimension%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D
|
|
||||||
```
|
|
||||||
|
|
||||||
[この URL にアクセス](<https://graphql-pokemon2.vercel.app/?query=fragment%20dimension%20on%20PokemonDimension%20%7B%0A%20%20minimum%0A%20%20maximum%0A%7D%0A%0Aquery%20%7B%0A%20%20pokemon(name%3A%20%22Pikachu%22)%20%7B%0A%20%20%20%20classification%0A%20%20%20%20height%20%7B%0A%20%20%20%20%20%20...dimension%0A%20%20%20%20%7D%0A%20%20%20%20weight%20%7B%0A%20%20%20%20%20%20...dimension%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D>)
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
### フラグメント
|
### フラグメント
|
||||||
|
|
||||||
いくつかのフィールドをまとめ、そのフィールドを取得する際に使用できる
|
いくつかのフィールドをまとめ、そのフィールドを取得する際に使用できる
|
||||||
|
|
||||||
|
[フラグメントの使用例](<https://graphql-pokemon2.vercel.app/?query=fragment%20dimension%20on%20PokemonDimension%20%7B%0A%20%20minimum%0A%20%20maximum%0A%7D%0A%0Aquery%20%7B%0A%20%20pokemon(name%3A%20%22Pikachu%22)%20%7B%0A%20%20%20%20classification%0A%20%20%20%20height%20%7B%0A%20%20%20%20%20%20...dimension%0A%20%20%20%20%7D%0A%20%20%20%20weight%20%7B%0A%20%20%20%20%20%20...dimension%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D>)
|
||||||
|
|
||||||
```graphql
|
```graphql
|
||||||
|
# フラグメントの定義
|
||||||
fragment dimension on PokemonDimension {
|
fragment dimension on PokemonDimension {
|
||||||
minimum
|
minimum
|
||||||
maximum
|
maximum
|
||||||
|
@ -695,34 +611,22 @@ query {
|
||||||
pokemon(name: "Pikachu") {
|
pokemon(name: "Pikachu") {
|
||||||
classification
|
classification
|
||||||
height {
|
height {
|
||||||
...dimension
|
...dimension # <= フラグメントの使用
|
||||||
}
|
}
|
||||||
weight {
|
weight {
|
||||||
...dimension
|
...dimension # <= フラグメントの使用
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
`dimension` … フラグメント
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
### ディレクティブの使用例
|
|
||||||
|
|
||||||
```text
|
|
||||||
https://graphql-pokemon2.vercel.app/?query=query%20(%24showClassification%3A%20Boolean!)%20%7B%0A%20%20pokemon(name%3A%20%22Pikachu%22)%20%7B%0A%20%20%20%20classification%20%40include(if%3A%20%24showClassification)%0A%20%20%7D%0A%7D%0A&variables=%7B%0A%20%20%22showClassification%22%3A%20true%0A%7D
|
|
||||||
```
|
|
||||||
|
|
||||||
[この URL にアクセス](<https://graphql-pokemon2.vercel.app/?query=query%20(%24showClassification%3A%20Boolean!)%20%7B%0A%20%20pokemon(name%3A%20%22Pikachu%22)%20%7B%0A%20%20%20%20classification%20%40include(if%3A%20%24showClassification)%0A%20%20%7D%0A%7D%0A&variables=%7B%0A%20%20%22showClassification%22%3A%20true%0A%7D>)
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
### ディレクティブ
|
### ディレクティブ
|
||||||
|
|
||||||
Query を修飾できる
|
Query を修飾できる
|
||||||
|
|
||||||
`@include` ディレクティブの例
|
[`@include` ディレクティブの使用例](<https://graphql-pokemon2.vercel.app/?query=query%20(%24showClassification%3A%20Boolean!)%20%7B%0A%20%20pokemon(name%3A%20%22Pikachu%22)%20%7B%0A%20%20%20%20classification%20%40include(if%3A%20%24showClassification)%0A%20%20%7D%0A%7D%0A&variables=%7B%0A%20%20%22showClassification%22%3A%20true%0A%7D>)
|
||||||
|
|
||||||
```graphql
|
```graphql
|
||||||
query ($showClassification: Boolean!) {
|
query ($showClassification: Boolean!) {
|
||||||
|
@ -752,11 +656,12 @@ query ($showClassification: Boolean!) {
|
||||||
- フィールド
|
- フィールド
|
||||||
- 引数と値
|
- 引数と値
|
||||||
- 子孫関係
|
- 子孫関係
|
||||||
- 変数 … Query を再利用できる
|
- 発展的な構文
|
||||||
- 操作名 … 複数の操作を識別できる
|
- 変数
|
||||||
- エイリアス … フィールドに名前を付ける
|
- 操作名
|
||||||
- フラグメント … いくつかのフィールドをまとめる
|
- エイリアス
|
||||||
- ディレクティブ … Query を修飾できる
|
- フラグメント
|
||||||
|
- ディレクティブ
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
BIN
assets/datalayer-experience-ranking.png
Normal file
BIN
assets/datalayer-experience-ranking.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 186 KiB |
Loading…
Add table
Reference in a new issue