gql-reqdeprecated

✨ Minimal and ultra Lightweight GraphQL client (lighter then `graphql-request` ⚡️) that supports Node and browsers for scripts or simple apps 🚀.

Usage no npm install needed!

<script type="module">
  import gqlReq from 'https://cdn.skypack.dev/gql-req';
</script>

README

gql-req

Build Status    Coverage Status    NPM version    License    Top Language    Code Size    Code of Conduct PRs Welcome   

✨ Minimal and ultra Lightweight GraphQL client (lighter then graphql-request ⚡️) that supports Node and browsers for scripts or simple apps 🚀.

This is an attempt to revive graphql-request ❤️.

Features

  • 🦄 Inspired from graphql-request (with almost identical interface).
  • 🔥 Most simple and lightweight GraphQL client (Lighter then graphql-request).
  • ⚖️ Tiny Bundle: 1.515 kB (gzip)
  • 📌 Promise-based API (works with async / await).
  • ✨ Isomorphic through Axios.
  • 🎯 Supports queries through POST and GET.
  • 🎉 Typescript support.

Limitation

  • 🚧 No front-end integration.
  • 🚧 No Cache System.
  • 🚧 No Subscription aka WS (WebSocket) support.

Installation

# npm
npm install gql-req

## yarn 
yarn add gql-req

API

  • GraphQLClient — class for create re-useable client.
  • request — funcs for plain request.

Options

The Options type adopts the AxiosRequestConfig type but with few additions and changes.

  • method — http method used to connect with graphql server ('GET'/'POST', 'POST' as default).
  • headers — key-value object that definite the headers.
  • pureDataResponse — Unlike graphql-request, I have found rawRequest method and Request
    method are same, for that this option was created. if this option is true, the result is equal
    to Request result (false as default).

Usage

const { request, GraphQLClient } = require('gql-req');

// Run GraphQL queries/mutations using a static function (plain request)
request(endpoint, { query, variables }).then(data => console.log(data));

// ... or create a GraphQL client instance to send requests (re-useable client)
// ... you can also update the header by use `setHeaders` method
// setHeaders(key: string, value: string)
// setHeaders(headers: Headers) with Headers = { [key:string]: string }
const client = new GraphQLClient(endpoint, { headers: {} });
client.request(query, variables).then(data => console.log(data));

You can play around with it on this sandbox example codesandbox.io/gql-req.

FAQ

Why gql-req over graphql-request?

Lighter by more then 2 kB, support queries under 'GET' request.

What's the difference between gql-req, Apollo and Relay?

like graphql-request, gql-req is perfect for small scripts or simple apps.

Compared to GraphQL clients like Apollo or Relay, gql-req doesn't have a built-in cache and has no integrations for frontend frameworks. The goal is to keep the package and API as minimal as possible.

So what about Lokka?

Lokka is great but it still requires a lot of setup code to be able to send a simple GraphQL query. gql-req does less work compared to Lokka but is a lot simpler to use.

License


MIT