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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@scottburch/graphql-gun

v1.0.3

Published

NOTE: This library is a new release and as such has not had good field testing. Please feel free to use and report any issues.

Readme

GraphQL-gun

NOTE: This library is a new release and as such has not had good field testing. Please feel free to use and report any issues.

A GraphQL library for GunDB queries. (looking at mutations next)

GraphQL-gun returns a RxJS Observable so you have all of the RxJS goodness available to you.

install

npm install @scottburch/graphql-gun

yarn add @scottburch/graphql-gun

Quickstart

1) Define a basic query

const query = gql`
    {
        app {
            settings {
                rememberMe 
            }
        }
	    user {
	        name
	    }
    }
`;

2) Add values to GunDB

gun.get('app').get('settings').get('rememberMe').put(true)
gun.get('user').get('name').put('scott')

3) Run the query and get the result

graphqlGun(query, gun).subscribe(result => {/* do something here*/})

NOTE: This will fire twice since there are really two values we are after. The second time will have all of the requested data.

If you want to filter out results that you don't care about, you can use RxJS filter to look for the values you want.

graphqlGun(query, gun).pipe(
		filter(({app, user}) => app?.settings?.rememberMe != undefined && user?.name)
).subscribe(result => {/* do something here*/})

Other Options

Using with GunDB Sets

gql`
    users(type: Set) {
	    name
	    age
	}
`;

Currently the set will be returned multiple times for each item in the set. This is so since the length of the set is not known at the beginning. The code below takes the first three responses and returns the last one which includes the first three elements of the set.

const gun = Gun();

const query = gql`
    {
        users(type: Set) {
            name
        }
    }
`;

const alice = gun.get('user').get('alice').put({name: 'alice'})
const bob = gun.get('user').get('bob').put({name: 'bob'})
const charlie = gun.get('user').get('charlie').put({name: 'charlie'})
gun.get('users').set(alice);
gun.get('users').set(bob);
gun.get('users').set(charlie);

graphqlGun(query, gun).pipe(
    take(3),
    last(),
).subscribe(result => {/* { users: [ { name: 'bob' }, { name: 'charlie' }, { name: 'alice' } ] } */})

Continuous live updates

To attach a live listener you can use @live directive in your query.

const query = gql`
    user {
        name @live
    }
`;
graphqlGun(query, gun).subscribe(result => {/* called every time "name" changes */})

Getting a gun instance in context

To get a gun instance in context you can use a _chain property.

const gun = Gun();

const query = gql`
    {
        user {
            _chain
        }
    }
`;

gun.get('user').get('name').put('alice');

graphqlGun(query, gun).subscribe(({user}) => user._chain.get('name').once((name: string) => {/* alice */}));

React

To use GraphQL-gun with React you should use react-rxjs.

import {bind} from "@react-rxjs/core";

const query = gql`
	{
			user @live {
				name
			}
	}
`;

const username$ = graphqlGun(query, gun).pipe(
	map(({user}) => user.name)
);

export const [useUsername] = bind(username$, 'default username');

Typescript

You can pass in your schema as a type to graphqlGun(). I am currently looking into ways to convert graphQL into types.

type Schema = {
    user: {
        name: string
    }
}

graphqlGun<Schema>(query, gun).subscribe(({user}) => user?.name)

Development

You will find mocha tests in the src directory in .spec.ts files. To run the tests you can run the 'test' script in package.json. Ex. yarn test

If you want to submit a bug or feature request, it should come with a test.