1.1.0 • Published 2 months ago

@awardit/graphql-ast-client v1.1.0

Weekly downloads
5
License
-
Repository
-
Last release
2 months ago

Features

  • All GraphQL Queries are run in GET requests.
  • All GraphQL Mutations are run in POST requests.
  • Multiple simultaneous GraphQL Queries are grouped in the same request.
  • Multiple simultaneous GraphQL Mutations are grouped in the same request, preserving order.

Example

import { parse } from "graphql";
import { createClient, handleFetchResponse } from "@awardit/graphql-client";

// Or use gql template strings or any other tool to compile these into AST
const myQuery = parse(`query {
  test
}`);
const infoQuery = parse(`query {
  info
}`);

const client = createClient({
  runQuery: ({ query, variables }) =>
    fetch("/graphql", {
      headers: {
        "Content-Type": "application/json",
      },
      body: JSON.stringify({ query, variables }),
    }).then(handleFetchResponse),
  debounce: 5,
});

// Single request
const { test } = await client(myQuery);

console.log(test);

// Two merged in the same query
const [{ test }, { info }] = await Promise.all([
  client(myQuery),
  client(infoQuery),
]);

console.log(test);
console.log(info);
1.1.0

2 months ago

1.0.1

2 months ago

1.0.0

2 months ago

1.0.0-rc1

3 months ago

0.2.1

6 months ago

0.2.2

6 months ago

0.2.0

3 years ago

0.1.1

4 years ago

0.1.0

4 years ago