Skip to content

Latest commit

 

History

History
92 lines (66 loc) · 1.94 KB

README.md

File metadata and controls

92 lines (66 loc) · 1.94 KB

NestJS Hasura

Installation

npm install @speakbox/nestjs-hasura

Usage

Import the module and the service in your NestJS application:

import { Module } from '@nestjs/common';
import { HasuraModule, HasuraService } from '@speakbox/nestjs-hasura';

@Module({
  imports: [HasuraModule],
  providers: [HasuraService],
})
export class AppModule {}

Using the service

import { Inject, Injectable } from "@nestjs/common";
import { HasuraService } from '@speakbox/nestjs-hasura';

@Injectable()
export class ExampleService {
  constructor(
    @Inject(HasuraService) private readonly hasura: HasuraService,
  ) {}
  
  exampleRequest() {
    return this.hasura.request(
      gql`query SomeQuery($id: bigint!) {
        some_resource_by_pk(id: $id) {
          id
          name
        }
      }`,
      { id: 1}
    );
  }
}

For more information on how to use the service, please refer to the NestJS Documentation.

Environment variables

This package relies on environment variables to configure Hasura:

# Hasura API endpoint
HASURA_GRAPHQL_ENDPOINT=https://hasura.example.com/v1/graphql

# Hasura API Admin Secret
HASURA_GRAPHQL_ADMIN_SECRET=my-secret

Change Log

See Changelog for more information.

Contributing

Contributions welcome! See Contributing.

Author

Valentin Prugnaud @valentinprgnd

License

Licensed under the MIT License - see the LICENSE file for details.