Framework for quickly starting up new graphql projects based on nestjs
Nest framework TypeScript starter repository.
npm version <nummer>
git push && git push --tags
<cd to madhatter>
npm link
<cd to project>
npm link @madxnl/madhatter
<cd to madhatter>
npm i
(don't forget to build after changes)
npm run generate-index
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 |
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.
-
queryArgs
object-
page
,size
: pagination variables. -
queryString
: A string field used for general search. -
sort
: An array of typeSortArg
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 theQueryArgs
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
}