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

sk-query-builder

v1.0.2

Published

An even simpler es5 friendly GraphQL query builder

Downloads

8

Readme

SK GraphQL Query Builder

An even simpler Javascript, ES5 friendly, GraphQL query builder

No need for multiple functions, commands, or es5 compatible compiling. Just create a single Query with an options object and get a GraphQL ready query string in return.

Forked from https://github.com/codemeasandwich/graphql-query-builder - a simple ES6 graphql query builder

info:

npm version License pull requests welcome GitHub stars

If this was helpful, ★ it on github

Install

npm install sk-query-builder

Query function:

Query is available out of the box on the Window object, but can also be required to prevent namespace interference.

var Query = require('sk-query-builder');

Use:

Query can be called with a single arguement of either a single query object or an array of query objects and will return a GraphQL formatted string to be attached to query.

var query = Query( query_obj[, options ] );

Query Constructor:

Single query object or an array of multiple queries to turn into a GQL query string.

| Key Value | Argument | Description | |--- |--- |--- | | func: | String | the name of the query function | | alias: | String | alias value that result will be returned under | | filters: | Object | An object mapping attribute to values | | value: | String or Object | Attribute name or nested query you want returned. Can be an array of multiple values with the values: key | | values: | Array | An Array of value items ( String or Obj ) to return multiple values |

Example: ( get the sum of users in given timeframe )
var sumQuery = Query({
  func: "sum",
  alias: "total_sum",
  filters: { from: 0, to: 1501234567890 },
  value: "count"
});
Output: ( returns formatted string )
"{total_sum: sum(from: 0,to: 1501234567890){count}}"

Additional Options:

| Key Value | Argument | Description | |--- |--- |--- | | prefix | String | prefix string before query obj ( i.e. "mutation" ) |

Example:
var prefixQuery = Query({
  func: 'update',
  filters: { id: 1, value: 3 },
  value: [ "id", "value" ]
}, { prefix: 'mutation' );

console.log( prefixQuery );
// "mutation{update(id:1,value:3){id,value}}"

Use:

Add Enum values inside query objects buy either the Enum() function with a string to represent the final value or by simply using any string starting with "e$"

Enum( 'VALUE' ) == 'e$VALUE'

| Argument (one) | Description | |--- |--- | | String | the name of the query function |

Example: ( get the sum of users in given timeframe )
var eventQuery = Query({
  alias: 'event_123',
  func: 'event',
  filters: {
    frequency: Enum( 'DAILY' ), // can also be "e$DAILY"
    value: Enum( 'CLICKS' )
  },
  values: [ 'timestamp', 'value' ]
});

console.log( eventQuery );
// "{event_123:event(frequency:DAILY,value:CLICKS){timestamp,value}}"

Examples:

Nested query values

var FetchLeeAndSam = Query({
  alias: 'FetchLeeAndSam',
  func: 'users',
  values: [
    {
      alias: 'lee',
      func: 'user',
      filters: { id: '1' },
      values: ['name', 'id' ]
    },
    {
      alias: 'sam',
      func: 'user',
      filters: { id: '2' },
      values: ['name', 'id' ]
    }
  ]
});

console.log( FetchLeeAndSam );
//"{FetchLeeAndSam:users{lee:user(id:"1"){name,id},sam:user(id:"2"){name,id}}}"

Multiple query array with reusable values

var reusable = function( model, year ) {
  return {
    alias: model,
    func: 'vehicle',
    filters: { year: year },
    values: [
      "num_produced",
      "horsepower"
    ]
  };
};

var CarCatalog = Query([
  reusable( 'Mustang', '1964' ),
  reusable( 'Camero', '1988' )
]);

console.log( CarCatalog );
//"{Mustang:vehicle(year:"1964"){num_produced,horsepower} Camero:vehicle(year:"1988"){num_produced,horsepower}}"

run Examples

node example/simple.js