Skip to content

Commit d105590

Browse files
committed
feedback: add +json media type
1 parent 4bbc748 commit d105590

File tree

1 file changed

+31
-10
lines changed

1 file changed

+31
-10
lines changed

src/pages/learn/debug-errors.mdx

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@ When building or consuming a GraphQL API over HTTP, it's common to run into
44
errors, especially during development. Understanding how to recognize and resolve these issues
55
can save you time and frustration.
66

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.
1013

1114
## `400 Bad Request`: Syntax or parse errors
1215

@@ -25,7 +28,7 @@ or the JSON body isn't valid.
2528

2629
- Validate your JSON body using a linter or formatter.
2730
- 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.
2932

3033
## `405 Method Not Allowed`: Wrong HTTP Method
3134

@@ -105,7 +108,7 @@ Something went wrong on the server.
105108

106109
### What it means
107110

108-
The HTTP layer succeeded, but the GraphQL request produced errors.
111+
The HTTP layer succeeded, but the GraphQL operation produced errors.
109112

110113
### Common causes
111114

@@ -116,11 +119,11 @@ The HTTP layer succeeded, but the GraphQL request produced errors.
116119

117120
### How to debug
118121

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.
120125

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:
124127

125128
```json
126129
{
@@ -133,4 +136,22 @@ If the response does not include a `data` property it's likely there was a mista
133136
}
134137
```
135138

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
157+
type or fallback to `application/json`.

0 commit comments

Comments
 (0)