Hasura exposes your domain’s data and logic over a high-performance flexible API. If you’re pointing Hasura at a database you might be wondering, where you’d write the necessary business logic that’s required for an API.
Note that Hasura removes the need for writing any code required for external or internal authorization rules.
Hasura provides 4 ways for exposing existing or new business logic in your domain:Event triggers:
Whenever there’s a change in the upstream database, Hasura can capture that change as an event and deliver that to a HTTP webhook that can process that data change event and react to it asynchronously. Apart from attaching specific pieces of logic to events, this is especially useful if you’re thinking about building end to end realtime and reactive applications.REST APIs:
If you have new or existing REST APIs that serve domain data or logic, you can easily connect Hasura to them and extend the GraphQL schema that Hasura exposes. This is useful not just when you have legacy APIs that contain a lot of transactional or application logic, but also when you want to build and serve custom logic with cloud-native code deployed as containers or serverless functions.GraphQL APIs:
If you have a new or existing GraphQL service that extends the schema, say with custom mutations that incorporate your custom logic, or if you’d like to extend your overall GraphQL API with a “sub graph” that comes from a service which you may not directly own, you can use “Remote Schemas” in Hasura to bring in GraphQL services as data & logic providers to your GraphQL API.Stored procedures / functions in the database:
Stored procedures and functions are a common way to write and store high-performance business logic, or transactional logic, that is close to the data. As a part of the GraphQL API that Hasura exposes over databases, Hasura allows you to expose stored procedures or functions as fields in the GraphQL schema. This is a great way to bring in existing business logic that maybe in your database, or to write custom, high-performance logic if you’re familiar with databases!
Choose one or more of the methods above depending on where your existing business logic is, and where you want it to be in the future.