graphql-binding-github
TypeScript icon, indicating that this package has built-in type declarations

0.3.25 • Public • Published

GraphQL Binding for GitHub

CircleCI npm version

Embed GitHub's GraphQL API into your server application

Install

yarn add graphql-binding-github

Example (Demo)

See example directory for full example application.

const { GitHub } = require('graphql-binding-github')
const { GraphQLServer } = require('graphql-yoga')
const { importSchema } = require('graphql-import')

const favoriteRepos = [
  { owner: 'graphcool', name: 'graphql-yoga' },
  { owner: 'graphql', name: 'graphql-js' },
]

const token = '__ENTER_YOUR_GITHUB_TOKEN__'
const github = new GitHub(token)

const typeDefs = importSchema('schemas/app.graphql')
const resolvers = {
  Query: {
    hello: (parent, { name }) => `Hello ${name || 'World'}!`,
    favoriteRepos: (parent, args, context, info) => {
      return Promise.all(
        favoriteRepos.map(args => github.query.repository(args, context, info)),
      )
    },
  },
  // the following is needed to make interfaces, unions & custom scalars work
  ...github.getAbstractResolvers(typeDefs),
}

const server = new GraphQLServer({ resolvers, typeDefs })
server.start(() => console.log('Server running on http://localhost:4000'))

How to create a GitHub Token

Simply follow this guide and head over to the token settings on GitHub.

Resources

Readme

Keywords

none

Package Sidebar

Install

npm i graphql-binding-github

Weekly Downloads

35

Version

0.3.25

License

none

Unpacked Size

320 kB

Total Files

15

Last publish

Collaborators

  • schickling