-
-
Notifications
You must be signed in to change notification settings - Fork 677
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
support defaultValue for input types #203
support defaultValue for input types #203
Conversation
Codecov Report
@@ Coverage Diff @@
## master #203 +/- ##
==========================================
+ Coverage 95.33% 95.39% +0.06%
==========================================
Files 59 60 +1
Lines 964 978 +14
Branches 166 169 +3
==========================================
+ Hits 919 933 +14
Misses 44 44
Partials 1 1
Continue to review full report at Codecov.
|
Looks ok but it's just a beginning. |
What is |
@InputType()
class SampleInput {
@Field()
implicitDefaultField: string = "implicitDefaultFieldValue"
@Field({ defaultValue: "explicitDefaultFieldValue" })
explicitDefaultField: string;
} input SampleInput {
implicitDefaultField: String = "implicitDefaultFieldValue"
explicitDefaultField: String = "explicitDefaultFieldValue"
} |
How should I go about doing that? |
@benawad class SampleInput {
normalField: string;
stringFieldWithDefault: string = "defaultValue"
}
const instance = new SampleInput();
const defaultsMap = Object.keys(instance).map(fieldName=> ({
fieldName,
defaultValue: instance[fieldName],
}));
console.log(defaultsMap); |
I was able to get it working for input objects, but I'm having trouble figuring out how to do it with args |
@benawad const instance = new (argumentType.target as any)(); |
We should also test some edge cases, like overwriting default values in child classes (implicit and by decorator option): class Base {
prop = "baseProp"
}
class Child extends Base {
prop = "childProp"
} And I think that we should report to user when |
Is it possible to detect the default values for function parameters?
|
It is possible by calling |
Would you like me to make any other changes? |
Yes, we need to add info about all this things in docs 😃
Also, examples and docs might need some updates when there's a default value together with And how do we handle the edge case when parent class has property initializer but child try to overwrites it with decorator option? Does it throw error? |
"And how do we handle the edge case when parent class has property initializer but child try to overwrites it with decorator option? Does it throw error?" I think we should take the child defaultValue in both cases without throwing an error because they could be inheriting from a class from a library or something and not know (and don't care) how thaat class set the default value. "Do we even test the simple inheritance with no overwrites? 😕" Nope, and I just added a test for it and it failed 😂. Where in the code do you handle inheritance? I'll start working on the docs next. |
Before #183 it's all over the place 😆 Args classes inheritance is here: Input types inheritance is here:
Right! Make sure that the tests are covering this cases 😉 Thanks and keep going! 💪 |
Are you going to finish this up or should I checkout your branch and add some changes there? |
I'm not sure when I'll get time to finish this up, so it would be great if you want to. |
@benawad |
I'll take a look at it tonight |
Looks good |
fix: #53
improved on: #141
I'm happy to iterate on this further if any changes are needed.