GRAPHQL CHEAT SHEET

API Query Language
v1.0
Scalar Types
  • Int32-bit integer
  • FloatDouble precision
  • StringUTF-8 text
  • Booleantrue/false
  • IDUnique identifier
Type Modifiers
  • StringNullable string
  • String!Non-null string
  • [String]List of strings
  • [String!]!Non-null list
Built-in Directives
  • @skip(if: Boolean)Skip field
  • @include(if: Boolean)Include field
  • @deprecatedMark deprecated
Operation Types
  • queryRead data
  • mutationWrite data
  • subscriptionReal-time
Schema Definition
type User { id: ID! name: String! email: String! posts: [Post!]! createdAt: DateTime! } type Post { id: ID! title: String! content: String author: User! published: Boolean! } type Query { user(id: ID!): User users: [User!]! posts(published: Boolean): [Post!]! }
Query Examples
# Basic query query { users { id name email } } # Query with arguments query GetUser($id: ID!) { user(id: $id) { name posts { title } } } # With aliases query { admin: user(id: "1") { name } guest: user(id: "2") { name } }
Mutations
# Schema type Mutation { createUser(input: CreateUserInput!): User! updateUser(id: ID!, input: UpdateUserInput!): User deleteUser(id: ID!): Boolean! } input CreateUserInput { name: String! email: String! } # Client mutation mutation CreateUser($input: CreateUserInput!) { createUser(input: $input) { id name } }
Fragments
fragment UserFields on User { id name email } query { users { ...UserFields posts { title } } } # Inline fragment query { search { ... on User { name } ... on Post { title } } }
Subscriptions
# Schema type Subscription { postCreated: Post! userOnline(id: ID!): User! } # Client subscription subscription { postCreated { id title author { name } } }
Interfaces & Unions
# Interface interface Node { id: ID! } type User implements Node { id: ID! name: String! } # Union union SearchResult = User | Post | Comment type Query { search(term: String!): [SearchResult!]! } # Enum enum Status { DRAFT PUBLISHED ARCHIVED }
Custom Scalars
  • DateTimeISO 8601 date
  • JSONArbitrary JSON
  • EmailEmail format
  • URLURL format
  • UUIDUUID format
Pagination
# Cursor-based (Relay) type UserConnection { edges: [UserEdge!]! pageInfo: PageInfo! } type UserEdge { node: User! cursor: String! } type PageInfo { hasNextPage: Boolean! endCursor: String }

DummyDataGenPro

Realistic synthetic test data with foreign keys that actually join.

All 51 cheat sheets

Free to read and free to print — no signup. Want them as A4 PDFs you can print? Get all 51 as a PDF bundle for £14.99.
A Martkos IT reference sheet · Blog · Free tools