npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ar-gql

v1.2.9

Published

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

Downloads

31,580

Readme

ar-gql version 1

Version

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

Installation

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

Migrating from version v0.x.x to v1.x.x

  • Functions are no longer directly imported. You need to import an ArGqlInterface object and create instanced from it. See Code Set Up section below
  • As axios is no longer used internally e.response will always be undefined. You can catch regular Error objects with:
e.message   // status text
e.cause     // http status number 

in all other Fetch error cases there will be a standard Fetch TypeError with a relevent message.

Code Set Up

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(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.