Skip to content

application/graphql MIME Type — Meaning, Usage & Examples

application/graphql
Extensions: .graphql Class: application Spec: GraphQL

application/graphql means: application/graphql is a media type for GraphQL query documents, where the request body is the raw query string rather than a JSON envelope. Some GraphQL servers accept it as an alternative to the common application/json POST with query and variables fields. Application media types carry structured or binary data that a program consumes rather than a human reading raw bytes. The subtype tells the receiver exactly which parser, decoder or handler to invoke, so sending the correct Content-Type is part of the API contract: a mismatch makes servers reject the body with 415 Unsupported Media Type or clients mis-parse the payload. You will encounter application/graphql in contexts such as graphql endpoints accepting a raw query body; get requests with the query in the url and this type implied; tooling that sends queries without a json wrapper. It is commonly associated with the file extension(s) .graphql. Most GraphQL servers expect application/json with {query, variables, operationName}; application/graphql is supported by some but not all. Check the server's accepted types — sending the wrong one yields a 400 or 415 rather than executing the query.

Advertisement
Ad slot · ref-top

When you'll see application/graphql

  • GraphQL endpoints accepting a raw query body
  • GET requests with the query in the URL and this type implied
  • Tooling that sends queries without a JSON wrapper

How to handle it

When handling an application type, set the Content-Type header explicitly on every request and response that carries a body, and advertise what you accept with the Accept header. Parse the payload with a library that matches the subtype rather than sniffing bytes, and validate the structure before trusting it. If a server returns 415, the declared type does not match what it expects — compare your header against the API documentation character for character, including parameters such as charset or boundary. As a final checklist for application types: register the exact subtype in your API documentation, validate incoming bodies against a schema before use, set X-Content-Type-Options: nosniff to stop MIME sniffing, and version your media types when the payload contract changes so old clients keep working.

Notes & gotchas

Most GraphQL servers expect application/json with {query, variables, operationName}; application/graphql is supported by some but not all. Check the server's accepted types — sending the wrong one yields a 400 or 415 rather than executing the query.

Examples

HTTP
POST /v1/resource HTTP/1.1
Host: api.example.com
Content-Type: application/graphql
Content-Length: 33

<root><item>example</item></root>
curl
curl -i -X POST -H "Content-Type: application/graphql" --data-binary @payload https://api.example.com/v1/resource
JavaScript (fetch)
const res = await fetch("/v1/resource", { headers: { Accept: "application/graphql" } });
// verify res.headers.get("Content-Type") starts with "application/graphql"
const text = await res.text();   // handle according to the declared type
Python (requests)
import requests

with open("payload", "rb") as fh:
    res = requests.post("https://api.example.com/v1/resource", data=fh,
                        headers={"Content-Type": "application/graphql"}, timeout=30)

Frequently asked questions

Should I send GraphQL as JSON or application/graphql?

Prefer application/json with a query/variables object unless the server documents application/graphql support. JSON is the broadly interoperable convention for GraphQL over HTTP.

How are variables sent with application/graphql?

The raw-query body has no place for variables, so they must go in the query string or the server must support a multipart form. This is one reason JSON envelopes are more common.

What happens if I send the wrong application Content-Type?

Servers that validate media types answer 415 Unsupported Media Type, and clients may parse the body with the wrong decoder. Always set Content-Type to the registered type that matches your payload, and set Accept to the types you can handle.

Is application/octet-stream a safe default?

It means 'arbitrary binary bytes' and forces a download rather than inline handling. Use it only when the real type is unknown or you deliberately want a save-as dialog; otherwise declare the specific registered type.

How do I debug a 415 Unsupported Media Type response?

Compare the Content-Type you actually sent against what the endpoint documents, including parameters like charset and boundary. A 415 means the server refuses that media type; send the exact registered type it accepts and retry.

Advertisement
Ad slot · ref-in-article

Try the JSON Formatter

Beautify, validate and minify JSON with clear error messages.

Open tool →