You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/pages/learn/debug-errors.mdx
+31-10Lines changed: 31 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,9 +4,12 @@ When building or consuming a GraphQL API over HTTP, it's common to run into
4
4
errors, especially during development. Understanding how to recognize and resolve these issues
5
5
can save you time and frustration.
6
6
7
-
This guide outlines common errors, what they mean, and how to debug them
8
-
effectively. These examples relate to servers that implement the
9
-
[GraphQL over HTTP specification](https://graphql.github.io/graphql-over-http/draft/). Different servers may produce different error messages and status codes in some circumstances, so this document should be treated as a general guide rather than a canonical reference.
7
+
This guide outlines common HTTP and GraphQL errors, what they mean, and how to debug them
8
+
effectively. It follows the recommendations of the
9
+
[GraphQL over HTTP spec (draft)](https://graphql.github.io/graphql-over-http/draft/),
10
+
which standardizes how GraphQL works over HTTP, including request formats, status codes,
11
+
and media types. Keep in mind that implementations may vary, so treat this as a general guide rather
12
+
than a definitive reference.
10
13
11
14
## `400 Bad Request`: Syntax or parse errors
12
15
@@ -25,7 +28,7 @@ or the JSON body isn't valid.
25
28
26
29
- Validate your JSON body using a linter or formatter.
27
30
- Make sure you're sending a `POST` request with a `Content-Type: application/json` header.
28
-
-Verify that the GraphQL query is syntactically correct. Use an IDE or a linter to verify it.
31
+
-Check your GraphQL query for syntax errors. Use an IDE or linter to verify it.
29
32
30
33
## `405 Method Not Allowed`: Wrong HTTP Method
31
34
@@ -105,7 +108,7 @@ Something went wrong on the server.
105
108
106
109
### What it means
107
110
108
-
The HTTP layer succeeded, but the GraphQL request produced errors.
111
+
The HTTP layer succeeded, but the GraphQL operation produced errors.
109
112
110
113
### Common causes
111
114
@@ -116,11 +119,11 @@ The HTTP layer succeeded, but the GraphQL request produced errors.
116
119
117
120
### How to debug
118
121
119
-
Check the `errors` array in the response body.
122
+
Check the `errors` array in the response body. If the response includes a `data` property, then
123
+
your query document is likely valid and you most likely hit a runtime exception - perhaps due to
124
+
invalid input, access denial, or a bug in server logic.
120
125
121
-
If the response includes a `data` property then your query document is likely valid and you most likely hit a runtime exception - perhaps something went wrong on the server, you supplied invalid data, you're not allowed to do that, or some other runtime exception occurred.
122
-
123
-
If the response does not include a `data` property it's likely there was a mistake in your request - an invalid GraphQL document or bad values for variables. A typical validation error response looks like:
126
+
If there's no `data` field, the request likely failed during validation. For example:
124
127
125
128
```json
126
129
{
@@ -133,4 +136,22 @@ If the response does not include a `data` property it's likely there was a mista
133
136
}
134
137
```
135
138
136
-
Compare your query against the schema using introspection or an IDE.
139
+
Use introspection or an IDE to verify your query matches the schema.
140
+
141
+
## Understanding GraphQL response formats
142
+
143
+
Most GraphQL servers return responses using the `application/json` media type. However,
144
+
the [GraphQL over HTTP spec](https://graphql.github.io/graphql-over-http/draft/) recommends
145
+
using a more specific type: `application/graphql-response+json`.
146
+
147
+
This media type identifies the payload as a GraphQL response and helps clients
148
+
distinguish it from other types of JSON.
149
+
150
+
### What to know
151
+
152
+
- Servers may respond with `application/graphql-response+json` instead of
153
+
`application/json`.
154
+
- Clients can request this media type using the `Accept` header: `Accept: application/graphql-response+json`
155
+
- This content type is optional, but support for it is growing.
156
+
- If your client uses content negotiation, ensure your server can response with the appropriate
0 commit comments