Track: APIs and back end · Lesson 34 of 41 · 16 min

Testing GraphQL and gRPC: how it differs from REST

One endpoint and arbitrary queries in GraphQL, binary contracts in gRPC: what to check, which tools to use and which defects are typical.

Client, server and HTTPBrowserclient · DevToolsServerAPI · databasePOST /api/orders { … }201 Created2xx success4xx bad request5xx server error
Client, server and HTTP. The browser sends a request, the server returns a response with a status code. 4xx is a client error, 5xx a server error.

Not every API is REST

The principles from API testing in depth still apply, but GraphQL and gRPC change where the bugs live.

REST GraphQL gRPC
Entry points Many URLs One /graphql Service methods
Format JSON JSON Protobuf (binary)
Errors HTTP status Often 200 + an errors array gRPC status codes
Contract OpenAPI Schema (SDL) .proto file
Tools Postman, curl Postman, GraphiQL, Insomnia Postman, grpcurl, Kreya

GraphQL: what to check

query Order($id: ID!) {
  order(id: $id) {
    id
    status
    total
    customer { email }
  }
}
  • Errors with a 200. GraphQL usually returns HTTP 200 even on an error — check that there's no errors array and that data has the expected shape.
  • Partial responses. Some fields may arrive and others come back null with an error. How does the UI show that?
  • Field-level permissions. customer.email may be visible only to the owner — request the field as a different user.
  • Depth and complexity. Nested queries (order → customer → orders → items → …) can take the server down. Is there a depth or query-cost limit?
  • Introspection is often disabled in production — check that the schema isn't open to everyone.
  • N+1. A list of 50 orders, each with a customer — does it make 51 database queries? You'll see it in the response time.

gRPC: what to check

grpcurl -plaintext -d '{"order_id": 42}' localhost:50051 shop.OrderService/GetOrder
  • gRPC status codes: OK, INVALID_ARGUMENT, NOT_FOUND, PERMISSION_DENIED, UNAVAILABLE, DEADLINE_EXCEEDED — each has its own scenario.
  • Deadlines. The client sets a timeout; the server must stop work properly rather than "quietly" completing the operation after the client gave up.
  • Streams. Server or bidirectional streaming: a disconnect midway, a slow consumer, message ordering.
  • .proto compatibility. Adding a field is safe; changing a field's number or type breaks old clients. That's what contract tests are for.

Common to all of them

  • Input validation and boundary values (calculator).
  • Authorization for every method or field.
  • Idempotency of state-changing operations.
  • Response time and behavior under load (k6 supports gRPC and GraphQL — see performance testing).

Next on this track: async systems: queues and webhooks.

Key takeaways

  • GraphQL often returns 200 with an errors array — check the body, not just the status.
  • GraphQL checks permissions at the field level, gRPC at the method level.
  • Changing a field's number or type in .proto breaks old clients — a job for contract tests.

Check yourself

  1. 1. A GraphQL query returned HTTP 200. Does that mean success?

  2. 2. Which .proto change is dangerous for old clients?

  3. 3. Why limit GraphQL query depth?

Practice: Postman in practice