Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/create module documents #7

Merged
merged 13 commits into from
May 30, 2024
Binary file added Brew-Logo-Small.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
92 changes: 32 additions & 60 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,73 +1,45 @@
<p align="center">
<a href="http://nestjs.com/" target="blank"><img src="https://nestjs.com/img/logo-small.svg" width="200" alt="Nest Logo" /></a>
<p align="center">
<a href="http://brewww.com/" target="_blank"><img src="https://github.com/BrewInteractive/nestjs-hasura-module/blob/main/Brew-Logo-Small.png?raw=true" width="300" alt="Brew Logo" /></a>
</p>

[circleci-image]: https://img.shields.io/circleci/build/github/nestjs/nest/master?token=abc123def456
[circleci-url]: https://circleci.com/gh/nestjs/nest
<h1 align="center">NestJS Hasura Module</h1>

<p align="center">A progressive <a href="http://nodejs.org" target="_blank">Node.js</a> framework for building efficient and scalable server-side applications.</p>
<p align="center">
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/v/@nestjs/core.svg" alt="NPM Version" /></a>
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/l/@nestjs/core.svg" alt="Package License" /></a>
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/dm/@nestjs/common.svg" alt="NPM Downloads" /></a>
<a href="https://circleci.com/gh/nestjs/nest" target="_blank"><img src="https://img.shields.io/circleci/build/github/nestjs/nest/master" alt="CircleCI" /></a>
<a href="https://coveralls.io/github/nestjs/nest?branch=master" target="_blank"><img src="https://coveralls.io/repos/github/nestjs/nest/badge.svg?branch=master#9" alt="Coverage" /></a>
<a href="https://discord.gg/G7Qnnhy" target="_blank"><img src="https://img.shields.io/badge/discord-online-brightgreen.svg" alt="Discord"/></a>
<a href="https://opencollective.com/nest#backer" target="_blank"><img src="https://opencollective.com/nest/backers/badge.svg" alt="Backers on Open Collective" /></a>
<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://opencollective.com/nest/sponsors/badge.svg" alt="Sponsors on Open Collective" /></a>
<a href="https://paypal.me/kamilmysliwiec" target="_blank"><img src="https://img.shields.io/badge/Donate-PayPal-ff3f59.svg"/></a>
<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://img.shields.io/badge/Support%20us-Open%20Collective-41B883.svg" alt="Support us"></a>
<a href="https://twitter.com/nestframework" target="_blank"><img src="https://img.shields.io/twitter/follow/nestframework.svg?style=social&label=Follow"></a>
<p align="center">This package was created to facilitate the use of the Hasura GraphQL API in NestJS projects.</p>
<p align="center">
<a href="https://sonarcloud.io/summary/overall?id=BrewInteractive_nestjs-hasura-module" target="_blank"><img src="https://sonarcloud.io/api/project_badges/measure?project=BrewInteractive_nestjs-hasura-module&metric=alert_status"/></a>
<a href="https://sonarcloud.io/summary/overall?id=BrewInteractive_nestjs-hasura-module" target="_blank"><img src="https://sonarcloud.io/api/project_badges/measure?project=BrewInteractive_nestjs-hasura-module&metric=coverage"/></a>
<a href="https://www.npmjs.com/package/@brewww/nestjs-hasura-module" target="_blank"><img src="https://img.shields.io/npm/v/@brewww/nestjs-hasura-module.svg" alt="NPM Version" /></a> <a href="https://www.npmjs.com/@brewww/nestjs-hasura-module" target="_blank"><img src="https://img.shields.io/npm/l/@brewww/nestjs-hasura-module.svg" alt="Package License" /></a> <a href="https://www.npmjs.com/@brewww/nestjs-hasura-module" target="_blank"><img src="https://img.shields.io/npm/dm/@brewww/nestjs-hasura-module.svg" alt="NPM Downloads" /></a>
</p>
<p align="center">
<a href="https://www.instagram.com/brew_interactive/" target="_blank"><img src="https://img.shields.io/badge/Instagram-E4405F?style=for-the-badge&logo=instagram&logoColor=white" alt="Instagram" /></a>
<a href="https://www.linkedin.com/company/brew-interactive/" target="_blank"><img src="https://img.shields.io/badge/LinkedIn-0077B5?style=for-the-badge&logo=linkedin&logoColor=white" alt="Linkedin" /></a>
<a href="https://twitter.com/BrewInteractive" target="_blank"><img src="https://img.shields.io/badge/Twitter-1DA1F2?style=for-the-badge&logo=twitter&logoColor=white" alt="Twitter" /></a>
</p>
<!--[![Backers on Open Collective](https://opencollective.com/nest/backers/badge.svg)](https://opencollective.com/nest#backer)
[![Sponsors on Open Collective](https://opencollective.com/nest/sponsors/badge.svg)](https://opencollective.com/nest#sponsor)-->

## Description

[Nest](https://github.com/nestjs/nest) framework TypeScript starter repository.

## Installation

```bash
$ yarn install
```

## Running the app

```bash
# development
$ yarn run start

# watch mode
$ yarn run start:dev

# production mode
$ yarn run start:prod
```

## Test

```bash
# unit tests
$ yarn run test

# e2e tests
$ yarn run test:e2e
## Purpose

# test coverage
$ yarn run test:cov
```
This package is developed to be used in NestJS projects. The purpose of the module is to use Hasura more easily and effectively in NestJS projects.

## Support
## Documents

Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please [read more here](https://docs.nestjs.com/support).
- [Local Development Instructions](https://github.com/BrewInteractive/nestjs-hasura-module/blob/main/docs/local_development.md)
- [Running Tests](https://github.com/BrewInteractive/nestjs-hasura-module/blob/main/docs/local_development.md#Test)
- [Running Build](https://github.com/BrewInteractive/nestjs-hasura-module/blob/main/docs/local_development.md#Build)
- [Hasura Module Installation](https://github.com/BrewInteractive/nestjs-hasura-module/blob/main/docs/installation.md)
- [Using the Hasura Service](https://github.com/BrewInteractive/nestjs-hasura-module/blob/main/docs/using_the_hasura_service.md)
- [Query&Mutation Request](https://github.com/BrewInteractive/nestjs-hasura-module/blob/main/docs/using_the_hasura_service.md#querymutation-request)
- [Basic Usage](https://github.com/BrewInteractive/nestjs-hasura-module/blob/main/docs/using_the_hasura_service.md#basic-usage)
- [Running Queries with Variables](https://github.com/BrewInteractive/nestjs-hasura-module/blob/main/docs/using_the_hasura_service.md#running-queries-with-variables)
- [Running Queries with Authorization Options](https://github.com/BrewInteractive/nestjs-hasura-module/blob/main/docs/using_the_hasura_service.md#running-queries-with-authorization-options)
- [Running Queries with Headers](https://github.com/BrewInteractive/nestjs-hasura-module/blob/main/docs/using_the_hasura_service.md#running-queries-with-headers)
- [Running Queries with Request Flags](https://github.com/BrewInteractive/nestjs-hasura-module/blob/main/docs/using_the_hasura_service.md#running-queries-with-request-flags)
- [Decorators](https://github.com/BrewInteractive/nestjs-hasura-module/blob/main/docs/decorators.md)
- [AuthorizationToken Decorator](https://github.com/BrewInteractive/nestjs-hasura-module/blob/main/docs/decorator_uses.md#authorizationtoken-decorator)

## Stay in touch
## Conclusion

- Author - [Kamil Myśliwiec](https://kamilmysliwiec.com)
- Website - [https://nestjs.com](https://nestjs.com/)
- Twitter - [@nestframework](https://twitter.com/nestframework)
These instructions will help you start, configure, test, and use the nestjs-hasura-module project.

## License

Nest is [MIT licensed](LICENSE).
NestJS Plugin Module is [MIT licensed](LICENSE).
19 changes: 19 additions & 0 deletions docs/decorators.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Decorators

## AuthorizationToken Decorator

Allows to get Authorization token by removing `Bearer` part in the authorization header of the incoming request.

```ts
import { Controller, Get } from '@nestjs/common';
import { AuthorizationToken } from '@brewww/nestjs-hasura-module';

@Controller()
export class ProtectedController {
@Get('/resource')
async getProtectedResource(@AuthorizationToken() authorizationToken: string) {
console.log('Authorization token:', authorizationToken);
return { message: 'Access granted to protected resource' };
}
}
```
85 changes: 85 additions & 0 deletions docs/installation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# Hasura Module Installation

## Installing the Hasura Module Package

In a NestJS project, it is possible to use the [Hasura Module](https://www.npmjs.com/package/@brewww/nestjs-hasura-module) package by installing it. With this package you will be able to easily manage Hasura in your project.

```bash
npm i @brewww/nestjs-hasura-module --save
```

```bash
yarn add @brewww/nestjs-hasura-module
```

### Usage

HasuraModule can be configured via the `register`, `registerAsync`, `forRoot`, and `forRootAsync` methods. These methods determine how the module is configured and how Hasura services are initialized.

#### `register` and `registerAsync`

The Hasura module, with its `register` and `registerAsync` methods, operates within the services, controllers, and other classes at the same level as the module it is imported into. However, services, controllers, and other classes in submodules do not utilize the features of the Hasura module.

```ts
import { HasuraModule } from '@brewww/nestjs-hasura-module';
import { Module } from '@nestjs/common';
import { UserController } from './user.controller';
import { UserService } from './user.service';
import { ConfigService } from '@nestjs/config';

@Module({
imports: [
HasuraModule.register({
graphqlEndpoint: 'http://localhost:8080/v1/graphql',
adminSecret: 'Admin Secret',
}),
// or
HasuraModule.registerAsync({
useFactory: (configService: ConfigService) => {
return {
graphqlEndpoint: configService.get('HASURA_GRAPHQL_ENDPOINT'),
adminSecret: configService.get('HASURA_ADMIN_SECRET'),
};
},
inject: [ConfigService],
}),
],
providers: [UserService],
controllers: [UserController],
})
export class UserModule {}
```

#### `forRoot` and `forRootAsync`

The Hasura module, with its `forRoot` and `forRootAsync` methods, works at both the module level it is imported into and in submodules. By configuring one of the forRoot methods in `app.module.ts`, the Hasura module can be utilized across all classes in the project.

```ts
import { HasuraModule } from '@brewww/nestjs-hasura-module';
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { ConfigService } from '@nestjs/config';

@Module({
imports: [
HasuraModule.forRoot({
graphqlEndpoint: 'http://localhost:8080/v1/graphql',
adminSecret: 'Admin Secret',
}),
// or
HasuraModule.forRootAsync({
useFactory: (configService: ConfigService) => {
return {
graphqlEndpoint: configService.get('HASURA_GRAPHQL_ENDPOINT'),
adminSecret: configService.get('HASURA_ADMIN_SECRET'),
};
},
inject: [ConfigService],
}),
],
providers: [AppService],
controllers: [AppController],
})
export class AppModule {}
```
50 changes: 50 additions & 0 deletions docs/local_development.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Local Development Instructions

Since the project is a project developed specifically for Hasura, care should be taken to ensure that it does not contain Hasura-specific enhancements.

## Requirements

- Node.js (>= 21.x)
- npm (>= 10.x)

## Usage

### Cloning The Repository

First, clone the repository to your local environment:

```bash
$ git clone https://github.com/BrewInteractive/nestjs-hasura-module.git
$ cd nestjs-hasura-module
```

### Package Installation

To install the required dependencies in the project directory:

```bash
$ yarn install
```

## Running Tests

There are unit tests for the project. To run the tests:

```bash
# To run tests in monitoring mode:
$ yarn test

# To run tests in monitoring mode:
$ yarn run test:watch

# To generate a test coverage report:
$ yarn run test:cov
```

## Building

You can use the following command to compile the project.

```bash
$ yarn build
```
Loading