🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

gql-api-client

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gql-api-client

Graphql Client Library

0.0.11
latest
Source
npm
Version published
Weekly downloads
21
950%
Maintainers
1
Weekly downloads
 
Created
Source

NPM Version Build Status Coverage Status

Graphql API Client

Simple usage and lightweight graphql api client. Returning promise type.

Install Package
npm install gql-api-client
Usage Examples
const request =  new GqlClient(
    {
       url: 'http://localhost:4000/graphql',
       query: `{                                   
                  user(id:1) {
                     id 
                     name
                     email                                                                          
                  }                      
               }`
    }
);
request.send().then((response)=>{
  console.log(response);
  /* Output
    {
      data: {..},
      status: ..,
      statusText: ..,
      headers: {..}
    }
   */
});
const request =  new GqlClient();
request.url = 'http://localhost:4000/graphql';
request.query =`{                                   
                  user(id:1) {
                    id 
                    name
                    email                                                                          
                  }                      
                }`;
request.send().then((response)=>{
  console.log(response);  
});

Pass parameters

const request =  new GqlClient();
request.url = 'http://localhost:4000/graphql';
request.query =`query ($id: Int!) {                                   
                  user(id:$id) {
                    id 
                    name
                    email                                                                          
                  }                      
                }`;
request.send({id:1}).then((response)=>{
  console.log(response);  
});

Bearer token support

const request =  new GqlClient();
request.url = 'http://localhost:4000/graphql';
// Bearer token
request.token = 'TestToken';
request.query =`query ($id: Int!) {                                   
                  user(id:$id) {
                    id 
                    name
                    email                                                                          
                  }                      
                }`;
request.send({id:1}).then((response)=>{
  console.log(response);  
});

Add custom headers

const request =  new GqlClient();
request.url = 'http://localhost:4000/graphql';
request.headers = {'authorization':'Token'};
request.query =`query ($id: Int!) {                                   
                  user(id:$id) {
                    id 
                    name
                    email                                                                          
                  }                      
                }`;
request.send({id:1}).then((response)=>{
  console.log(response);  
});

Keywords

graphql

FAQs

Package last updated on 28 Jan 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts