Skip to content
This repository was archived by the owner on Jan 6, 2025. It is now read-only.

Commit c7d54d1

Browse files
committed
update README.md
1 parent f00d0b8 commit c7d54d1

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,40 @@ Just use it as you would normally use [Nest's built-in validation pipe](https://
6565
## Motivation
6666

6767
This behavior is achievable by passing a custom `exceptionFactory` to the original pipe, but I found myself writing the same exception factory for each one of my projects, so I made this package to do the job.
68+
69+
## GraphQL Validation Filter
70+
71+
This filter is just what I personally use for my GraphQL responses. it catches the validation exceptions and returns them as the following object:
72+
73+
```ts
74+
@ObjectType()
75+
export class UserError {
76+
@Field(() => [String], { nullable: true })
77+
field: string[];
78+
79+
@Field(() => String)
80+
message: string;
81+
}
82+
```
83+
84+
Additionally, your returned objects should contain a `userErrors` field, for example:
85+
86+
```ts
87+
@ObjectType()
88+
export class PostCreatePayload {
89+
@Field(() => Post)
90+
post: Post;
91+
92+
@Field(() => [UserError])
93+
userErrors: UserError[];
94+
}
95+
```
96+
97+
To use the filter, add it filter to your main.ts file:
98+
99+
```ts
100+
import { GraphqlValidationFilter } from '@exonest/better-validation';
101+
102+
// ...
103+
app.useGlobalFilters(new GraphqlValidationFilter());
104+
```

0 commit comments

Comments
 (0)