graphql-binding-github

Embed GitHub's GraphQL API into your server application

Usage no npm install needed!

<script type="module">
  import graphqlBindingGithub from 'https://cdn.skypack.dev/graphql-binding-github';
</script>

README

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