Skip to content

Commit ebf38c6

Browse files
committed
readme
1 parent a2a51b6 commit ebf38c6

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

README.md

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,44 @@
1-
# github-graphql-binding
1+
# GitHub GraphQL Binding
2+
23
Embed GitHub's GraphQL API into your server application
4+
5+
## Install
6+
7+
```sh
8+
yarn add github-graphql-binding
9+
```
10+
11+
## Example
12+
13+
See [example directory](example) for full example application.
14+
15+
```js
16+
const { GitHub } = require('github-graphql-binding')
17+
const { GraphQLServer } = require('graphql-yoga')
18+
const { importSchema } = require('graphql-import')
19+
20+
const favoriteRepos = [
21+
{ owner: 'graphcool', name: 'graphql-yoga' },
22+
{ owner: 'graphql', name: 'graphql-js' },
23+
]
24+
25+
const token = '__ENTER_YOUR_GITHUB_TOKEN__'
26+
const github = new GitHub(token)
27+
28+
const typeDefs = importSchema('schemas/app.graphql')
29+
const resolvers = {
30+
Query: {
31+
hello: (parent, { name }) => `Hello ${name || 'World'}!`,
32+
favoriteRepos: (parent, args, context, info) => {
33+
return Promise.all(
34+
favoriteRepos.map(repo =>
35+
github.delegate('query', 'repository', repo, context, info),
36+
),
37+
)
38+
},
39+
},
40+
}
41+
42+
const server = new GraphQLServer({ resolvers, typeDefs })
43+
server.start(() => console.log('Server running on http://localhost:4000'))
44+
```

0 commit comments

Comments
 (0)