Embed GitHub's GraphQL API into your server application
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.remoteResolvers(typeDefs),
}
const server = new GraphQLServer({ resolvers, typeDefs })
server.start(() => console.log('Server running on http://localhost:4000'))
Simply follow this guide and head over to the token settings on GitHub.
- Github GraphQL Explorer: https://developer.github.com/v4/explorer/