Created
June 23, 2016 20:58
-
-
Save chuck0523/50d08985346a878d9e80fa191d4d7703 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 通常のフィールド | |
{ | |
recentPosts(count: 10) { | |
title | |
} | |
} | |
# queryキーワードでクエリに名前をつけられる。 | |
query getFewPosts { | |
recentPosts(count: 10) { | |
title | |
} | |
} | |
# クエリのcountを変数化できる。!はrequiredを意味している。 | |
query getFewPosts($postCount: Int!) { | |
recentPosts(count: $postCount) { | |
title | |
} | |
} | |
# クエリ変数は以下のようにして使う。 | |
{ | |
"postCount" : 2 | |
} | |
# 複数のクエリ変数を同時に使う。 | |
query getFewPosts($postCount: Int!, $commentCount: Int) { | |
recentPosts(count: $postCount) { | |
title, | |
comments(limit: $commentCount) { | |
content | |
} | |
} | |
} | |
query getFewPosts($postCount: Int!, $commentCount: Int) { | |
recentPosts(count: $postCount) { | |
title, | |
...comments | |
} | |
} | |
# クエリ変数はフラグメント内でも利用可能。 | |
fragment comments on Post { | |
comments(limit: $commentCount) { | |
content | |
} | |
} | |
# クエリ変数には、Int, String, Float, Booleanや、Enum、あるいは、それらのArrayしか指定できない。 | |
query getFewPosts($category: Category) { | |
posts(category: $category) { | |
title | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment