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

Allow disabling inferring the default values from properties initializers #793

Closed
MichalLytek opened this issue Feb 28, 2021 · 2 comments
Closed
Assignees
Labels
Community 👨‍👧 Something initiated by a community Enhancement 🆕 New feature or request Solved ✔️ The issue has been solved
Milestone

Comments

@MichalLytek
Copy link
Owner

Extracted from #787 (comment)

@InputType("ArchiveInput")
@ObjectType()
export class Archive {
	@Field(is => Date)
	created = new Date();
}

This behavior is unexpected, as I had no intention to even affect the API in this manner. All I wanted to achieve, was that I have a default value when I locally construct an instance of the class, like in a test. There is a specific defaultValue setting that I can and do use when I want to set default values. I didn't expect any magic to happen beyond that.

Type-GraphQL, by applying this default value detection magic, prevents this use case entirely. I end up declaring an input schema (where the input value is nullable and then set in a resolver), an output schema (where the value isn't nullable) and a class to internally represent the same schema, but which sets default values upon construction. This is something I was hoping to avoid by using the library in the first place.

I'm happy to accept that this 3-model-approach is ultimately the correct one for what I'm trying to achieve. I just wasn't expecting this and the root cause is unsettling. I don't feel in control of what's happening. I'd much rather like to disable this default value detection entirely.

In some cases, the default value should be only internally, like current date for some optional date filer input field.

In order to not introduce a breaking change, a schema option should be introduced to disable that mechanism.

@MichalLytek MichalLytek added Enhancement 🆕 New feature or request Community 👨‍👧 Something initiated by a community labels Feb 28, 2021
@MichalLytek MichalLytek added this to the 1.x versions milestone Feb 28, 2021
@MichalLytek MichalLytek self-assigned this Feb 28, 2021
@MichalLytek
Copy link
Owner Author

Closing by e8e164d 🔒

@MichalLytek MichalLytek added the Solved ✔️ The issue has been solved label May 22, 2021
@MichalLytek MichalLytek modified the milestones: 1.x versions, 1.2 Nov 25, 2021
@oliversalzburg
Copy link
Contributor

Upgraded to 1.2.0-rc.1 today and this seems to work really well for me. Thanks 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Community 👨‍👧 Something initiated by a community Enhancement 🆕 New feature or request Solved ✔️ The issue has been solved
Projects
None yet
Development

No branches or pull requests

2 participants