> ## Documentation Index
> Fetch the complete documentation index at: https://hexagraph-docs.voyla.in/llms.txt
> Use this file to discover all available pages before exploring further.

# Query Scholarly Data with the Hexagraph GraphQL API

> Use Hexagraph's GraphQL endpoint to fetch multiple scholarly entities in a single query. Explore outputs, authors, and more with the interactive playground.

Hexagraph provides a code-first GraphQL gateway at `https://api.hexagraph.in/graphql`. The same URL doubles as an interactive browser playground powered by Apollo Sandbox, so you can explore the schema, write queries, and inspect responses without leaving your browser — no client setup required. For programmatic access, send a standard `POST` request with a JSON body.

## The GraphQL Playground

Navigate to [https://api.hexagraph.in/graphql](https://api.hexagraph.in/graphql) in your browser to open the Apollo Sandbox. The playground gives you:

* **Schema explorer** — browse all available query types, arguments, and return fields in the left-hand panel.
* **Autocomplete** — the query editor surfaces field suggestions as you type, so you can discover the full data model interactively.
* **Live execution** — click **Run** to fire a query against the live Hexagraph API and inspect the response inline.

No sign-in or API key is needed. The playground is the fastest way to prototype a query before wiring it into your application.

## Making GraphQL Requests

All GraphQL operations use a single endpoint and HTTP method. Send your query as the `query` property of a JSON body in a `POST` request:

```bash theme={null}
curl -X POST https://api.hexagraph.in/graphql \
  -H "Content-Type: application/json" \
  -d '{"query": "{ output(id: \"HX_W2107277218\") { id title year } }"}'
```

**Example response**

```json theme={null}
{
  "data": {
    "output": {
      "id": "HX_W2107277218",
      "title": "Artificial Intelligence in Clinical Decision Support",
      "year": 2022
    }
  }
}
```

Because you asked only for `id`, `title`, and `year`, those are the only three fields returned — the response is exactly as wide as you declared, no more.

## Available Queries

### `output(id)`

Fetch a single scholarly work by its HX\_ID. Use this when you have a known identifier and need its full metadata record.

```graphql theme={null}
query GetOutput {
  output(id: "HX_W2107277218") {
    id
    doi
    title
    year
    date
    citations
    authors {
      name
    }
  }
}
```

**Example response**

```json theme={null}
{
  "data": {
    "output": {
      "id": "HX_W2107277218",
      "doi": "https://doi.org/10.1016/j.artint.2022.103751",
      "title": "Artificial Intelligence in Clinical Decision Support",
      "year": 2022,
      "date": "2022-04-15",
      "citations": 148,
      "authors": [
        { "name": "Jordan Rivera" },
        { "name": "Priya Nambiar" }
      ]
    }
  }
}
```

### `outputs(query)`

Search and filter the full outputs index. The `query` argument mirrors the REST endpoint's `search`, `filter`, `page`, and `per_page` parameters, but returns only the fields you declare.

```graphql theme={null}
query SearchPublications {
  outputs(query: {
    search: "artificial intelligence"
    filter: "has_doi:true"
    page: 1
    per_page: 3
  }) {
    id
    doi
    title
    date
    source
    citations
    authors {
      name
      affiliations
    }
  }
}
```

**Example response**

```json theme={null}
{
  "data": {
    "outputs": [
      {
        "id": "HX_W2107277218",
        "doi": "https://doi.org/10.1016/j.artint.2022.103751",
        "title": "Artificial Intelligence in Clinical Decision Support",
        "date": "2022-04-15",
        "source": "Artificial Intelligence",
        "citations": 148,
        "authors": [
          { "name": "Jordan Rivera", "affiliations": ["Massachusetts Institute of Technology"] }
        ]
      }
    ]
  }
}
```

### `author(id)`

Fetch a complete researcher profile by HX\_ID, including citation metrics and institutional affiliations.

```graphql theme={null}
query GetAuthorProfile {
  author(id: "HX_A5086208034") {
    id
    orcid
    name
    citations
    outputs
    affiliations {
      institution {
        name
      }
    }
  }
}
```

**Example response**

```json theme={null}
{
  "data": {
    "author": {
      "id": "HX_A5086208034",
      "orcid": "https://orcid.org/0000-0002-1825-0097",
      "name": "Jordan Rivera",
      "citations": 6201,
      "outputs": 84,
      "affiliations": [
        { "institution": { "name": "Massachusetts Institute of Technology" } },
        { "institution": { "name": "Stanford University" } }
      ]
    }
  }
}
```

## Batching Multiple Lookups

One of GraphQL's most practical advantages is the ability to resolve multiple independent entities in a single HTTP request. The example below fetches both a scholarly output and an author profile in one round trip, using [aliases](https://graphql.org/learn/queries/#aliases) to give each field a distinct key in the response:

```graphql theme={null}
query BatchLookup {
  paper: output(id: "HX_W2107277218") {
    id
    title
    year
    citations
  }

  researcher: author(id: "HX_A5086208034") {
    id
    name
    citations
    outputs
  }
}
```

**Example response**

```json theme={null}
{
  "data": {
    "paper": {
      "id": "HX_W2107277218",
      "title": "Artificial Intelligence in Clinical Decision Support",
      "year": 2022,
      "citations": 148
    },
    "researcher": {
      "id": "HX_A5086208034",
      "name": "Jordan Rivera",
      "citations": 6201,
      "outputs": 84
    }
  }
}
```

Two records retrieved — one API call charged against your rate limit quota.

## Benefits over REST

| Capability                      | REST                          | GraphQL                         |
| ------------------------------- | ----------------------------- | ------------------------------- |
| Request only specific fields    | ❌ Full object always returned | ✅ Declare exactly what you need |
| Combine multiple entity lookups | ❌ One request per entity      | ✅ Batch in a single request     |
| Interactive exploration         | ❌ Requires external tooling   | ✅ Built-in browser playground   |
| Precise rate-limit efficiency   | ❌ Each entity = one request   | ✅ Many entities = one request   |

<Tip>
  Using GraphQL to batch multiple entity lookups into a single request is the most efficient way to stay within Hexagraph's rate limits (30 requests/min, 1,000/day) when building integrations. A single query that fetches ten outputs and five author profiles counts as just **one** request against your quota.
</Tip>
