-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: add null
check in deepFindPathToProperty
function
#137
Conversation
Hey @igwejk, thank you very much for the PR and for trying to fix #58! Could you elaborate a bit more as to why you chose to entirely reimplement the It seems like you are covering other use-cases with this implementation as well and I don't quite understand 'which' and 'why' yet. 🙂 |
👋 Hey @davelosert, I honestly got carried away 🤦♂️ when considering other capabilities I would like the plugin to have
Those are needs I came across first when querying repository statistics across an enterprise (and how I came about the motivating issue). This change also serves as a first baby step towards those goals. Let me clearly say that I understand your line of question, and it makes total sense. So, I can offer to trim things down to a simple null check with additional tests if you would prefer that. |
Hey @igwejk, as already discussed internally, we've chosen to not support multiple (or nested) pagination with this library on purpose, as this can lead to all sort of problems (you can find more info and a link to a more in depth-explanation in the README Section: Unsupported Nested Pagination. As I also don't see a GraphQL Response that would be so nested that the current, recursive implementation would cause a overflowing call stack, I'd rather keep the current, more lightweight implementation and just use a null-check to avoid the error reported in #58. Still, thank you again for the contribution and your work here! 👍🏻 |
Was that null check ever implemented? |
Previously the `deepFindPathToProperty` function would occasionally fail with `TypeError: Cannot read properties of null (reading 'hasOwnProperty')`. This change fixes that by adding a null check to the `findPaginatedResourcePath` function. Resolves octokit#58
@karpikpl It was fixed with with an addition of support for deep nested |
null
check in deepFindPathToProperty
function
🎉 This PR is included in version 5.2.3 🎉 The release is available on: Your semantic-release bot 📦🚀 |
responseData, | ||
"pageInfo", | ||
); | ||
if (paginatedResourcePath.length === 0) { | ||
if (paginatedResourcePath === null || paginatedResourcePath.length === 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did this line fix #58? The stacktrace and the description looks like it happens in deepFindPathToProperty
implementation, not for the returned value.
This causes currentValue.hasOwnProperty(searchProp) to throw TypeError: Cannot read properties of null (reading 'hasOwnProperty') error.
plugin-paginate-graphql.js/src/object-helpers.ts
Lines 26 to 28 in 17e58b6
if (currentValue.hasOwnProperty(searchProp)) { | |
return currentPath; | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
…ctokit#137)" This reverts commit cfda527.
Resolves #58
Before the change?
The
deepFindPathToProperty
function would occasionally fail withTypeError: Cannot read properties of null (reading 'hasOwnProperty')
.After the change?
The error has been fixed:
src/object-helpers.ts
: ThedeepFindPathToProperty
function was refactored and its return type updated fromstring[]
tostring[] | null
. The refactoring includes the introduction of a new typeTreeNode
and several new helper functions likegetDirectPropertyPath
,makeTreeNodeChildrenFromData
, andfindPathToObjectContainingProperty
. ThefindPaginatedResourcePath
function was also updated to accommodate these changes.test/typescript-validate.ts
: ThepageInfoBackwaredExported
function was renamed topageInfoBackwardExported
for correct spelling.test/object-helpers.test.ts
: New tests were added for thefindPaginatedResourcePath
function to validate its behavior in different scenarios.Pull request checklist
Does this introduce a breaking change?
Please see our docs on breaking changes to help!