Skip to main content

Nx Plugin for Hasura

The Nx Plugin for Hasura contains generators for managing Hasura services and sdk within an Nx workspace. It provides:

  • Integration with tools such as GraphQL Code Generator
  • Scaffolding for sdk based on GraphQL API as library
  • Scaffolding for hasura metadata and migration folder in services
  • Utilities for environments based migrations

Adding the Hasura plugin#

Adding the Hasura plugin to a workspace can be done with the following:

#yarnyarn add -D @raftlabs/nx-hasura
#npmnpm install -D @raftlabs/nx-hasura

The file structure for a Hasura application looks like:

myorgโ”œโ”€โ”€ appsโ”œโ”€โ”€ libsโ”œโ”€โ”€ nx.jsonโ”œโ”€โ”€ package.jsonโ”œโ”€โ”€ package-lock.jsonโ”œโ”€โ”€ README.mdโ”œโ”€โ”€ servicesโ”‚   โ””โ”€โ”€ hasuraโ”‚       โ”œโ”€โ”€ config.yamlโ”‚       โ””โ”€โ”€ metadataโ”‚           โ”œโ”€โ”€ actions.graphqlโ”‚           โ”œโ”€โ”€ actions.yamlโ”‚           โ”œโ”€โ”€ allow_list.yamlโ”‚           โ”œโ”€โ”€ cron_triggers.yamlโ”‚           โ”œโ”€โ”€ databasesโ”‚           โ”‚   โ””โ”€โ”€ databases.yamlโ”‚           โ”œโ”€โ”€ query_collections.yamlโ”‚           โ”œโ”€โ”€ remote_schemas.yamlโ”‚           โ””โ”€โ”€ version.yamlโ”œโ”€โ”€ toolsโ”‚   โ”œโ”€โ”€ generatorsโ”‚   โ””โ”€โ”€ tsconfig.tools.jsonโ”œโ”€โ”€ tsconfig.base.jsonโ””โ”€โ”€ workspace.json

Executors / Builders#

  • hasura - exposes hasura cli with preloaded environment
  • console - start hasura local console environment
  • migrate - run hasura migrate & metadata command on environment
  • generate - run graphql generator and update the sdk

Generators#

  • application - Create an Hasura service
  • sdk - Create an GraphQL based sdk in lib & configure graphql code generator