-
Notifications
You must be signed in to change notification settings - Fork 537
arg parameters in resolve don't inherit from Object #177
Comments
This is happening because we use I think the rationale is that step 1 of
And the closest thing we have in JS to an "empty" object is the kind of prototype-less shell that you create with This in turn means that you can probably replace your
I'm going to close this for now, but please comment again if you have any follow-up. |
@wincent This is a problem when you pass your coerced objects around as inputs to other libraries/tools that you don't control. This happened to me today when using What's the real benefit around stripping objects from their prototypes? |
@nfantone It's general problem of JS you can't use standard objects as maps. For example, if you create an argument called
It should be fixed in |
@IvanGoncharov I'd argue that's not a realistic expectation. "Fixing" all libraries out there is not viable. Not to mention, many library authors could understandably take no action and consider this no be a very valid, correct usage of a native function. And my original question still stands: besides debatable semantics, what's the benefit in using > var o = { toString: 3 }
> o.toString
3
Exactly my point. That was actually my question to you. JS is incredibly permissive in what it allows users to do. I could be sending arrays to libraries where the property There's a tacit consensus that |
@nfantone But it shouldn't affect your schema design you should be able to do this: type Query {
foo(toLocaleString: Boolean): String
} Actually, it's a question for for (const key in args) {
//No need for hasOwnProperty
} |
@IvanGoncharov Thanks for pointing me to the appropriate issue! Sad to see that it's closed, though. I recognize that it rather futile now, but I believe your argument for not using plain And I still haven't heard/read any real tradeoffs of this approach.
This is a rehash of the argument in your original response. To me, this reads dangerously close to: "It's not us doing it wrong, it's everyone else". |
In case there are any libraries left which do not support null type objects, I made a library that is faster than going to json and back because it works in place. Link: https://www.npmjs.com/package/normalize-object-inheritance |
Given a resolve function that looks like
If I try to use
args.person.hasOwnProperty('description')
I get the errorhasOwnProperty is not a function
. I'm forced to useObject.prototype.hasOwnProperty.call
per this issue in another moduleNote that if I create an object similar to args.person I don't get an error. See the
test
example in the code snippet.I'm not enough of a javascript guru to say why this is happening, but it is a gotcha for when I"m attempting an update, where I merge the update with the existing object depending on what attributes are set in the update. My unit tests for the database pass (e.g. just like the
test
object above), but then fails when I attempt have graphql-express use my database.I've checked, and there is no attribute 'hasOwnProperty' on args.person, per the Mozilla description of Object.hasOwnProperty
The text was updated successfully, but these errors were encountered: