How to Build a Supergraph using Snowflake, Neon PostgreSQL, and Hasura in Five Steps
Tags: graphql, snowflake, postgres, hasura
Published: 2024-06-20 20:17:00

---
title: How to Build a Supergraph using Snowflake, Neon PostgreSQL, and Hasura in Five Steps
published: true
description: By combining Hasura Cloud, Snowflake DB, and PostgreSQL on Neon, you can create a powerful supergraph backend to handle complex data tasks such as joining data across multiple data sources and filtering data on model relations.
tags: graphql,snowflake,postgresql,hasura 
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fkv89aae6oemdh5oquz2.png
# Use a ratio of 100:42 for best results.
published_at: 2024-06-20 20:17 +0000
canonical_url: https://hasura.io/blog/building-a-supergraph-backend-with-hasura
---

By combining Hasura Cloud, Snowflake DB, and PostgreSQL on Neon, you can create a powerful supergraph backend to handle complex data tasks such as joining data across multiple data sources and filtering data on model relations. It's a supergraph framework with modular, unified layers that is continuously evolving and deployed by many companies worldwide. 

![Supergraph with Hasura](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fkv89aae6oemdh5oquz2.png)

This tutorial will guide you through the creation of an application backend that leverages the powerful features of Snowflake and PostgreSQL databases. I will show how to integrate tables from both Snowflake and PostgreSQL into your supergraphs, allowing you to perform sophisticated, nested queries that connect models from diverse databases. This approach not only increases your backend's capabilities but also streamlines the data handling process for more complex data relationship management across different sources.


## 1. Setting up Hasura Cloud
Start with Hasura Cloud to quickly create GraphQL APIs. 

- Sign up for a free [Hasura Cloud account](https://cloud.hasura.io/signup?pg=product&plcmt=body&cta=get-started-for-free&tech=default).
- Create a new project and connect it to your version control system (e.g., GitHub).
- Define your data model using Hasura's metadata.
- Run some exciting queries

![Run GraphQL queries](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lw5azl6yk0fpgmfy7bjn.png)

## 2. Integrating Snowflake DB
Snowflake is a cloud-based data warehousing platform that [seamlessly integrates with Hasura Cloud](https://hasura.io/graphql/database/snowflake). To integrate Snowflake:

- Obtain your Snowflake credentials (account, username, password).

![Connect to Snowflake](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lsyz0pashcv7pi26u1rw.png)

- In Hasura Cloud, navigate to the "Data" tab and add a new data source.
- Select "Snowflake" and input your credentials.
- “Import all tables” to add all the tables as models to the supergraph

![Import snowflake tables to Hasura](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k07j450t945qzpdcepys.png)

## 3. Incorporate PostgreSQL on Neon
[Neon](https://hasura.io/docs/latest/databases/postgres/neon/) is a managed platform for PostgreSQL databases. To incorporate PostgreSQL on Neon into your supergraph backend:

Sign up for Neon and create a new PostgreSQL database instance.

![Neon PostgreSQL](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pveb53fkcoibiq6dp2aj.png)

- Obtain the connection details for your Neon PostgreSQL database.
- In Hasura Cloud, add another data source, but this time, select "Neon Database" and authorize the Neon database connection details.

![Connect to Neon](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r1pqr2tg7xremwnvav0f.png)

- Add the models and relationships you want to track in the data tab.

## 4. Executing individual queries
Now that you have Snowflake and PostgreSQL on Neon integrated into your Hasura Cloud project, you can execute queries individually.

### Querying Snowflake
To query data from Snowflake, you can use Hasura's GraphQL API:

```graphql
query MyQuery {
  SNOWFLAKETABLE {
    COLUMN1
    COLUMN2
  }
}
```

Replace snowflakeTable, column1, and column2 with your Snowflake table and columns.

![Snowflake GraphQL query](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dvj7cz2nwz7mqmx6aqr3.png)

### Querying PostgreSQL on Neon
Similarly, to query data from your Neon PostgreSQL database:

```graphql
query MyQuery {
  neontable {
    column1
    column2
    column3
  }
}
```

Replace neonTable, column1, and column2 with your Neon table and columns.

![Postgres GraphQL Query](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8e6mcd50z96hlmz15q7i.png)

## 5. Nested queries for complex data retrieval
GraphQL has the ability to handle complex data retrieval through nested queries. Here’s an example:

```graphql
query {
  getUser(userId: 123) {
    username
    email
    posts {
      title
      content
    }
  }
}
```

In this query:
- We retrieve user details by their ID from either Snowflake or PostgreSQL.
- Then, we fetch the user's posts with their titles and content.

By defining appropriate relationships and foreign keys in Hasura's metadata for both Snowflake and PostgreSQL, you can perform nested queries like the one above, aggregating data from multiple sources into a single response.

## Conclusion
Continue to explore and experiment with Hasura Cloud, Snowflake DB, and PostgreSQL on Neon. Discover how to efficiently integrate multiple data sources and execute both individual and nested queries. This will increase performance and scalability across a wide range of applications.