Skip to content

ahincalan/gql-api-client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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);  
});

About

Graphql Client Library

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published