question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

arg parameters in resolve don't inherit from Object

See original GitHub issue

Given a resolve function that looks like

resolve: (root, args, request) => {
  test =  { uuid: '1234', description: 'lead singer of the Doors' };
  console.log('result: ' + Object.prototype.hasOwnProperty.call(args.person, 'description'));
  // XXX This fails!:  console.log('result: ' + args.person.hasOwnProperty('description'));
  console.log('result: ' + test.hasOwnProperty('description'));
  return db.personUpdate(request.user, args.person);
}

If I try to use args.person.hasOwnProperty('description') I get the error hasOwnProperty is not a function. I’m forced to use Object.prototype.hasOwnProperty.call per this issue in another module

Note 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

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:2
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

6reactions
nfantonecommented, Jun 11, 2018

@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 Object suffers from lack of common sense vs. technical purity. Removing widely used methods from the most commonly used type in JS is only asking for trouble and generating incompatibilities with pretty much everything else out in the wild.

And I still haven’t heard/read any real tradeoffs of this approach.

And I don’t think we would change anything since it’s a big breaking change because following is valid at the moment:

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”.

5reactions
nfantonecommented, Jul 16, 2018

@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 dynamo-data-types to convert GraphQL inputs into DynamoDB representations. The module uses obj.hasOwnProperty, which raised an exception. This can happen any time, any where from sources that are out of reach for users. Having to wrap my inputs with ad-hoc objects, like { ...myGraphQLInput }, feels hackish and unsafe.

What’s the real benefit around stripping objects from their prototypes?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Resolve error 'there is no argument given that corresponds to ...
Fixing your bug: The error occurs due to the lack of a parameterless constructor (or your lack of using the base() method in...
Read more >
Super Inherit Your Python Class - E.Y. - Medium
It takes 2 parameters. The first is the class whose parent's scope we're trying to resolve to, and the second argument is the...
Read more >
Promise.resolve() - JavaScript - MDN Web Docs
This function flattens nested layers of promise-like objects (e.g. a promise that fulfills to ... Argument to be resolved by this Promise ....
Read more >
Inheritance in Jackson | Baeldung
By default, Jackson recreates data objects by using no-arg constructors. This is inconvenient in some cases, such as when a class has non- ......
Read more >
Object orientation - The Apache Groovy programming language
Groovy does support named parameters so long as the class contains a no-arg constructor or provides a constructor which takes a Map argument...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found