This repository was archived by the owner on Aug 29, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Change Nullability
Alex Ald edited this page May 21, 2019
·
3 revisions
This decorator allows you to modify a field's nullability on a Graphql type. A decorator for PostGraphile's makeChangeNullabilityPlugin.
Decorator takes a single parameter of type ChangeNullabilityOptions
interface ChangeNullabilityOptions {
fieldName: string;
}We can use the ChangeNullability decorator to allow the email field on the User Graphql type to be null.
NOTE: This decorator usually will be paired with WrapResolver, since the field may initially not allow nulls, but if your WrapResolver modifies the resolver to sometimes return null, then ChangeNullability is needed.
@SchemaType({ typeName: 'User'})
export class UserType {
@ChangeNullability({ fieldName: 'email'})
public emailNullability() {
return true;
}
}@SchemaType({ typeName: 'User'})
export class UserType {
public constructor(private configService: ConfigurationService) {}
@ChangeNullability({ fieldName: 'email'})
public emailNullability() {
return this.configService.get('isEmailNullable');
}
}