Docs
Launch GraphOS Studio

Operation request format

How to send requests to the Apollo Router over HTTP


By default, almost every IDE and client library takes care of sending in a format that the supports. This article describes that format, which is also described on

and in
this preliminary spec
.

The accepts queries, , and sent as POST requests. It also accepts queries sent as GET requests.

POST requests

The accepts POST requests with a JSON body. A valid request contains a query , along with optional variables and an operationName (if query contains multiple possible ).

Let's say we want to execute the following :

query GetBestSellers($category: ProductCategory) {
bestSellers(category: $category) {
title
}
}

Here's an example of a valid POST request body for that :

{
"query":"query GetBestSellers($category: ProductCategory){bestSellers(category: $category){title}}",
"operationName": "GetBestSellers",
"variables": { "category": "BOOKS" }
}

Note that operationName isn't required for this particular request body, because query includes only one definition.

You can execute this against an Apollo-hosted example server right now with the following curl command:

curl --request POST \
-H 'Content-Type: application/json' \
--data '{"query":"query GetBestSellers($category:ProductCategory){bestSellers(category: $category){title}}", "operationName":"GetBestSellers", "variables":{"category":"BOOKS"}}' \
https://rover.apollo.dev/quickstart/products/graphql

The 's default landing page provides a curl command you can use to execute a test on your own server:

GET requests

The also accepts GET requests for queries (but not ). With a GET request, details (query, operationName, variables) are provided as URL parameters. The variables option is a URL-escaped JSON object.

Here's the same from

formatted for a curl GET request:

curl --request GET \
https://rover.apollo.dev/quickstart/products/graphql?query=query%20GetBestSellers%28%24category%3AProductCategory%29%7BbestSellers%28category%3A%20%24category%29%7Btitle%7D%7D&operationName=GetBestSellers&variables=%7B%22category%22%3A%22BOOKS%22%7D

Persisted queries protocol

The () and () features of the use a separate protocol to send the information in the extensions. This protocal can also use HTTP POST or GET. See the docs on the

for details.

Previous
@defer support
Next
Query batching
Edit on GitHubEditForumsDiscord

© 2024 Apollo Graph Inc.

Privacy Policy

Company