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 🙏

© 2025 – Pkg Stats / Ryan Hefner

graph-squirrel

v0.2.1

Published

A schema-driven GraphQL provider for MS SQL databases

Readme

Graph Squirrel

Graph Squirrel is a JavaScript/TypeScript library to translate GraphQL requests with your SQL query:

  • 🚀 Efficient: Graph Squirrel leverages join information in your schema to retrieve all required data in a single query.
  • 🧬 Generic: Use Graph Squirrel with a server implementation or SQL library of your own choice.
  • 🔌 Pluggable: Since Graph Squirrel is an implementation detail of your resolvers, it can be used at any level of your resolver chain. Entities retrieved from your SQL database can then be enriched with child resolvers.

Supported features

  • Joins
  • Filters
  • Sort
  • Offset-based pagination

Installation

npm i graph-quirrel # using npm

yarn graph-squirrel # using yarn

Basic usage

  1. Use directives to map object fields with SQL tables and columns:
type Query {
  # use @join to map a field to a SQL table
  users: [User] @join(name: "tickets_table")
}

type User {
  # use @column to map a field with a SQL column
  id: GraphQLInt @column

  # if a field depends on multiple SQL columns, you can provide
  # the corresponding column names as a list
  # note: you'll have to implement a resolver for `displayName`
  displayName: GraphQLString @column(names: ["givenName", "surname"])

  # use @join with ownKey/foreignKey to link your SQL tables together
  # and retrieve all data in a single query
  tickets: [Ticket]
    @join(name: "tickets_table", ownKey: "id", foreignKey: "userId")
}

type Ticket {
  id: GraphQLInt @column
  title: GraphQLString @column
}
  1. Within your resolvers, use ASTQueryTranslator to translate GraphQL resolve information into a SQL query:
const queryResolver = {
  users(source, args, parent, info) {
    const translator = new ASTQueryTranslator(info),
      query = translator.run();

    const [queryStr, bindings] = query.buildQuery();

    // run your query against a MS SQL database
    return new Promise((resolve, reject) => {
      sql.query(
        process.env.CONNECTION_STRING,
        queryStr,
        bindings,
        (err, rows) => {
          if (err || !rows) reject(err);
          // use `transform` to convert rows into a GraphQL result
          else resolve(translator.transform(rows!));
        }
      );
    });
  },
};

Query example

{
  users {
    id
    displayName
    tickets {
      title
    }
  }
}

The above query will give you the following JSON data:

{
  "users": [
    {
      "id": 1,

      "givenName": "Bob",
      "surname": "McCain",

      "tickets": [{ "title": "Ticket #1" }, { "title": "Ticket #2" }]
    }
  ]
}

Note: givenName and surname are automatically retrieved as dependencies for displayName. However, it's up to you to define a custom resolver to compute its effective value, e.g.:

const userResolver = {
  displayName(source) {
    return `${source.givenName} ${source.surname}`;
  },
};

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT