This is a collection of useful modules for creating a NestJS project. Mostly all of these modules are used by the in-house boilerplate of Web & Söhne.
Since nest.js
lets GraphQL
handle its errors in its own way, graphqlErrorParser
is just a function instead of a filter. This will format the errors in the same way of the HTTP errors, so you can also throw HTTP_STATUS
errors instead of plain GraphQLError
for more distinction and using the status code directly in the frontend. It will also add the GraphQL error field of which field this error is coming from.
Usage
Just add the error parser to the GraphQL Module itself.
import { GraphQLModule } from '@nestjs/graphql'
import { GraphQLErrorParser } from '@webundsoehne/nestjs-util-graphql'
import { Module } from '@nestjs/common'
@Module({
imports: [
GraphQLModule.forRoot({
formatError: GraphQLErrorParser
})
]
})
export class ServerModule {}
- Author: Backend Team
- Website: Web & Söhne