New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@amoutonbrady/graphql-client

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@amoutonbrady/graphql-client

Minimalistic GraphQL client

0.0.4
Source
npm
Version published
Weekly downloads
6
200%
Maintainers
1
Weekly downloads
 
Created
Source
preview badge

Graphql Client

The most minimal graphql client you'll ever find

Features:

  • Typescript ready: written in Typescript
  • Fully tested: literally 3 functions
  • Minimal footprint: 30 loc, ~800 bytes minfied
  • No BS cache or w/e, ask data and you shall receive

Installation

$ npm i @amoutonbrady/graphql-client

Usage

import { GraphQLClient, gql } from '@amoutonbrady/graphql-client';

// A function that creates a client
// You can pass a token a second parameter
const client = GraphQLClient('https://jurassic.park/graphql');
const token = getToken();

// You can set a bearer token after wards
client.setAuth(`Bearer ${token}`);

// gql is just a pass through that minify the string for leaner payload
const query = gql`
 query getDinosaur($name: String!) {
  getDinosaur({ where: { name: $name } }) {
    name
    height
    speed
  }
 }
`;

// This needs to mimic what you send to the query above
const variables = { name: 'Velociraptor' };

// This will return the `data` property of the graphql response or throw if `errors` is present
client.request(query, variables).then(console.log).catch(console.error);
// => { getDinosaur: { name: 'Velociraptor', height: 150, speed: 70 } }

Keywords

graphql

FAQs

Package last updated on 03 Sep 2020

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