# ar-gql

> [![Version](https://img.shields.io/npm/v/ar-gql?style=flat&colorA=000000&colorB=000000)](https://www.npmjs.com/package/ar-gql)

Latest version **3.1.2** (published 2025-08-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install ar-gql
pnpm add ar-gql
yarn add ar-gql
bun add ar-gql
```

## Health

**Score 35/100 (D)** — status: maintenance-mode.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.1.2 |
| Published | 2025-08-28 |
| First published | 2020-11-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=18.0.0 |
| Dependencies | 0 |
| Unpacked size | 12.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 14 |
| Author | John Letey |
| Maintainers | johnletey, rosmcmahon |

## Links

- npm: https://www.npmjs.com/package/ar-gql
- Repository: https://github.com/johnletey/arGql
- Homepage: https://github.com/johnletey/arGql#readme
- Issues: https://github.com/johnletey/arGql/issues
- npm.io page: https://npm.io/package/ar-gql

## Recent versions

- 3.1.2 (latest) — 2025-08-28
- 3.1.1 — 2025-03-11
- 3.1.0 — 2025-01-31
- 3.0.0 — 2025-01-31
- 2.0.2 — 2024-09-06
- 2.0.1 — 2024-08-07
- 2.0.0 — 2024-07-22
- 1.2.9 — 2024-03-11
- 1.2.8 — 2024-02-15
- 1.2.7 — 2024-01-29
- 1.2.6 — 2024-01-29
- 1.2.5 — 2024-01-29
- 1.2.4 — 2023-08-06
- 1.2.3 — 2023-08-06
- 1.2.2 — 2023-07-11
- … 14 more at https://npm.io/package/ar-gql/versions

## README

# `ar-gql` 

[![Version](https://img.shields.io/npm/v/ar-gql?style=flat&colorA=000000&colorB=000000)](https://www.npmjs.com/package/ar-gql)

> A JavaScript/TypeScript package that makes interaction with the Arweave GraphQL endpoint simple and easy.

## Installation

```sh
# npm
npm i ar-gql
# yarn
yarn add ar-gql
```

> ## Migrating from previous versions to v3
> - Functions are no longer directly imported. You need to import an `ArGqlInterface` object and create instanced from it. See [Code Set Up](#code-set-up) section below
> - Errors have changed again (sorry!). `GQLError` is supplied and you can use it's type definition.
> ```ts
> import { GQLError } from 'ar-gql/dist/faces'
> ```

## Code Set Up

```ts
import { arGql, GQLUrls } from 'ar-gql'

//...

const argql = arGql() // default is `https://arweave.net/graphql`.

// you can now use argql similar to as before and it will make requests to the default GQL endpoint
const tx = await argql.tx('DeYQPjoEQLLds7usOMZFJFCe7VyTpodYl6Mok6UP6Z4')
console.log(tx.id) // 'DeYQPjoEQLLds7usOMZFJFCe7VyTpodYl6Mok6UP6Z4'

// you can set up another instance with another endpoint
const goldsky = arGql({ endpointUrl: GQLUrls.goldsky }) // 'https://arweave-search.goldsky.com/graphql'
// and use it at the same time
const edges = await goldsky.tx(someTxid)

//...

```

## Functions

### `run(query, variables?)`

The `run` function receives as input a required GraphQL query (compatible with the Arweave GraphQL endpoint) and an optional object of GraphQL variables for the query.

The function returns the result of this query with the variables passed in, if any, returned by the Arweave GraphQL endpoint.

### `all(query, variables?, pageCallback?)`

Similar to the `run` function, the `all` function receives a query and optional variables.

The one key difference is that it returns all possible transactions returned from running this query. As the Arweave GraphQL endpoint is paginated, this returns all the data by traversing through the pages.

Your query must follow the template shown below:

```
query($cursor: String) {
  transactions(
    # your query parameters
      
    # standard template below
    after: $cursor
    first: 100
  ) {
    pageInfo {
      hasNextPage
    }
    edges {
      cursor
      node {
        # what tx data you want to query for:
        
      }
    }
  }
}
```

The optional `pageCallback` feature is a convenience function to process pages as they are returned. The page results are processed asynchronously, and the function `all` returns after all callback functions have completed internally.
> N.B When a callback function is used, `all` returns an empty edges array once all page callbacks are complete `[]`.

### `tx(id)`

The `tx` function recieves as an input a valid Arweave transaction id. The function will then return all metadata information about the transaction that the GraphQL endpoint supports.

### `fetchTxTag(id, name)`

This function will fetch all tags for the supplied transaction. Then, if it finds a tag with the name provided, it will return the tag value. Else, it will return `undefined`.

### `endpointUrl`

A read-only property of the GQL endpoint URL of the instance.

---
_Source: https://npm.io/package/ar-gql · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
