QA AND TEST AUTOMATION · PART 4 · API TESTING · PROTOCOLS · 46 OF 112

GraphQL and SOAP API Testing for QA Engineers

Two API styles beyond REST that testers still meet: GraphQL (one endpoint, queries and mutations, errors inside a 200 response, variables, query depth and cost, introspection) and SOAP (XML envelopes, WSDL contracts, faults, XPath assertions), with how to test each from Postman, REST Assured and Python. ShopRung is REST only, so the examples are generic and labelled as such.

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  25. 25
  26. 26
  27. 27
  28. 28
  29. 29
  30. 30
  31. 31
  32. 32
  33. 33
  34. 34
  35. 35
  36. 36
  37. 37
  38. 38
  39. 39
  40. 40
  41. 41
  42. 42
  43. 43
  44. 44
  45. 45
  46. 46
  47. 47
  48. 48
  49. 49
  50. 50
  51. 51
  52. 52
  53. 53
  54. 54
  55. 55
  56. 56
  57. 57
  58. 58
  59. 59
  60. 60
  61. 61
  62. 67
  63. 68
  64. 69
  65. 70
  66. 71
  67. 72
  68. 73
  69. 74
  70. 75
  71. 76
  72. 77
  73. 78
  74. 79
  75. 80
  76. 81
  77. 82
  78. 83
  79. 84
  80. 85
  81. 86
  82. 87
  83. 88
  84. 89
  85. 90
  86. 91
  87. 92
  88. 93
  89. 94
  90. 95
  91. 96
  92. 97
  93. 98
  94. 99
  95. 100
  96. 101
  97. 102
  98. 103
  99. 104
  100. 105
  101. 106
  102. 107
  103. 108
  104. 109
  105. 110
  106. 111
  107. 112
1 / 11

Press play to hear the narration, or step through at your own pace.

Key takeaways

  • GraphQL: one endpoint, queries and mutations, errors in a 200
  • SOAP: XML envelopes, WSDL, faults, XPath

Notes

GraphQL basics

GraphQL usually has one endpoint, often slash graphql, and every call is a post. The body holds a query, written in GraphQL's own language, plus variables. The client asks for exactly the fields it wants, here a product's sku and price in cents, and the response mirrors that shape under data. Reading is a query; changing data is a mutation. A typed schema defines every type and field, and it is the contract you test against.

A GraphQL request
POST /graphql
{
 "query": "query P($id: ID!) {
    product(id: $id) {
      sku priceCents } }",
 "variables": {"id": "1"}
}
→ 200
{"data": {"product":
  {"sku": "BK-101",
   "priceCents": 1250}}}

The big difference

Here is the biggest difference for testers. In GraphQL, problems often come back with HTTP status two hundred. Ask for a field that does not exist, and the response has an errors array: cannot query field price on type product. Ask for a product that does not exist, and you may simply get product null. So a test that only checks for two hundred passes on broken calls. Always assert that errors is absent, and that data has what you expect.

Errors in GraphQL
ask for a field that does not
  exist ("price"):
{"errors": [{"message":
  "Cannot query field 'price'
   on type 'Product'.",
  "locations": [...]}]}

product that does not exist:
{"data": {"product": null}}

many servers: HTTP 200 for both

What to test

A GraphQL checklist. Queries: fields, nulls and lists. Mutations: check the data really changed with a follow up query. Wrong or missing variables. No errors array on success. Authorisation per field, since one query can reach many types. Very deep or large queries, which need depth and cost limits. One query causing hundreds of database calls. And whether introspection, which reveals the whole schema, is off in production.

GraphQL test ideas
  • queries: fields, nulls, lists
  • mutations: data really changed
  • variables: wrong types, missing
  • errors array: absent on success
  • authorisation per FIELD, not just per endpoint
  • deep or huge queries: depth and cost limits
  • N+1: one query, 100s of DB calls
  • introspection off in production?

Tools

The good news: GraphQL is still HTTP and JSON, so your existing tools work. In pytest, post the query and variables to slash graphql, then assert errors is not in the body, and check the value under data, product, sku. In REST Assured, the same post, then check errors is null and use a JSON path into data. Postman has a GraphQL mode with schema based autocomplete, and Playwright's request object works too.

GraphQL from code
# pytest + httpx
r = client.post("/graphql", json={
  "query": Q, "variables": {"id": "1"}})
body = r.json()
assert "errors" not in body
assert body["data"]["product"]
              ["sku"] == "BK-101"

// REST Assured: same post, then
.body("errors", nullValue())
.body("data.product.sku", ...)

SOAP basics

SOAP is an older, stricter protocol. Every message is XML inside an envelope with a body. You post the envelope to the service's address, often with a SOAP action header naming the operation, here get product. The service is described by a WSDL file, a machine readable contract listing every operation and its XML types. Tools read the WSDL to generate requests for you.

A SOAP request
POST /ws/ProductService
Content-Type: text/xml
SOAPAction: "getProduct"
<soap:Envelope xmlns:soap=...>
 <soap:Body>
  <getProduct><id>1</id>
  </getProduct>
 </soap:Body>
</soap:Envelope>

WSDL = machine-readable contract

Testing SOAP

In SOAP, errors come back as a fault element inside the body, with a fault code saying whether the client or the server caused it, and a fault string with the reason. In SOAP one point one, faults usually come with HTTP status five hundred, even for client mistakes. Assert on values with XPath expressions, like get product response slash sku, and validate messages against the XML schema from the WSDL.

SOAP checks
errors come back as a Fault:
<soap:Fault>
  <faultcode>soap:Client
  </faultcode>
  <faultstring>Unknown id
  </faultstring>
</soap:Fault>  (HTTP 500 in 1.1)

assert with XPath:
  //getProductResponse/sku
  validate against the XSD

SOAP tools

Tools for SOAP. SoapUI, and its commercial version ReadyAPI, import a WSDL and generate every request for you; it remains the classic SOAP testing tool. REST Assured can post XML and assert with has XPath. In Python, the zeep library reads the WSDL and turns each operation into a function call. And Postman can send a raw XML body when you just need a quick check.

Tools for SOAP
  • SoapUI / ReadyAPI: import the WSDL, get every request
  • REST Assured: post the XML, then XPath assertions: .body(hasXPath("//sku", equalTo("BK-101")))
  • Python: zeep reads the WSDL and gives you functions
  • Postman: raw XML body works

Common mistakes

Mistakes with these styles. In GraphQL: checking only for two hundred, skipping depth and cost tests, and checking authorisation only at the endpoint instead of per field. In SOAP: comparing XML as plain strings, which breaks on whitespace and namespace prefixes, and ignoring the WSDL, which already gives you the contract. In both: forgetting negative tests, which matter as much as with REST.

Avoid these
  • GraphQL: only checking 200
  • GraphQL: no depth/cost tests
  • GraphQL: authZ per endpoint only
  • SOAP: string-comparing XML (whitespace, namespaces)
  • SOAP: ignoring the WSDL
  • both: no negative tests

Say it like this

In the interview: GraphQL has one endpoint, the client chooses the fields, and errors often arrive inside a two hundred response, so I always assert that the errors array is absent and check the data. I test variables, nulls, mutations with follow up queries, authorisation per field, and depth and cost limits. For SOAP, messages are XML envelopes described by a WSDL; I check faults and assert with XPath.

In the interview
  • "One endpoint, client-chosen
  • fields, and errors often in a 200 body, so I always assert
  • the errors array is absent and check data. I test variables, nulls, mutations with follow-up queries, per-field authZ and depth or cost limits. SOAP: XML envelopes, WSDL contract, faults and XPath checks."

Interview questions

Q1How do GraphQL errors differ from REST errors?

GraphQL commonly returns HTTP 200 with an "errors" array (and possibly partial data), so tests must assert on the body, not only the status code.

Q2What is the difference between a GraphQL query and a mutation?

A query reads data; a mutation changes data. Both are sent (usually as POST) to the same endpoint.

Q3What should you test in a GraphQL API?

Queries and nulls, mutations (verified by a follow-up query), variables and types, errors array, per-field authorisation, depth and cost limits, N+1 performance and introspection settings.

Q4What is GraphQL introspection?

A built-in query that returns the full schema; useful in development, often disabled or restricted in production for security.

Q5What is a WSDL?

Web Services Description Language: an XML contract describing a SOAP service's operations, messages and types.

Q6How are errors returned in SOAP?

As a soap:Fault element in the body with a fault code and fault string (and detail); in SOAP 1.1 typically with HTTP 500.

Q7How do you assert on a SOAP response?

With XPath expressions on the XML (for example hasXPath in REST Assured) and schema validation against the WSDL's XSD.

Q8Which tools are used for SOAP testing?

SoapUI or ReadyAPI, REST Assured with XML and XPath, Python zeep, and Postman with raw XML bodies.