Socket
Book a DemoInstallSign in
Socket

@awardit/graphql-ast-client

Package Overview
Dependencies
Maintainers
3
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@awardit/graphql-ast-client

Experimental small GraphQL client adaptable to HTTP/1.x or HTTP/2.x

latest
npmnpm
Version
1.1.0
Version published
Maintainers
3
Created
Source

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);

FAQs

Package last updated on 01 Mar 2024

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.