Cheatsheets/GraphQL
Web

GraphQL

Queries, mutations, schema types, and HTTP transport.

Queries

# Basic field
{ status }

# Nested
{ hero { name height } }

# With argument
{ hero(id: "1000") { id name } }

# Aliases
{ luke: hero(id: "1000") { name }
  han:  hero(id: "1001") { name } }

Named query & variables

query FindHero($id: String!) {
  hero(id: $id) {
    name
    friends { name }
  }
}

Mutations

mutation CreateReview($review: ReviewInput!) {
  createReview(review: $review) {
    id
    stars
    commentary
  }
}

Fragments & unions

{ search(q: "ada") {
    id
    ... on User    { name }
    ... on Comment { body author { name } }
  }
}

Schema types

type Query { me: User }Root query type
type User { id: ID! name: String }Object type
Int, Float, String, Boolean, IDScalar types
String!Non-null field
[String!]!Non-null list of non-null strings
interface Entity { id: ID! }Interface
enum STATUS { ACTIVE INACTIVE }Enum type
union Result = User | PostUnion type

HTTP transport

GET ?query={ me { name } }GET with query param
POST body: { query, variables }POST with variables