GraphQL

You can test and document GraphQL APIs in DocStar as regular HTTP requests. Most GraphQL servers accept a POST with a JSON body, and DocStar's request editor handles that directly.

DocStar doesn't currently have a separate GraphQL mode with schema browsing or a query editor. Endpoints are HTTP requests (GET, POST, PUT, PATCH or DELETE), and you write the GraphQL query inside the body.

#

Send a GraphQL query

  1. Create an endpoint in your API collection (see Document an API Endpoint).
  2. Set the method to POST and enter your GraphQL URL, for example {{BASE_URL}}/graphql.
  3. In the Body tab, choose raw, then JSON.
  4. Enter the query and its variables:
{
  "query": "query GetUser($id: ID!) { user(id: $id) { id name email } }",
  "variables": { "id": "42" }
}
  1. Add authentication in the Authorization or Headers tab if your API needs it. See Authorization.
  2. Click Send.

Mutations work the same way. Put the mutation in the query field.

#

Read the result

GraphQL servers usually return status 200 even when part of the query fails. Check the response body:

  • data holds the fields you asked for.
  • errors lists problems such as unknown fields or bad arguments.

Add a Post-Script test so a failed query is easy to spot:

hm.test("No GraphQL errors", () => {
  expect(hm.response.body.errors).to.be.undefined;
});

See Responses and Cookies and Scripts.

#

Use variables

Keep IDs and tokens in an environment instead of the query text. DocStar replaces {{name}} placeholders in the body before it sends the request:

{
  "query": "query GetUser($id: ID!) { user(id: $id) { name } }",
  "variables": { "id": "{{userId}}" }
}

See Environments and Variables.

#

Document GraphQL operations

  • Create one endpoint per query or mutation, and name it after the operation, such as Get user or Create order.
  • Switch the raw JSON body to Body Description to describe the variables fields.
  • Save real responses with Add to Sample Response so readers see the shape of data.
  • Add notes on required scopes or rate limits with + Text Area in the DOC view.
#

Importing GraphQL schemas

DocStar imports OpenAPI, Swagger and Postman files. It doesn't import GraphQL schema files (SDL or introspection JSON). If you have a Postman collection with GraphQL requests, check the imported bodies after import.