SyntaxStudy
Sign Up
GraphQL Beginner 10 min read

GraphQL Queries

A GraphQL query is a read operation. Queries let you specify exactly which fields you want to retrieve. Fields can be nested to fetch related data in a single request.

Example
# Basic query
query {
  books {
    title
    author
    year
  }
}

# Query with arguments
query {
  book(id: "42") {
    title
    author {
      name
      bio
    }
    reviews {
      rating
      comment
    }
  }
}

# Named query with variables
query GetBook($bookId: ID!, $reviewLimit: Int = 10) {
  book(id: $bookId) {
    title
    reviews(limit: $reviewLimit) {
      rating
      comment
      author { name }
    }
  }
}

# Variables (sent as JSON)
{
  "bookId": "42",
  "reviewLimit": 5
}