graphql-fetch

    1.0.1 • Public • Published

    graphql-fetch Build Status js-standard-style

    Thin GraphQL client powered by fetch.

    Installation

    npm i --save graphql-fetch

    Usage

    var fetch = require('graphql-fetch')('http://domain.com/graphql')
     
    var query = `
      query q (id: String!) {
        user(id: $id) {
          id,
          email,
          name
        }
      }
    `
    var queryVars = {
      id: 'abcdef'
    }
    var opts = {
      // custom fetch options
    }
     
    /**
     * @param  {Query} query graphql query
     * @param  {Object} [vars]  graphql query args, optional
     * @param  {Object} [opts]  fetch options, optional
     */
    fetch(query, queryVars, opts).then(function (results) {
      if (results.errors) {
        //...
        return
      }
      var user = result.data.user
      //...
    })

    Notes

    • Uses isomorphic-fetch under the hood, which makes fetch, Headers, Request, and Response globally available.

    License

    MIT

    Install

    npm i graphql-fetch

    DownloadsWeekly Downloads

    709

    Version

    1.0.1

    License

    MIT

    Last publish

    Collaborators

    • tjmehta