Menu

Tiny GraphQL

A tiny GraphQL client for making your dev and user experience better than ever.

Truly tiny

Core

https://www.npmjs.com/package/@tiny-graphql/core

core

Everything you need to get going query for data and perform mutations lives in it's own package.

Cache

https://www.npmjs.com/package/@tiny-graphql/cache

cache

For more advanced use-cases caching may be wanted and can easily be added by including the package.

Installation

> npm install -s @tiny-graphql/core

Optionaly install the cache as well

> npm install -s @tiny-graphql/core @tiny-graphql/cache

Usage

import { createClient } from '@tiny-graphql/core';
import { createCache } from '@tiny-graphql/cache'; // Optional

const client = createClient({
  cache: createCache(), // Optional
  url: '<YOUR_URL>'
});

async function sayHello(name) {
  const result = await client.execute({
    query: `
      query SayHello($name: String) {
        hello(name: $name)
      }
    `,
    variables: {
      name: 'World'
    }
  });

  if (result.errors || !result.data) {
    throw new Error('Could not say hello');
  }

  return result.data.hello;
}