plugin-paginate-graphql.js icon indicating copy to clipboard operation
plugin-paginate-graphql.js copied to clipboard

fix: Throw error if graphql response field is null

Open stergion opened this issue 2 years ago • 3 comments

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

stergion avatar Feb 12 '23 17:02 stergion

Some times a graphql response fields have value null.

Are you saying this is intended behavior and not an API issue?

kfcampbell avatar Feb 17 '23 23:02 kfcampbell

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.

stergion avatar Feb 19 '23 20:02 stergion

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.

nickfloyd avatar Aug 03 '23 20:08 nickfloyd