You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CHANGELOG.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,6 +6,8 @@
6
6
-**Breaking Change**: `AuthChecker` type is now "function or class" - update to `AuthCheckerFn` if the function form is needed in the code
7
7
-**Breaking Change**: update `graphql-js` peer dependency to `^16.6.0`
8
8
-**Breaking Change**: `buildSchemaSync` is now also checking the generated schema for errors
9
+
-**Breaking Change**: `validate` option of `buildSchema` is set to `false` by default - integration with `class-validator` has to be turned on explicitly
10
+
-**Breaking Change**: `validate` option of `buildSchema` doesn't accept anymore a custom validation function - use `validateFn` option instead
9
11
- support class-based auth checker, which allows for dependency injection
10
12
- allow defining directives for interface types and theirs fields, with inheritance for object types fields (#744)
Copy file name to clipboardExpand all lines: docs/installation.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,10 +10,10 @@ Before getting started with TypeGraphQL we need to install some additional depen
10
10
11
11
## Packages installation
12
12
13
-
First, we have to install the main package, as well as [`graphql-js`](https://github.com/graphql/graphql-js)and [`class-validator`](https://github.com/typestack/class-validator)which are peer dependencies of TypeGraphQL:
13
+
First, we have to install the main package, as well as [`graphql-js`](https://github.com/graphql/graphql-js) which is a peer dependency of TypeGraphQL:
14
14
15
15
```sh
16
-
npm i graphql class-validator type-graphql
16
+
npm i graphql type-graphql
17
17
```
18
18
19
19
Also, the `reflect-metadata` shim is required to make the type reflection work:
TypeGraphQL will automatically validate our inputs and arguments based on the definitions:
@@ -66,16 +81,8 @@ export class RecipeResolver {
66
81
67
82
Of course, [there are many more decorators](https://github.com/typestack/class-validator#validation-decorators) we have access to, not just the simple `@Length` decorator used in the example above, so take a look at the `class-validator` documentation.
68
83
69
-
This feature is enabled by default. However, we can disable it if we must:
70
-
71
-
```typescript
72
-
const schema =awaitbuildSchema({
73
-
resolvers: [RecipeResolver],
74
-
validate: false, // disable automatic validation or pass the default config object
75
-
});
76
-
```
77
-
78
-
And we can still enable it per resolver's argument if we need to:
84
+
We don't have to enable this feature for all resolvers.
85
+
It's also possible to keep `validate: false` in `buildSchema` options but still enable it per resolver's argument if we need to:
79
86
80
87
```typescript
81
88
classRecipeResolver {
@@ -101,6 +108,7 @@ class RecipeResolver {
101
108
```
102
109
103
110
Note that by default, the `skipMissingProperties` setting of the `class-validator` is set to `true` because GraphQL will independently check whether the params/fields exist or not.
111
+
Same goes to `forbidUnknownValues` setting which is set to `false` because the GraphQL runtime checks for additional data, not described in schema.
104
112
105
113
GraphQL will also check whether the fields have correct types (String, Int, Float, Boolean, etc.) so we don't have to use the `@IsOptional`, `@Allow`, `@IsString` or the `@IsInt` decorators at all!
106
114
@@ -193,15 +201,15 @@ It receives two parameters:
193
201
-`argValue` which is the injected value of `@Arg()` or `@Args()`
194
202
-`argType` which is a runtime type information (e.g. `String` or `RecipeInput`).
195
203
196
-
The `validate` function can be async and should return nothing (`void`) when validation passes or throw an error when validation fails.
197
-
So be aware of this while trying to wrap another library in `validate` function for TypeGraphQL.
204
+
The `validateFn` option can be an async function and should return nothing (`void`) when validation passes or throw an error when validation fails.
205
+
So be aware of this while trying to wrap another library in `validateFn` function for TypeGraphQL.
198
206
199
207
Example using [decorators library for Joi validators (`joiful`)](https://github.com/joiful-ts/joiful):
0 commit comments