Join data from Google Sheets API and Postgres using Hasura Remote Joins
This post is a part of our Remote Joins series. Remote Joins in Hasura allows you to join data across tables and remote data sources. Data Federation using Hasura Remote Joins is now available in v1.3.0 stable release.
Try it out on Hasura Cloud and let us know what you think!
In this example, we will look at how data from Google Sheets API can be joined with existing data in Postgres using Hasura Remote Joins. Let's say there is a
users table with columns
Adding Google Sheets API 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.
Deploy Custom Resolver
Add the following environment variables in the
.env file on glitch.
- Get the Google Sheets API Key by visiting the Authorize Requests Sheets API page.
- Set the API key as
- We need to input the spreadsheet id from where we are going to fetch data. Set that as
SPREADSHEET_IDenvironment 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.
Get the GraphQL API Endpoint from Glitch and add it as remote schema.
Now let's add the Remote Relationship called
Now the GraphQL query to fetch this data in a single API call would look like the following:
Notice that, the nested query
sheets come from Google Sheets API and it will apply the filter of users.email = sheets.author, there by only giving data about the current user.
Checkout our other posts in the Remote Joins series:
- Building a Music Playlist app with Gatsby, Contentful
- Using GraphQL to join data across Google Places API and Postgres
- Build apps with rich content using Contentful and Postgres
Remote Joins opens up a lot of exciting use-cases and these boilerplates are simple examples to explore the possibilities.