Skip to content

Instantly share code, notes, and snippets.

@chuck0523
Created June 23, 2016 20:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chuck0523/50d08985346a878d9e80fa191d4d7703 to your computer and use it in GitHub Desktop.
Save chuck0523/50d08985346a878d9e80fa191d4d7703 to your computer and use it in GitHub Desktop.
# 通常のフィールド
{
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