Huge News!Announcing our $40M Series B led by Abstract Ventures.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.2.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
10
increased by150%
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');

// You can also provide your own fetch if you want to
// const client = GraphQLClient('https://jurassic.park/graphql', { fetch: require('node-fetch') });
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

FAQs

Package last updated on 05 Jun 2021

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc