Catch the highlights of GraphQLConf 2023!Click for recordings.Or check out our recap blog post.
Client
graphql-http

graphql-http

graphql-http (opens in a new tab) is a simple, pluggable, zero-dependency, GraphQL over HTTP Protocol compliant server and client.

Installation

npm i graphql graphql-http

Use

Connect to the server and execute operations.

import { createClient } from 'graphql-http';
 
const client = createClient({
  url: 'http://localhost:50005/graphql',
});
 
(async () => {
  let cancel = () => {
    /* abort the request if it is in-flight */
  };
 
  const result = await new Promise((resolve, reject) => {
    let result;
    cancel = client.subscribe(
      {
        query: '{ hello }',
      },
      {
        next: (data) => (result = data),
        error: reject,
        complete: () => resolve(result),
      },
    );
  });
 
  expect(result).toEqual({ hello: 'world' });
})();