npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gatsby-source-google-spreadsheet

v2.0.0

Published

Gatsby source plugin for all sheets in a Google Spreadsheet

Downloads

1,324

Readme

gatsby-source-google-spreadsheet

Source plugin for sourcing all data from a Google Spreadsheet.

Nodes are created separately for each sheet within the document, allowing for more explicit queries if you have your data managed in the different sheets.

The plugin is based on the node-sheets package and the Google Sheets API V4, which allows for better value types and column names than many of the other Gatsby Google Sheets source plugins.

Configuration

// Add and modify this plugin config to your `gatsby-config.js`:
{
  resolve: "gatsby-source-google-spreadsheet",
  options: {
    // The `spreadsheetId` is required, it is found in the url of your document:
    // https://docs.google.com/spreadsheets/d/<spreadsheetId>/edit#gid=0
    spreadsheetId: "<spreadsheetId>",

    // The `spreadsheetName` is recommended, but optional
    // It is used as part of the id's during the node creation, as well as in the generated GraphQL-schema
    // If you are sourcing multiple sheets, you can set this to distringuish between the source data
    spreadsheetName: "MySheet",

    // The `typePrefix` is optional, default value is "GoogleSpreadsheet"
    // It is used as part of the id's during the node creation, as well as in the generated GraphQL-schema
    // It can be overridden to fully customize the root query
    typePrefix: "GoogleSpreadsheet",

    // The `credentials` are only needed when you need to be authenticated to read the document.
    // It's an object with the following shape:
    // {
    //   client_email: "<your service account email address>",
    //   private_key: "<the prive key for your service account>"
    // }
    //
    // Refer to googles own documentation to retrieve the credentials for your service account:
    //   - https://github.com/googleapis/google-api-nodejs-client#service-to-service-authentication
    //   - https://developers.google.com/identity/protocols/OAuth2ServiceAccount
    //
    // When you have generated your credentials, it's easiest to refer to them from an environment variable
    // and parse it directly:
    credentials: JSON.parse(GOOGLE_SERVICE_ACCOUNT_CREDENTIALS),

    // Simple node transformation during node sourcing can be achieved by implementing the following functions
    // - `filterNode`
    // - `mapNode`
    //
    // By implementing a `filterNode(node): boolean` function, you can choose to eliminate some nodes before
    // they're added to Gatsby, the default behaviour is to include all nodes:
    filterNode: () => true,

    // By implementing a `mapNode(node): node` function, you can provide your own node transformations directly
    // during node sourcing, the default implementation is to return the node as is:
    mapNode: node => node
  }
}

Example usage

Given a spreadsheet with data organized in two sheets like this:

| Sheet 1 | | Sheet 2 | | | --------- | -------- | --------- | -------- | | col1 | col2 | col1 | col2 | | one | 1 | three | 3 | | two | 2 | four | 4 |

You would be able to query it like this:

query {
  allGoogleSpreadsheetSheet1 {
    edges {
      node {
        col1
        col2
      }
    }
  }
  allGoogleSpreadsheetSheet2 {
    edges {
      node {
        col1
        col2
      }
    }
  }
}

With the following result:

{
  allGoogleSpreadsheetSheet1: {
    edges: {
      node: [
        {
          col1: "one",
          col2: 1
        },
        {
          col1: "two",
          col2: 2
        }
      ]
    }
  },
  allGoogleSpreadsheetSheet2: {
    edges: {
      node: [
        {
          col1: "three",
          col2: 3
        },
        {
          col1: "four",
          col2: 4
        }
      ]
    }
  }
}

Considerations

  • In order to automatically parse cell values as numbers and dates, you need to specify the format of the column (or the cell) in your spreadsheet.