Join data from Google Sheets API and Postgres using Hasura Remote Joins

Subscribe to the Hasura Newsletter


Use Hasura Remote Joins to join data from your Postgres database with Google Sheets API in GraphQL. Boilerplate -> Google Sheets

This post is a part of our Remote Joins (available in beta) 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 starting from the v1.3 beta release. Jump on our discord or comment on github 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 id, name, email. There is a Google Sheet, with a list of email IDs mapped to URLs. Now we would like to query users data along with the url data in Google Sheets mapped against each user's email id. Let's see how this can be done using a custom resolver.

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 visting the Authorize Requests Sheets API 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.

Get the GraphQL API Endpoint from Glitch and add it as remote schema.

Now let's add the Remote Relationship called sheets

Now the GraphQL query to fetch this data in a single API call would look like the following:

query {
  users {
    sheets {

Notice that, the nested query sheets come from Google Sheets API and it will apply the filter of =, there by only giving data about the current user.

Checkout our other posts in the Remote Joins series:

Remote Joins opens up a lot of exciting usecases and these boilerplates are simple examples to explore the possibilities.

Hasura makes your data instantly accessible over a real-time GraphQL API, so you can build and ship modern apps and APIs faster. Hasura connects to your databases, REST servers, GraphQL servers and third party APIs (eg: Stripe) to provide a unified realtime GraphQL API across all your data sources instantly.

Subscribe to the Hasura Newsletter

PS: We’re hiring!