22 { status: 'available' }
29 { hero { name height } }
36 { name: "Luke Skywalker",
51 [ { name: "Luke Skywalker" },
57 GraphQL queries look the same for both single items or lists of items.
63 hero(id: "1000") { id name }
72 { name: "Luke Skywalker" } }
80 luke: hero(id: "1000") { name }
81 han: hero(id: "1001") { name }
89 { name: "Luke Skywalker" },
91 { name: "Han Solo" } }
95 ### Operation names and variables
99 query FindHero($id: String!) {
100 hero(id: $id) { name }
104 Just to make things less ambiguous. Also, to use variables, you need an operation name.
117 { createReview($review) { id } }
123 { review: { stars: 5 } }
129 { createReview: { id: 5291 } }
132 Mutations are just fields that do something when queried.
141 ... on Comment { body author { name } }
155 fetch('http://myapi/graphql?query={ me { name } }')
161 fetch('http://myapi/graphql', {
162 body: JSON.stringify({
164 operationName: '...',
179 users(limit: Int): [User]
188 See: [sogko/graphql-shorthand-notation-cheat-sheet](https://raw.githubusercontent.com/sogko/graphql-shorthand-notation-cheat-sheet/master/graphql-shorthand-notation-cheat-sheet.png)
196 | `String` | String |
197 | `Boolean` | Boolean |
200 #### Type definitions
202 | `scalar` | Scalar type |
203 | `type` | Object type |
204 | `interface` | Interface type |
205 | `union` | Union type |
206 | `enum` | Enumerable type |
207 | `input` | Input object type |
211 | `String` | Nullable string |
212 | `String!` | Required string |
213 | `[String]` | List of strings |
214 | `[String]!` | Required list of strings |
215 | `[String!]!` | Required list of required strings |
221 users(params: ListUsersInput) [User]!
232 type User implements Entity {
247 direction: DIRECTION!
250 {: data-line="1,2,3,4"}
258 union Result = Artist | Album
261 search(q: String) [Result]
269 - <http://graphql.org/learn/queries/>
270 - <http://graphql.org/learn/serving-over-http/>