Skip to content

Commit

Permalink
add google sheets api
Browse files Browse the repository at this point in the history
  • Loading branch information
praveenweb committed Jul 30, 2019
0 parents commit 08c5a2c
Show file tree
Hide file tree
Showing 7 changed files with 1,286 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# google-sheets-remote-schema

[Google Sheets API](https://developers.google.com/sheets/api/) is a service to read, write and format data in sheets programatically.

## Adding Google Sheets as Remote Schema

To be able to query Google Sheets data via Hasura, it needs to be added as a Remote Schema using the Hasura Console.

- Get the Google Sheets API Key by visting the [Authorize Requests Sheets API](https://developers.google.com/sheets/api/guides/authorizing#APIKey) page.
- Set the API key as `GOOGLE_SHEETS_API_KEY` environment variable.
- We need to input the spreadsheet id from where we are going to fetch data. Set that as `SPREADSHEET_ID` environment variable. We can find the sheet ID in the url.
- This custom resolver is used to accept a user's email and will return a filtered list of data pertaining to that user.

## Google Sheets API Documentation

[API Documentation](https://developers.google.com/sheets/api/).

## Deploy with Glitch

1. Click the following button to edit on glitch

[![glitch-deploy-button](https://raw.githubusercontent.com/hasura/graphql-engine/master/community/boilerplates/auth-webhooks/nodejs-express/assets/deploy-glitch.png)](http://glitch.com/edit/#!/import/github/praveenweb/google-sheets-remote-schema)

2. Add the following environment variables in the `.env` file on glitch.

```env
GOOGLE_SHEETS_API_KEY=xxx
SPREADSHEET_ID=xxx
PORT=3000
```

## Running Locally

```bash
npm install
PORT=3000 GOOGLE_SHEETS_API_KEY=xxx SPREADSHEET_ID=xxx npm start
```
9 changes: 9 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const { ApolloServer } = require('apollo-server');
const { typeDefs } = require('./type_defs');
const { resolvers } = require('./resolvers');

const schema = new ApolloServer({ typeDefs, resolvers });

schema.listen({ port: process.env.PORT}).then(({ url }) => {
console.log(`schema ready at ${url}`);
});
Loading

0 comments on commit 08c5a2c

Please sign in to comment.