@madxnl/madhatter
TypeScript icon, indicating that this package has built-in type declarations

0.7.16 • Public • Published

Description

Framework for quickly starting up new graphql projects based on nestjs

Nest framework TypeScript starter repository.

New version

npm version <nummer>
git push && git push --tags

Link to Madhatter

<cd to madhatter>
npm link
<cd to project>
npm link @madxnl/madhatter
<cd to madhatter>
npm i

(don't forget to build after changes)

New modules/files

npm run generate-index

Settings

You can use environment variables to change certain behavior of MadHatter:

Key description default
SECURE_FILE_DOWNLOADS Enables the default security header on file downloads true

How to use

Validation rules

Starting from version 0.7.14, validationRules field on a service is deprecated. Please use the @ValidationRule decorator instead on a class, and define the rules on the class as static methods. Example:

import { ValidationRule } from '@madxnl/madhatter';
import { Address } from './address.model';
import { Injectable } from '@nestjs/common';

@ValidationRule(Address)
@Injectable()
export class AddressValidator {
  public static city(value: string, model: Address): void | string {
    if (value !== 'Amsterdam') {
      return 'City must be Amsterdam'
    }
    return undefined
  }
}

Do not forget to then register this class as a provider in an appropriate module.

API

GraphQL queries

  • queryArgs object
    • page, size: pagination variables.
    • queryString: A string field used for general search.
    • sort: An array of type SortArg that is directly being mapped to elasticsearch sort query. Recommended for sorting on multiple fields, since changing the order of the sort means simply changing the order of the array.
    • orderBy: An object with key-value pairs, where the keys are fields to be sorted on and the values are the sort order. Madhatter does not provide native type for this, you are required to create the type definition by extending the QueryArgs type. This is also being mapped to elasticsearch sort query, but due to how NestJS processes input variables, the type definition will determine the order of the mapping, and henceforth the order of the sorting. Therefore this is NOT RECOMMENDED for sorting on multiple fields!

              Example type definition on the client side:

@InputType()
class UserOrderBy {
  @Field(() => Order, { nullable: true })
  email: Order
}

@InputType()
export class UserQueryArgs extends PartialType(QueryArgs(UserInputSchema)) {
  @Field(() => UserOrderBy, { nullable: true })
  orderBy?: UserOrderBy
}

Readme

Keywords

none

Package Sidebar

Install

npm i @madxnl/madhatter

Weekly Downloads

534

Version

0.7.16

License

ISC

Unpacked Size

639 kB

Total Files

198

Last publish

Collaborators

  • gergohrubo
  • doeke
  • patrick_madx
  • funonly