Adding custom business logic with Hasura

Hasura provides instant realtime GraphQL on Postgres along with an authorization engine. This makes it easy to setup a blazing-fast GraphQL API that is secure & scalable, including GraphQL subscriptions that work and scale out of the box!

How would you add custom business logic though?

This blogpost covers the different ways of customising and extending Hasura so that you can add your own business logic easily, with your favourite tools & frameworks.

You will notice that Hasura encourages opinions that allow you to leverage the benefits of cloud-native patterns (stateless microservices, serverless functions, event-driven) as you think about adding new or existing business logic to your application.


Data-driven logic

Often, some business logic is better (or easier) done in the database than in the application layer. For example, complex high-performance aggregations (say a continuous time-series aggregate) or transactional stored-procedures.

Hasura makes it easy to use Postgres views (named-queries) and functions to add new types and fields to the GraphQL API. Hasura also makes it easy to customise and extend types and fields generated in the GraphQL API.

Hasura makes it easy to get the best out of your database, while enforcing and reusing a common authorisation system so that you don't have to write code for data-heavy tasks.


Bring your own GraphQL service: Custom business logic

Hasura provides an easy way to add business logic using your own GraphQL API using "remote schemas".

(This method is ideal when you need to bring types to your GraphQL schema that are not derived from the database that Hasura is already pointing to.)

Domain specific business logic often reside in microservices that might speak to other databases, external SaaS APIs or require complex application layer processing and transformations.

Hasura can integrates them directly into a unified GraphQL API and also allows you to configure semantic relationships between the types exposed by different GraphQL service by configuring "remote joins".


Event-driven business logic (write heavy workflows)

As microservices and serverless functions proliferate the “backend stack”, event-driven patterns are becoming the norm to deal with increasing complexity.

Driving business logic with events allows for easier decoupling and fault-tolerance without compromising on scalability.

Hasura Actions provide an easy way to create a custom GraphQL mutation specification and maps them to event handlers which can be microservices APIs or serverless functions (or even Postgres functions!).

Hasura internally takes care of the event plumbing, including event capture, persistence and delivery.

Read more about Hasura actions here!


Talk to us!

If you're having trouble thinking about how to add your business logic to an application designed with Hasura, hit us up on our community discord or set up a chat with us!

👉 Discord: discord.gg/hasura

👉Github: github.com/hasura/graphql-engine

👉 Setup a call with the team: Schedule a chat


Hasura is an open-source engine that gives you realtime GraphQL APIs on new or existing Postgres databases, with built-in support for stitching custom GraphQL APIs and triggering webhooks on database changes.


PS: We’re hiring!


Tanmai Gopal

Tanmai Gopal

Tanmai is the co-founder of hasura.io. He is passionate about making it easier to build things.

Read More