Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(graphql): Add omitDefaultValue option to PartialType #2988

Merged
merged 5 commits into from Nov 8, 2023

Conversation

nsams
Copy link
Contributor

@nsams nsams commented Aug 27, 2023

This allows removing defaultValue for the optional properties. It doesn't make much sense to have a nullable field in an update dto that has a default value.

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Other... Please describe:

What is the current behavior?

PartialType does keep defalutValue option. It doesn't make much sense to have a nullable field in an update dto that has a default value.

Issue Number: #1425

What is the new behavior?

A new option is added (omitDefaultValue) that allows removing the defaultValue.

Also the current second argument (decorator) is converted into a optionsOrDecorator argument.

Does this PR introduce a breaking change?

  • Yes
  • No

The old behaviour is kept by default, so this is not a breaking change.

@nsams nsams changed the title fix(graphql): Add omitDefaultValue option to PartialType feat(graphql): Add omitDefaultValue option to PartialType Aug 28, 2023
This allows removing defaultValue for the optional properties. It doesn't make much sense to have
a nullable field in an update dto that has a default value.

The old behaviour is kept by default, so this is not a breaking change.
): optionsOrDecorator is PartialTypeOptions {
return (
optionsOrDecorator &&
((optionsOrDecorator as PartialTypeOptions).decorator !== undefined ||
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about 'decorator' in optionsOrDecorator instead?

@@ -14,16 +14,39 @@ import { PropertyMetadata } from '../schema-builder/metadata';
import { getFieldsAndDecoratorForType } from '../schema-builder/utils/get-fields-and-decorator.util';
import { applyFieldDecorators } from './type-helpers.utils';

interface PartialTypeOptions {
decorator?: ClassDecoratorFactory;
omitDefaultValue?: boolean;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
omitDefaultValue?: boolean;
omitDefaultValues?: boolean;

?

@kamilmysliwiec kamilmysliwiec merged commit e42222c into nestjs:master Nov 8, 2023
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants