API Design

GraphQL Query Request JSON Example

A real-world JSON example of a GraphQL query request body — the query string, variables, and operationName sent to a GraphQL endpoint. Copy-ready for building GraphQL clients and mock servers.

{
  "operationName": "GetUserOrders",
  "query": "query GetUserOrders($userId: ID!, $limit: Int) { user(id: $userId) { id fullName orders(limit: $limit) { id total status createdAt } } }",
  "variables": {
    "userId": "usr_9k2mXpQr4t",
    "limit": 5
  }
}

Field Reference

queryrequiredstringThe GraphQL document — one or more operations (query/mutation/subscription) written in GraphQL's own syntax, sent as a plain string
variablesoptionalobjectValues for the query's $-prefixed variables, keyed by variable name — keeps the query string static and cacheable while data changes per request
operationNameoptionalstringRequired only when query contains multiple named operations, to specify which one to execute — optional for single-operation documents

Variants

MutationA mutation request follows the identical envelope shape — only the query string's keyword changes.
{
  "operationName": "UpdateOrderStatus",
  "query": "mutation UpdateOrderStatus($orderId: ID!, $status: OrderStatus!) { updateOrder(id: $orderId, status: $status) { id status updatedAt } }",
  "variables": {
    "orderId": "ord_29fk3jd93kd",
    "status": "SHIPPED"
  }
}
With FragmentsReusing a field selection across multiple parts of a query via a named fragment.
{
  "query": "query GetOrderWithItems($orderId: ID!) { order(id: $orderId) { ...OrderFields items { sku qty } } } fragment OrderFields on Order { id total status createdAt }",
  "variables": {
    "orderId": "ord_29fk3jd93kd"
  }
}

Common Use Cases

  • Building a lightweight GraphQL client without a full library like Apollo or urql
  • Mocking a GraphQL endpoint's expected request shape for frontend development
  • Debugging why a GraphQL server rejected a request by inspecting the exact query/variables sent
GraphQLqueryrequestAPIvariables

Validate or format this JSON

One click loads this exact example into the tool — no copy-paste needed. Format it, validate it, explore the tree, or generate TypeScript types instantly.

Frequently Asked Questions

GraphQL has its own query language (a typed selection-set syntax) that's more expressive than JSON can represent directly — JSON here is just the HTTP transport envelope carrying that string, plus the variables that parameterize it.

POST with this content-type: application/json body is the overwhelming convention, though the GraphQL spec also allows GET requests with query/variables as URL parameters — mainly used for simple, cacheable queries at a CDN edge.

Almost always 200 OK, even when the operation fails — GraphQL errors are reported inside the response body's errors array, not via HTTP status, since a single request can partially succeed (some fields resolved, others errored).

Related JSON Examples