GraphQL Cheat Sheet
Quick reference for GraphQL syntax. Queries, mutations, subscriptions, schema definition, types, directives, and fragments — all in one page.
Queries
| { user { name } } | Basic query |
| { user(id: 1) { name } } | Query with argument |
| { user { name posts { title } } } | Nested fields |
| { user { name ...on Admin { role } } } | Inline fragment |
| query GetUser($id: ID!) { user(id: $id) { name } } | Named query with variable |
| { users(first: 10, after: "cursor") { edges { node { name } } } } | Pagination (Relay-style) |
Mutations
| mutation { createUser(name: "Alice") { id } } | Basic mutation |
| mutation Create($input: UserInput!) { createUser(input: $input) { id name } } | Named mutation with variables |
| mutation { updateUser(id: 1, name: "Bob") { id name } } | Update mutation |
| mutation { deleteUser(id: 1) { success } } | Delete mutation |
Schema Definition
| type User { id: ID! name: String! } | Object type |
| type Query { user(id: ID!): User } | Query type (entry point) |
| type Mutation { createUser(name: String!): User } | Mutation type |
| input UserInput { name: String! email: String } | Input type |
| enum Role { ADMIN USER GUEST } | Enum type |
| interface Node { id: ID! } | Interface type |
| union SearchResult = User | Post | Comment | Union type |
| scalar DateTime | Custom scalar type |
Type System
| String | UTF-8 string |
| Int | 32-bit signed integer |
| Float | Double-precision float |
| Boolean | true or false |
| ID | Unique identifier (serialized as String) |
| String! | Non-nullable String |
| [String] | List of strings (nullable items) |
| [String!]! | Non-nullable list of non-nullable strings |
Fragments & Directives
| fragment UserFields on User { id name email } | Fragment definition |
| { user { ...UserFields } } | Fragment spread |
| @deprecated(reason: "Use newField") | Deprecation directive |
| @include(if: $withPosts) | Conditional inclusion |
| @skip(if: $noPosts) | Conditional skip |
Subscriptions
| subscription { messageAdded { text sender } } | Basic subscription |
| subscription OnMsg($room: ID!) { messageAdded(room: $room) { text } } | Subscription with variable |
Try It Live
Test these patterns with our free API Tester. No signup needed.
Open API Tester →
Step-by-Step Guide
Read Guide →