Skip to content

Commit

Permalink
Safer use of Object.prototype.hasOwnProperty (#3069)
Browse files Browse the repository at this point in the history
* Safer use of `Object.prototype.hasOwnProperty`

Fixes an error I get when GraphQL JS passes a prototypeless object into the resolver

```
ReferenceError: maybeRef is not defined
    at eval (eval at <anonymous> (/Users/mattalexander/Projects/edge-sites-schema/tests/regression.test.js:67:7), <anonymous>:1:38)
    at forEach (/projectpath/tests/regression.test.js:67:7)
    at Array.forEach (<anonymous>)
    at Object.<anonymous> (/projectpath/tests/regression.test.js:65:17)
```

* changeset and test

Co-authored-by: Arda TANRIKULU <ardatanrikulu@gmail.com>
  • Loading branch information
mattalexander-pantheon and ardatan authored Jun 17, 2021
1 parent b796078 commit 50be397
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/fifty-wombats-help.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-tools/mock': patch
---

Safer use of Object.prototype.hasOwnProperty #3069
2 changes: 1 addition & 1 deletion packages/mock/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ export type Ref<KeyT extends KeyTypeConstraints = string> = {
};

export function isRef<KeyT extends KeyTypeConstraints = string>(maybeRef: unknown): maybeRef is Ref<KeyT> {
return maybeRef && typeof maybeRef === 'object' && maybeRef.hasOwnProperty('$ref');
return maybeRef && typeof maybeRef === 'object' && '$ref' in maybeRef;
}

export function assertIsRef<KeyT extends KeyTypeConstraints = string>(
Expand Down

0 comments on commit 50be397

Please sign in to comment.