txbm / graphql-http

A GraphQL client for executing queries over HTTP.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

graphql-http

A GraphQL client for executing queries over HTTP.

DISCLAIMER

This library is not suitable for production use. If you're looking for a client with similar functionality, see Lokka. It has much more support and is much more robust.

Usage

import { GQLClient } from 'graphql-http';

const client = GQLClient('http://localhost:3000', {
  fetch: {
    // anything passed here is merged with
    // the options passed to fetch()
    credentials: true,
    headers: {
      'X-Requested-With': 'XMLHttpRequest'
    }
  }
});

Queries

client.query(`
  query ($id: RecordID!) {
    user(id: $id) {
      id
      name
    }
  }
`, { id: 1234 }).then((result) => {
  console.log(result.data.user);
  // => { id: 1234, name: ... }
});

Mutations

client.mutate(`
  mutation ($id: RecordID!, $name: String!) {
    updateUser(input: {id: $id, name: $name}) {
      user {
        id
        name
      }
    }
  }
`, { id: 1234, name: 'Danny' }).then((result) => {
  console.log(result.data.user);
  // => { id: 1234, name: 'Danny' }
});

About

A GraphQL client for executing queries over HTTP.

License:MIT License


Languages

Language:JavaScript 100.0%