# gatsby-source-github-api

> gatsby plugin for github v4 API

Latest version **1.0.0** (published 2021-04-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install gatsby-source-github-api
pnpm add gatsby-source-github-api
yarn add gatsby-source-github-api
bun add gatsby-source-github-api
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2021-04-14 |
| First published | 2017-09-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 9.2 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 65 |
| Author | ldd |
| Maintainers | ldds |
| Keywords | gatsby, gatsby-plugin, github |

## Links

- npm: https://www.npmjs.com/package/gatsby-source-github-api
- Repository: https://github.com/ldd/gatsby-source-github
- npm.io page: https://npm.io/package/gatsby-source-github-api

## Dependencies (2)

- [uuid](https://npm.io/package/uuid.md) ^3.1.0
- [graphql-fetch](https://npm.io/package/graphql-fetch.md) ^1.0.1

## Recent versions

- 1.0.0 (latest) — 2021-04-14
- 0.2.1 — 2020-04-07
- 0.2.0 — 2020-03-05
- 0.1.5 — 2020-02-14
- 0.1.4 — 2019-11-07
- 0.1.3 — 2019-08-28
- 0.1.2 — 2019-08-28
- 0.1.1 — 2019-08-28
- 0.1.0 — 2019-05-15
- 0.0.4 — 2019-04-02
- 0.0.3 — 2017-09-10
- 0.0.2 — 2017-09-10
- 0.0.1 — 2017-09-10

## README

[![Build Status](https://travis-ci.com/ldd/gatsby-source-github-api.svg?branch=master)](https://travis-ci.com/ldd/gatsby-source-github-api)
[![Coverage Status](https://coveralls.io/repos/github/ldd/gatsby-source-github-api/badge.svg?branch=master)](https://coveralls.io/github/ldd/gatsby-source-github-api?branch=master)

# gatsby-source-github-api

Source plugin for pulling data into Gatsby from the official GitHub v4 [GraphQL API](https://developer.github.com/v4/).

## Install

`npm i gatsby-source-github-api`

## How to use

Follow GitHub's guide [how to generate a token](https://help.github.com/articles/creating-a-personal-access-token-for-the-command-line/).

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:

```javascript
// In your gatsby-config.js
plugins: [
  {
    resolve: `gatsby-source-github-api`,
    options: {
      // url: API URL to use. Defaults to  https://api.github.com/graphql
      url: someUrl,

      // token: required by the GitHub API
      token: someString,

      // GraphQLquery: defaults to a search query
      graphQLQuery: anotherString,

      // variables: defaults to variables needed for a search query
      variables: someObject
    }
  }
];
```

## Examples

**Search query:**

```javascript
// In your gatsby-config.js
plugins: [
  {
    resolve: `gatsby-source-github-api`,
    options: {
      token: "hunter2",
      variables: {
        q: "author:ldd state:closed type:pr sort:comments",
        nFirst: 2
      }
    }
  }
];
```

resulting API call:

```graphql
  query ($nFirst: Int, $q: String) {
    search(query: "${q}", type: ISSUE, first: ${nFirst}){
      edges{
        node{
          ... on PullRequest{
            title
          }
        }
      }
    }
  }
```

**Custom GraphQL query:**

```javascript
// In your gatsby-config.js
plugins: [
  {
    resolve: `gatsby-source-github-api`,
    options: {
      token: "hunter2",
      variables: {},
      graphQLQuery: `
        query {
          repository(owner:"torvalds",name:"linux"){
            description
          }
        }
        `
    }
  }
];
```

resulting API call:

```graphql
query {
  repository(owner: "torvalds", name: "linux") {
    description
  }
}
```

For more examples see [gatsby-starter-github-portfolio](https://github.com/ldd/gatsby-starter-github-portfolio).

## Tips and Tricks

You'll probably want to use valid GraphQL queries. To help you, GitHub has a [Query Explorer](https://developer.github.com/v4/explorer/) with auto-completion.

![Query Explorer](https://user-images.githubusercontent.com/1187476/30273078-69695a10-96c5-11e7-90b8-7dc876cc214a.png)

## Changelog

- `v1.0.0` add support for gatsby v3. Remove support for older versions of gatsby
- `v0.2.1` update dependencies
- `v0.2.0` provide raw github response
- `v0.1.5` document url option (for GitHub Enterprise users)
- `v0.1.4`
  - Add tests
  - expose DEFAULT_QUERY by exporting it
- `v0.1.3`
  - Change mediaType of exported node to be ignored by `gatsby-transformer-json`
  - prettify changelog of this file
- `v0.1.2` Updated `yarn.lock` to address github security warnings
- `v0.1.1` Updated Readme for easier usage
- `v0.1.0` Submit to Gatsby's Plugin Library
- `v0.0.4` Update dev dependencies, add linting script to package.json
- `v0.0.3` Initial public release

---
_Source: https://npm.io/package/gatsby-source-github-api · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
