Hasura: A GraphQL Approach To Connecting Postgres With Neo4j

Hasura instant graphQL

At Dayspring, we love discovering new technologies that will allow us to better serve our clients’ needs. Fortunately, because we are a digital consulting agency based in San Francisco, we are often surrounded by a host of innovative practices and technical knowledge. One of our recent collaborations has been with a research lab doing chemical and biological research on the health benefits and nutritional properties of different carbohydrates.

To assist them, we needed a graph database that would accommodate the massive quantity of data expressed through nodes and relationships, and have gotten a lot of mileage out of using Hasura as our GraphQL engine.

What is Hasura?

Hasura is an open-source solution that integrates one or more GraphQL endpoints into a unified API. We are loving the admin interface for seeing and modifying table data, as well as the ability to write custom handlers or business logic based off of certain triggers or actions in our applications.

Suffice to say, Hasura is a brilliant solution to integrate all of our backend efforts into one solution. It enables us to reduce boilerplate code, especially when layering GQL on top of a typical relational database like SQL or PostgreSQL.

What are GraphQL, Postgres, and Neo4j?

GraphQL, or Graph Query Language, is quickly becoming standard as the structured way to ask (“query”) for the data that you need. It embodies the relationships between objects in a way that is easy to understand. GQL is different from REST in that it does not tie a particular URL to a specific resource. Instead, GQL enables you to completely separate what data you are requesting from how you intend to get it.

Postgres, short for PostgreSQL, has been a robust object-relational database system for over 30 years of development. It is free and open-source.

Conversely, Neo4j is a graph database system. It is a NoSQL solution because it has no tables and it does not use Structured Query Language to provide backend transactions. Instead it uses Cypher, a graph-optimized query language, to follow patterns along edges and nodes in the graph and articulate data connections.

How Does Hasura Help Us Connect Postgres with Neo4j?

Through our work with BCD, we discovered that we needed both the advantages of PostgreSQL as well as the powerful capabilities of a graph database. However, it was daunting to maintain GraphQL APIs for both of these databases. Hasura made it trivial to layer GraphQL endpoints on top of our Postgres tables. But even better, it enabled us to reach across databases through the definition of “remote schemas” to integrate our backend needs!

The result of this remote schema relationship is that we can query from objects stored in our PG tables to nodes and associated information that we store in our Neo4j database. If we want to take advantage of Hasura’s built in actions and event triggers, we can also easily trigger information cascades from one database to the other. Using Hasura, we get the best of both worlds—the simpler, well-defined relational database tables in Postgres, combined with the nuanced and complex web of information stored in our graph database, mimicking all of the complex relationships between chemical and biological processes that BCD is working so hard to uncover.

Do I Need a Graph Database?

It depends. Most of our clients do not need the complex web of relationships that only a graph database can capture. Smaller non-profit organizations or sales-oriented businesses, for example, benefit from a more streamlined approach to storing and retrieving data. Using customizable WordPress templates that are maintainable by the customer afterwards also allows for the skills of our Design team to shine.

If you are a start-up that has more intensive needs, let’s talk! We love developing elegant solutions, but we always work first to understand the problems and avoid over-engineering something that doesn’t need to be built.

Read more

Let’s talk

Put our 20+ year track record in software development to work for you. Get in touch today.

415.247.9421 Ext. 102