plugin-paginate-graphql.js
plugin-paginate-graphql.js copied to clipboard
fix: Throw error if graphql response field is null
Some times a graphql response fields have value null. This causes currentValue.hasOwnProperty(searchProp) to throw TypeError: Cannot read properties of null (reading 'hasOwnProperty') error. The fix checks first if currentValue is null before calling hasOwnProperty() method.
Resolves #58
Behavior
Before the change?
- Throughs TypeError if graphql response field has value of null.
After the change?
- Checks if field is null to prevent TypeError
Some times a graphql response fields have value null.
Are you saying this is intended behavior and not an API issue?
I'm not sure if this is an API issue or not, although it seems like it.
Some fields that I have checked, like name, location, bio, that return null are of type String, so returning an empty string should be the better option.
Isn't it better though checking for null anyway? These were just the fields that I found. There might be many more fields that return null and some may not be able to change them.
Hey @stergion,
Thanks for doing this ❤️ . Would you mind writing some test coverage for the null check as we'll? That should allow future contributors to understand why it was put in place and also makes sure we don't inadvertently break things in the future.