Graph QL
Graph QL
IO Edit
GraphQL cheatsheet
— Proudly sponsored by —
# Queries
Basic query Nesting Lists
↓ ↓ ↓
Aliases GraphQL queries look the same for both single items or
{
hero(id: "1000") { id name } lists of items.
} {
luke: hero(id: "1000") { name }
↓ han: hero(id: "1001") { name } Operation names and variables
}
{ hero: Query
{ id: "1000", ↓
{ name: "Luke Skywalker" } } query FindHero($id: String!) {
{ luke: hero(id: $id) { name }
{ name: "Luke Skywalker" }, }
Mutations han:
{ name: "Han Solo" } }
Just to make things less ambiguous. Also, to use
variables, you need an operation name.
Query Multiple types Variables
# Over HTTP
GET
POST
fetch('http://myapi/graphql', {
body: JSON.stringify({
query: '...',
operationName: '...',
variables: { ... }
})
})
# Schema
Basic schemas Built in types Mutations
Scalar types
type Query { type Mutation {
me: User Int Integer users(params: ListUsersInput) [User]!
users(limit: Int): [User] }
} Float Float
String String Interfaces
type User {
id: ID! Boolean Boolean
name: String interface Entity {
} ID ID id: ID!
}
Type definitions
See: sogko/graphql-shorthand-notation-cheat-sheet type User implements Entity {
scalar Scalar type
id: ID!
Enums type Object type
name: String
}
# References
http://graphql.org/learn/queries/
http://graphql.org/learn/serving-over-http/
• 0 Comments for this cheatsheet. Write yours!
0 Comments Cheatsheets
1 Login
Name
✉ Subscribe d Add Disqus to your siteAdd DisqusAdd 🔒 Disqus' Privacy PolicyPrivacy PolicyPrivacy