From 212bf44a31af0c21b49047afb7583026cf884a19 Mon Sep 17 00:00:00 2001 From: "Rico Sta. Cruz" Date: Wed, 28 Dec 2016 12:42:06 +0800 Subject: [PATCH] Update --- graphql.md | 47 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 35 insertions(+), 12 deletions(-) diff --git a/graphql.md b/graphql.md index 05be70455..e5de9404d 100644 --- a/graphql.md +++ b/graphql.md @@ -19,6 +19,16 @@ category: Misc // height: 1.74 } } ``` +### Lists +GraphQL queries look the same for both single items or lists of items. + +```js +{ friends { name } } +// → { friends: +// [ { name: "Luke Skywalker" }, +// { name: "Han Solo" }, +// { name: "R2D2" } ] } +``` ### Lookups ```js @@ -43,22 +53,16 @@ category: Misc // { name: "Han Solo" } } ``` -### Variables +### Operation names and variables + +Just to make things less ambiguous. Also, to use variables, you need an operation name. ```js -{ hero(id: $id) } // Query ---- -{ id: '1000' } // Variables -``` - -### Operation name - -Just to make things less ambiguous. - -```js -query FindHero($id: String) { +query FindHero($id: String!) { hero(id: $id) { name } } +--- +{ id: '1000' } // Variables ``` ### Mutations @@ -72,6 +76,20 @@ Mutations are just fields that do something when queried. // → { createReview: { id: 5291 } } ``` +### Multiple types + +Great for searching. + +```js +{ + search(q: "john") { + id + ... on User { name } + ... on Comment { body author { name } } + } +} +``` + Over HTTP --------- @@ -91,7 +109,12 @@ fetch('http://myapi/graphql', { "variables": { ... } }) }) +``` +Schema +------ + +See: References ----------