gql-api-client
TypeScript icon, indicating that this package has built-in type declarations

0.0.11 • Public • Published

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

Package Sidebar

Install

npm i gql-api-client

Weekly Downloads

1

Version

0.0.11

License

MIT

Unpacked Size

9.57 kB

Total Files

8

Last publish

Collaborators

  • ahincalan