gatsby-source-github
Source plugin for pulling data into Gatsby from the official Github v4 graphQL API.
Install
npm install --save gatsby-source-github
How to use
Follow Github's guide to generate a token
Once you are done, either create a gatsby-config.js
file or open the one you already have.
In there, you want to add this plugin and at least add the token in the options object:
plugins: [
{
resolve: `gatsby-source-github`,
options: {
token: someString = undefined,
graphQLQuery: anotherString,
variables: someObject
}
}
]
Examples (How to use)
Simple search query
plugins: [
{
resolve: `gatsby-source-github`,
options: {
token: 'hunter2',
variables: {
q: "author:ldd state:closed type:pr sort:comments",
nFirst: 2
}
}
}
]
resulting API call:
query ($nFirst: Int, $q: String) {
search(query: "${q}", type: ISSUE, first: ${nFirst}){
edges{
node{
... on PullRequest{
title
}
}
}
}
}
generic graphQL query
plugins: [
{
resolve: `gatsby-source-github`,
options: {
token: 'hunter2',
variables: {},
graphQLQuery: `
query {
repository(owner:"torvalds",name:"linux"){
description
}
}
`
}
}
]
resulting API call:
query {
repository(owner:"torvalds", name:"linux"){
description
}
}
Changelog
v0.0.2 Include a link to github in package.json
v0.0.1 Initial Release