eslint-plugin-type-graphql
Version:
Linter for TypeGraphQL decorators
60 lines (49 loc) • 1.37 kB
Markdown
# Prevent invalid types on nullable input types<br/>(`invalid-nullable-input-type`)
## Rule Details
GraphQL contains only a `null` type and not an `undefined` type. Whether a received input in JavaScript is `undefined` or `null` depends on the server implementation. Because assuming input values to be either `null` or `undefined` is dangerous, this rules warns when an input type is not defined as `Type | null | undefined`.
Examples of **incorrect** code for this rule:
```ts
class MyInputType {
myString!: string | undefined;
}
```
```ts
class MyArgsType {
myString!: string | null;
}
```
```ts
class MyResolver {
getUserName( userId: string | null) {
return 'John doe';
}
}
```
Examples of **correct** code for this rule:
```ts
class MyInputType {
myString!: string | null | undefined;
}
```
```ts
class MyArgsType {
myString!: string | null | undefined;
}
```
```ts
class MyResolver {
getUserName( userId: string | null | undefined) {
return 'John doe';
}
}
```