Exposing API with Hasura
Hasura is an easy way to expose indexed data using a GraphQL REST API. All you need is to download the latest Hasura engine docker image, set the database connection string, and run it.
Prerequisites
You will need the following for this guide:
We assume you already have an existing Dappetizer project with Postgresql database. Check out our Quick Start guide to learn how to set up one. PostgreSQL support needs to be also added.
Docker installed
Setting up Hasura
If you don't have a local Hasura instance running, you can spawn one using Docker:
Configuring Dappetizer
Dappetizer can automatically configure your Hasura instance to expose the entities you defined in your project. To do this, add the following section to your configuration file:
The url
specifies the Hasura instance Dappetizer will connect to on startup. The properties autotrackEntities
and dropExistingTracking
mean Dappetizer will automatically set up fields based on all known TypeORM entities. Check out the typedoc to learn more about this configuration section.
Testing in Hasura
You can run queries using the Hasura UI in your browser (for example, open http://localhost:8080
if you are running Hasura locally using Docker).
Example of simple GraphQL query of latest indexed block:
Should result output:
You can also secure your Hasura instance by limiting access to your Hasura endpoint, controlling permissions, and setting query limits for particular objects. Read more in the Hasura documentation.
Last updated