Skip to content

graphql-api-test/node-github-graphql

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Node-Github-GraphQL

A GitHub GraphQL HTTP wrapper

Table of contents

Installation

npm install node-github-graphql --save

Basic Example

var GithubGraphQLApi = require('node-github-graphql')
var github = new GithubGraphQLApi({
  token: process.env.GITHUB_API_TOKEN
})
github.query(`
{
	viewer {
	  login
	}
}
`, null, (res, err) => {
  console.log(JSON.stringify(res, null, 2))
})

Advanced Example

var GithubGraphQLApi = require('node-github-graphql')
var github = new GithubGraphQLApi({
  Promise: require('bluebird'),
  token: process.env.GITHUB_API_TOKEN,
  userAgent: 'Hello', // Optional, if not specified, a default user agent will be used
  debug: true
})
github.query(`
query ($number_of_repos: Int!) {
  repository(name: "node-github-graphql", owner: "wilsonchingg") {
    ref(qualifiedName: "master") {
      target {
        ...handleCommits
      }
    }
  }
}

fragment handleCommits on Commit {
  id
  history(first: $number_of_repos) {
    pageInfo {
      hasNextPage
    }
    edges {
      node {
        messageHeadline
        oid
        message
        author {
          name
          email
          date
        }
      }
    }
  }
}`, {
  'number_of_repos': 3
}
).then(function (res) {
  console.log(JSON.stringify(res, null, 2))
}).catch((err) => { console.log(err) })

API Reference

new GithubGraphQLApi(options)

- options

Type: objects

The accepted keys are as below:

Key Value
Promise/promise The promise object
token Github API key(Mandatory)
debug To turn on debug log (boolean)
userAgent User-Agent if specified
url Alternative url to send the request

github.request(query, variables, callback)

- query

Type: string

GraphQL query

- variables (optional)

Type: object

Dynamic arguments to be passed inside the query string. See http://graphql.org/learn/queries/#variables

- callback (optional)

Type: function (string response, string error)

If callback is specified, it will be used instead of promises.

LICENSE

MIT license. See the LICENSE file for details.

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%