What is a Query

A query in GraphQL is a read operation. The client sends a query describing the exact fields it needs, and the server returns data matching that shape. Queries are the GraphQL equivalent of GET requests in REST.

How it works

A query names the root field and nests the desired fields:

query {
  user(id: 42) {
    name
    email
    posts { title }
  }
}

The server resolves each field in the query tree using resolvers and returns a JSON response with the same structure. The client gets exactly what it asked for — no unused fields, no missing fields.

Why it matters

Queries are what make GraphQL flexible. Different clients (mobile, web, watch) can send different queries to the same API, each requesting only the fields they need. This eliminates over-fetching (REST returns everything) and under-fetching (REST requires multiple requests for nested data).

See How GraphQL Works for the full query language, variables, and fragments.