GraphQL Cheatsheet - GraphQL Query Language & API Reference
This reference is for developers designing a GraphQL schema or consuming one from Apollo/URQL/etc. It covers the client-facing vocabulary first — querying exactly the fields you want, mutating data, subscribing to updates, and reusing fragments — then the schema side from the type system and directives to pagination and the introspection __typename. Unlike a generic syntax sheet, items are grouped by the role you are playing in an API conversation. After reading you should be able to shape a precise query with arguments and fragments, declare a type with the right scalar/object fields, and add a connection-style paginated field.
Query 9
{ user { id name } }{ user(id: 1) { name } }{ users { id name posts { title } } }query GetUser($id: ID!) { user(id: $id) { name } }{ user { name email } posts { title } }{ user(id: 1) { name @include(if: $withName) } }{ user(id: 1) { name @skip(if: $skipName) } }{ me: user(id: 1) { name } you: user(id: 2) { name } }{ users(first: 10) { edges { node { name } } } }Mutation 5
mutation { createUser(name: "Alice") { id } }mutation CreateUser($input: CreateUserInput!) { createUser(input: $input) { id } }mutation { updateUser(id: 1, name: "Bob") { id name } }mutation { deleteUser(id: 1) { id } }mutation { bulkCreate(input: [{ name: "A" }, { name: "B" }]) { id } }Subscription 3
subscription { newMessage { content } }subscription { userUpdated(id: 1) { name } }subscription($roomId: ID!) { messageAdded(roomId: $roomId) { id content } }Schema (Type System) 10
type User { id: ID! name: String! email: String }input CreateUserInput { name: String! email: String! }enum Role { ADMIN USER GUEST }union SearchResult = User | Postinterface Node { id: ID! }type User implements Node { id: ID! name: String! }scalar DateTimetype Query { user(id: ID!): User }type Mutation { createUser(input: CreateUserInput!): User }directive @auth(requires: Role!) on FIELD_DEFINITIONFragments & Directives 5
fragment UserFields on User { id name email }{ user { ...UserFields } }{ user { ...UserFields ... on Admin { permissions } } }@deprecated(reason: "Use newField")@cacheControl(maxAge: 3600)Introspection & Validation 5
{ __schema { types { name } } }{ __type(name: "User") { fields { name type { name } } } }{ __schema { queryType { name } mutationType { name } } }{ __type(name: "User") { fields { name args { name type { name } } } } }{ __schema { directives { name locations } } }Advanced Features 5
query($id: ID!, $withPosts: Boolean!) { user(id: $id) { name posts @include(if: $withPosts) { title } } }{ users(first: 10, after: "cursor") { pageInfo { hasNextPage endCursor } } }{ user { name } } # expected user.name; errors returned alongside dataquery @cost(complexity: 10) { user { name } }extend type User { age: Int }Tips
- GraphQL returns only the fields the client asks for; the server need not return everything.
- Variables use a $ prefix and are defined outside the query to avoid string concatenation.
- The Schema Definition Language (SDL) is core to GraphQL: define types first, then implement resolvers.
- Introspection queries (__schema/__type) can generate TypeScript types and editor tooling.
- Prefer the Relay connection spec (edges/node/pageInfo) for pagination, supporting forward and backward paging.
Official References
Each command links to its official documentation below, so you can verify the latest usage and read deeper.
Maintained by LaoHand
Publicly updated on Jul 21, 2026, continuously proofread against official docs.
Contact Us
Wrong command or description? Send us corrections, business inquiries or product feedback by email.
Contact Us