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

minimal-graphql

v1.0.3

Published

Minimal graphql is a minimal node graphql client, it is built using the awesome [apollo library](https://www.apollographql.com/), but wires it up so that you can use it in node instead of the browser.

Downloads

13

Readme

Minimal graphql npm

Minimal graphql is a minimal node graphql client, it is built using the awesome apollo library, but wires it up so that you can use it in node instead of the browser.

Usage

Initializing

The only libraries you will need are minimal-graphql (guess what) and graphql-tag (parses you graphql documents). To create a client

const minimalGraphql = require("minimal-graphql")
const client = minimalGraphql(httpOptions, subscriptionOptions)
  • httpOptions: and object with the following props:

    • uri (required): the uri at which your server is found. E.g.
    {
        uri: "http://localhost:3000/graphql",
    }
    • headers (optional): and object containing the headers you want your request to have. E.g.
    {
        uri: "http://localhost:3000/graphql",
        headers: {
            Authorization: "Bearer " + bearer
        }
    }
  • subscriptionOptions(optional): if not passed you will not be able to use subscriptions. It's an object with the following props:

    • uri (required): the uri at which your subscription server can be found (the websocket uri not http one). E.g.
      {
          uri: `ws://localhost:3000/subscriptions`
      }
    • options(optional): and object containing reconnect (optional, boolean, whether to try to reconnect) and connectionParams (optional, an object containing the websocket connection parameters). E.g.
     {
         uri: `ws://localhost:3000/subscriptions`,
         options: {
             reconnect: true,
             connectionParams: {
                 Authorization: "Bearer " + bearer,
             },
         },
     }

Queries

Once you created a client you can use it's prop query to run a query. The client.query(opts) function returns a Promise and takes an option object as input, it has this props:

  • query: a query parsed with graphql-tag. E.g.
const gql = require("graphql-tag")

// create the client here

client
    .query({
        query: gql`
            {
                user {
                    email
                }
            }
        `,
    })
    .then(res => console.log(res.data))
  • variables (optional): containing the variables used in the graphql query. E.g.
const gql = require("graphql-tag")

// create the client here

client
    .query({
        query: gql`
            query userQuery($id: ID!) {
                user(id: $id) {
                    email
                }
            }
        `,
        variables: {
            id: "myId",
        },
    })
    .then(res => console.log(res.data))

Mutations

To run a mutation use the client.mutation(opts) function. It works as the client.query(opts) function, but instead of passing a query parameter in options you pass a mutation parameter E.g.

client
    .mutate({
        mutation: gql`mutation logIn($email:String, password:String){
        authenticateUser(email:$email, password:$password){
            token
        }
    }`,
        variables: {
            email: "[email protected]",
            password: "password",
        },
    })
    .then(res => console.log(res.data))

Subscriptions

Finally you can use subscriptions through client.subscribe(opts). The options are the same as for client.query(opts), but instead of returning a Promise it returns a ZenObservable.
The ZenObservable has a observable.subscribe(handlers) prop that allows you to handle the subscription results. The handlers object has to have the following props:

  • next: the function handling successful result
  • err (optional): the function handling errors

E.g.

const gql = require("graphql-tag")

client
    .subscribe({
        query: gql`
            subscription {
                deviceCreated {
                    id
                    customName
                }
            }
        `,
    })
    .subscribe({
        next: console.log,
        err: console.log,
    })

Contributing

This package is hosted here, feel free to contribute or ask for any new feature ;)