graphql.js

A Simple and Isomorphic GraphQL Client for JavaScript

graphql.js: lightweight graphql client

Lightest GraphQL client with intelligent features.

Bower version NPM version Build Status

Originally inspired by Robert Mosolgo’s blog post

Features

  • No dependencies, plain vanilla JavaScript.
  • Plug & Play.
  • Isomorphic.
  • Runs on most browsers.
  • You don’t need to install Node.js ecosystem on your computer.

Overview

GraphQL is based on a very simple HTTP transaction, which sends a request to an endpoint with query and variables.

Many libraries require complex stacks to make that simple request. In any project you don’t use ReactRelay, you’ll need a simpler client which manages your query and makes a simple request.

// Connect...
var graph = graphql("/graphql")

// Prepare...
graph.fragment({
  user: `on User {
    id,
    name
  }`
})

const allUsers = graph(`query { allUsers { ...user } }`)

const createUser = graph(`mutation (@autodeclare) {
  createUser($firstName, $lastName) { ...user }
}`)

await createUser({
  firstName: "John",
  lastName: "Doe"
})

const users = await allUsers()

console.log(users)
// {
//   "allUsers": [{ "id": 1, "name": "John Doe" }] 
// }

Subscribe to the Newsletter

Get our latest news,tutorials,guides,tips & deals delivered to your inbox.

1 thought on “Graphql.js

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.