# How a GraphQL Request Works — GraphQL

Source: https://www.skillbyai.com/en/graphql/f-request

> Parse, validate, execute.

## Operations over HTTP

A client usually sends an HTTP POST with a JSON body containing `query` (the operation text), optional `variables` and an optional `operationName`. The server **parses** the document, **validates** it against the schema (unknown fields or wrong argument types are rejected before execution), then **executes** it by calling a resolver for each field. The JSON response has a `data` key and, when something went wrong, an `errors` array; a response can contain both (partial success). Queries can also be sent with GET, which helps caching.

## A request and its response

The JSON envelope (illustrative data).

```json
// request body: POST /graphql
{
  "query": "query UserCard($id: ID!) { user(id: $id) { name email } }",
  "variables": { "id": "42" },
  "operationName": "UserCard"
}

// response
{
  "data": { "user": { "name": "Asha Verma", "email": "asha@example.com" } }
}
```

## Expect 200 with errors

Many GraphQL servers return HTTP 200 even when the errors array is present, so clients must inspect the body, not just the status code.

**Quiz:** What happens to a query that requests a field not in the schema?

- [x] It fails validation before execution
- [ ] The field is returned as null silently
- [ ] The server creates the field
- [ ] Only the HTTP status changes

*Answer:* It fails validation before execution. The schema is a contract.
