-
-
Notifications
You must be signed in to change notification settings - Fork 29
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
fix(graphql): column with complex object could throw null pointer exception #1130
fix(graphql): column with complex object could throw null pointer exception #1130
Conversation
…lue in the parameter signature
it looks like there's a Linting problem in the new unit test, could you please fix it
|
|
||
it('should return a query string including a direct reference to a complex object', () => { | ||
const expectation = `firstName, lastName, billing{address{street, zip}}`; | ||
const columns = ['firstName', 'lastName', 'billing', 'billing.address.street', 'billing.address.zip']; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so the only difference is that you added billing
and this was previously throwing an error, is that it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that's right
@@ -195,7 +195,7 @@ export class GraphqlService implements BackendService { | |||
|
|||
const set = (o: any = {}, a: any) => { | |||
const k = a.shift(); | |||
o[k] = a.length ? set(o[k], a) : null; | |||
o[k] = a.length ? set(o[k] ?? undefined, a) : null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from your description, you say doing this would force the use of the default {}
but in that case why not provide it directly here instead? Wouldn't it be better to simply use set(o[k] ?? {}, a)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I can do that if you prefer.
However, the benefit of passing undefined
, is that if you decide to change the default value to something else in the future, you won't have to update the places it's passed in.
eg:
Changing the signature to
const set = (o: any = { a: true }, a: any)
Means updating
set(o[k] ?? { a: true }, a)
// to match the new default value
While, doesn't need to change
set(o[k] ?? undefined, a)
// o will end up having the update default value as specified
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see why it would ever change and I also think passing {}
is much more obvious because I would not have imagined that it would use the default until you said it would, it's less clear with undefined
as opposed to {}
which to me seems clearer what the change and intention is
This is really weird? |
ah sorry that was actually caused by me when I edited the file through GitHub a few minutes ago, oops sorry about that. But since you pulled my code, it fails your PR, could you simply fix it anyway in your PR, I added an extra space by mistake as shown below on line 8 of |
…-when-directly-using-complex-object
Codecov Report
@@ Coverage Diff @@
## master #1130 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 245 245
Lines 16886 16886
Branches 6062 6062
=========================================
Hits 16886 16886
|
@Harsgalt86 shipped in v3.3.2 and all other libs. |
As per discussion
Unit test:
Fix:
By passing undefined it will use the default {} as per the parameter signature.
Currently it is pasing
null
which will not use TypeScript's default value functionality.In TypeScript, a property only makes use of the default value if the property is
undefined
, notnull
set(null, a)
=>o
will have valuenull
set(undefined, a)
=>o
will have value{}
Note: I did try setting the line to be
o[k] = a.length ? set(o[k], a) : undefined;
but it broke other tests (most likely because of strict equality checks?)