# gatsby-source-google-sheets

> A source plugin for Gatsby that allows reading data from Google Sheets.

Latest version **1.1.1** (published 2018-03-01) · MIT license · 52 weekly downloads

## Install

```sh
npm install gatsby-source-google-sheets
pnpm add gatsby-source-google-sheets
yarn add gatsby-source-google-sheets
bun add gatsby-source-google-sheets
```

## 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.1.1 |
| Published | 2018-03-01 |
| First published | 2017-09-29 |
| Weekly downloads | 52 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 12.6 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Author | Brandon Paquette |
| Maintainers | brandonsh |
| Keywords | gatsby, gatsby-plugin, gatsby-source-plugin |

## Links

- npm: https://www.npmjs.com/package/gatsby-source-google-sheets
- npm.io page: https://npm.io/package/gatsby-source-google-sheets

## Dependencies (4)

- [uuid](https://npm.io/package/uuid.md) ^3.1.0
- [lodash](https://npm.io/package/lodash.md) ^4.17.4
- [flow-bin](https://npm.io/package/flow-bin.md) ^0.56.0
- [google-spreadsheet](https://npm.io/package/google-spreadsheet.md) 2.0.3

## Alternatives

- [jsforce](https://npm.io/package/jsforce.md) — 851.2K weekly downloads
- [react-native-qrcode-svg](https://npm.io/package/react-native-qrcode-svg.md) — 693.5K weekly downloads
- [@salesforce/plugin-data](https://npm.io/package/@salesforce/plugin-data.md) — 394.9K weekly downloads
- [@backstage/plugin-search-common](https://npm.io/package/@backstage/plugin-search-common.md) — 308.5K weekly downloads
- [@chain-registry/types](https://npm.io/package/@chain-registry/types.md) — 38.4K weekly downloads

## Recent versions

- 1.1.1 (latest) — 2018-03-01
- 1.1.0 — 2018-02-26
- 1.0.5 — 2017-09-30
- 1.0.4 — 2017-09-29
- 1.0.3 — 2017-09-29
- 1.0.2 — 2017-09-29
- 1.0.1 — 2017-09-29
- 1.0.0 — 2017-09-29

## README

# gatsby-source-google-sheets

Why go through the hassle of setting up a complicated headless CMS when Google Sheets already has user permissions, revision history, and a powerful UI? 

This source plugin for [Gatsby JS](https://github.com/gatsbyjs/gatsby) will turn any Google Sheets worksheet into a GraphQL type for build-time consumption. 

## heads-up! 
Until [this issue in Gatsby](https://github.com/gatsbyjs/gatsby/issues/2727) is addressed, when this plugin fails, it will fail *silently*. Your build will still complete, but the data you were expecting to be available won't be there. 

I'll add `retry` to this plugin eventually, but this is a limitation of Gatsby's build that likely affects all source plugins.

# How to:

## Step 1: set up sheets/permissions

Follow this tutorial: https://www.twilio.com/blog/2017/03/google-spreadsheets-and-javascriptnode-js.html

...but stop just before the part that says "Read Data from a Spreadsheet with Node.js"

Essentially this creates a Google Sheets API for your project, then shares whichever spreadsheet you're looking to Gatsby-fy with that endpoint. 



## Step 2: configure your gatsby project

Standard source plugin installation.

```
yarn add gatsby-source-google-sheets


// gatsby-config.js
// ...
{
    resolve: 'gatsby-source-google-sheets',
    options: {
        spreadsheetId: 'get this from the sheet url',
        worksheetTitle: 'ie the name in the worksheet tab',
        credentials: require('./path-to-credentials-file.json')
    }
},
// ...

```

The plugin makes the following conversions before feeding Gatsby nodes:
1. Numbers are converted to numbers. Sheets formats numbers as comma-delineated strings, so to determine if something is a number, the plugin tests to see if the string (a) is non-empty and (b) is composed only of commas, decimals, and digits:
```
if (
    "value".replace(/[,\.\d]/g, "").length === 0 
      && "value" !== ""
   ) { 
    ...assume value is a number and handle accordingly
}
```
2. "TRUE"/"FALSE" converted to boolean true/false
3. empty cells ("" in sheets payload) converted to null
4. Column names are converted to camelcase via lodash _.camelCase() (see note 2 in 'A few notes')


A few notes:

1. Not tested with cells of data type dates.
2. Google sheets mangles column names and converts them all to lower case. This plugin will convert them to camelcase, so the best convention here is to name your columns all lowercase with dashes. e.g. instead of "Column Name 1" or "columnName1", prefer "column-name-1"--this last one will be turned into "columnName1" in your GatsbyQL graph.

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