GraphQL requests in VS Code with .http files
You do not need a separate app to query a GraphQL API. A GraphQL request is an HTTP POST with a JSON body, and the .http format has a readable way to write one: the query as plain text, the variables as JSON underneath. Plainwire (free, open source, no login) sends these from VS Code, Cursor, Windsurf or VSCodium, shows them in a Query + Variables editor, runs checks on the result and runs the same file in CI.
The format is the one REST Client uses for GraphQL, so existing files work unchanged. Plainwire is an independent project, not affiliated with REST Client.
The syntax
Add the header X-REQUEST-TYPE: GraphQL. The body is the query; after a blank line, an optional JSON object holds the variables:
@base = https://countries.trevorblades.com
### Country by code
# @assert status == 200
# @assert $.data.country.name == "Poland"
POST {{base}}/graphql
X-REQUEST-TYPE: GraphQL
query Country($code: ID!) {
country(code: $code) { name capital currency }
}
{ "code": "PL" }
This is a real public API; the request above passes both checks.
The JetBrains HTTP Client’s form works too (since 0.16): write GRAPHQL instead of POST and leave out the header. Plainwire sends it as a POST with the same JSON body, so files shared with IntelliJ users run unchanged:
### Country by code
GRAPHQL https://countries.trevorblades.com/graphql
query Country($code: ID!) {
country(code: $code) { name capital }
}
{ "code": "PL" }
What is actually sent
- The body becomes JSON:
{"query": "...", "variables": {...}, "operationName": "Country"}.variablesis{}when you wrote none. operationNameis added only when the query contains exactly one operation and it has a name. With several operations it is left out.Content-Type: application/jsonis added unless you set a Content-Type yourself.- The
X-REQUEST-TYPEheader is a marker for the client and is not sent to the server. {{variables}}are replaced first, so you can use environment values and chained responses inside the query and inside the variables JSON.- GraphQL requests must use
POST; aGETgives a clear error instead of a request without a body.
Authentication and environments
Headers work as in any other request. Keep the token in an environment file (http-client.private.env.json, git-ignored) or chain it from a login request:
### Log in
# @name login
POST {{base}}/auth/login
Content-Type: application/json
{ "user": "{{user}}", "password": "{{password}}" }
### My orders
POST {{base}}/graphql
Authorization: Bearer {{login.response.body.$.token}}
X-REQUEST-TYPE: GraphQL
query MyOrders($first: Int) {
viewer { orders(first: $first) { nodes { id total } } }
}
{ "first": {{pageSize}} }
The GraphQL editor
Open the request with Open in Plainwire (the link above it) and choose GraphQL as the body type. The editor shows two boxes, Query and Variables, and writes them back to the file in the format above. Invalid JSON in Variables is flagged before you send. Switching between GraphQL and JSON converts the body in both directions.
Test GraphQL responses
GraphQL servers usually answer 200 even when the query failed, with the problem in an errors array. Check for it explicitly:
# @assert status == 200 # @assert $.errors notExists # @assert $.data.viewer.orders.nodes.length > 0
Run a whole file or folder with Run all, or in CI with the free command-line runner: node plainwire.mjs run api/ --env ci. See API tests in .http files and run .http files in CI.
Copy as cURL
Copy as cURL on a GraphQL request copies the JSON body that would be sent, not the raw query, so you can paste it into a terminal or a bug report as is.
Coming from Postman or Thunder Client
Postman (body.mode: graphql) and Thunder Client GraphQL requests are imported in this format, with their variables. See Postman collections to .http files and Thunder Client collections to .http files.
Not supported yet
- Schema introspection, autocomplete and validation of the query.
- A subscription editor. You can still run a subscription as a WebSocket request by writing the protocol messages yourself (
Sec-WebSocket-Protocol: graphql-transport-ws, thenconnection_initandsubscribe). - GraphQL over
GET(query in the URL), and choosingoperationNamewhen a document has several operations.