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

graphql-sql

v1.1.25

Published

A mirco library that helps making graphql request in a simple way using sql like style

Downloads

30

Readme

graphql-sql

A micro library that helps making graphql request in a simple way using sql like style.

Installing

Using npm:

$ npm install graphql-sql

Quickstart

var ocs = require('graphql-sql');

//your graphql services endpoint
var endPoint = 'https://www.endpoint.com/graphql';

new ocs.GQLService().query().select(['id','name']).from('getProduct').where({id:1})
.request(new ocs.HTTPServiceRequest('post', {Authorization:'bearer TOKEN'}, null, endPoint))
.then(response=>console.log(response.data))
.catch(error=>console.log('error',error));

Preview graphql query

require('graphql-sql');

console.log(new ocs.GQLService().query().select(['id','name']).from('getProduct').where({id:1}).toString());
// query 
// {
// 	getProduct(id:1) 
// 	{
// 		id,
// 		name
// 	}
// }

Creating an instance

creating a new instance with a custom config more info about config please refer to : https://www.npmjs.com/package/axios#request-config

require('graphql-sql');

var gqlService = (new gsql.GQLService())

gqlService.getRequester().defaults.baseURL = 'BASE_URL';
gqlService.getRequester().defaults.headers.common['Authorization'] = 'AUTH_TOKEN';

gqlService.query().select(['id','name']).from('getProduct').where({id:1}).post('/path/to/request').then(console.log);

Example

var ocs = require('graphql-sql');

//your graphql services endpoint
var endPoint = 'https://www.endpoint.com/graphql';

//initialize GQLService
new ocs.GQLService()
/* [optional] type of request (query or mutation) by calling .query() or .mutation()
* by default "query" is set.
*/
.query()
/* [required] defining which fields to be returned by passing an array with field name, 
* or object with key (type name) and value (array with list of field)
* #select([fieldName1, fieldName2, {typeName:[fieldName1, fieldName2]}])
*/
.select([{product:['id','name','path','status']},{collection:['id','name','path']}])
//defining type of service
.from('getProduct')
/* [optional] defining condition by passing an object with key pair value ()
* #where(key1:value1,key2:value2})
*/
.where({id:1,madeFrom:"HK"})
/*
* [required] start making request by passing HTTPServiceRequest
* @param {string} type - request method post, get, put...
* @param {object} data - currently only support Authorization
* @param {object} requester - callback object which has implemented result method for data handling and fault method for error handling
* @param {string} endpoint'
* @returns {Promise} 
*/
.request(new ocs.HTTPServiceRequest('post', {Authorization:'bearer TOKEN'}, null, endPoint))
// data handling once receiving server response
.then(response=>console.log(response.data))
// or error handling if anything goes wrong
.catch(error=>console.log('error',error));