Skip to content
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(gatsby): context.nodeModel.runQuery should return [] instead of null #25885

Merged
merged 7 commits into from
Feb 24, 2021

Conversation

kartikcho
Copy link
Contributor

@kartikcho kartikcho commented Jul 20, 2020

As of now, context.nodeModel.runQuery returns Promise<null>, but the documentation specifies type Promise<Node[]> to be returned.

This PR resolves #25857 by updating the default return statement.

@kartikcho kartikcho requested a review from a team as a code owner July 20, 2020 18:53
@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Jul 20, 2020
@kartikcho
Copy link
Contributor Author

@vladar could you provide more context on these tests that seem to affect the change in this PR. Thanks!

// Nothing is lt null so zero nodes should match
// (Note: this is different from `lte`, which does return nulls here!)
expect(result).toEqual(null)

// Nothing is gt null so zero nodes should match
// (Note: this is different from `gte`, which does return nulls here!)
expect(result).toEqual(null)

@sidharthachatterjee sidharthachatterjee added topic: GraphQL Related to Gatsby's GraphQL layer and removed status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer labels Jul 21, 2020
@vladar
Copy link
Contributor

vladar commented Jul 21, 2020

Thanks for the PR! I think you should modify those tests to expect [] vs. null (as that's effectively what we change here).

But as I mentioned in the issue this is likely a breaking change, so we'll keep this PR open until the next major.

@vladar vladar added the breaking change If implemented, this proposed work would break functionality for older versions of Gatsby label Jul 21, 2020
@vladar vladar requested a review from pvdz July 21, 2020 11:41
kartikcho and others added 2 commits July 23, 2020 04:11
Co-authored-by: Vladimir Razuvaev <vladimir.razuvaev@gmail.com>
Copy link
Contributor

@pvdz pvdz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like @vladar said, this is a small but breaking change that we can't apply on a patch or even a minor version bump.

I would 💜 this PR when we're ready to bump the major because the distinction is annoying to me (I've messed with this code a lot) and I think it's only there because the original filtering library (sift) did it this way.

But an API is an API and even though the change looks benign, you can bet there's code out there that relies on this behavior.

@@ -417,10 +417,7 @@ function convertAndApplyFastFilters(
stats.totalSiftHits++
}

if (firstOnly) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

iirc there were one or two other places where this happens (returning null vs returning an empty array) but maybe I already unified those into this check here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you want to update here @pvdz?

@pvdz
Copy link
Contributor

pvdz commented Jul 28, 2020

I'm going to put this PR in draft mode as we won't be merging it any time soon. Rest assured that I really want this PR merged once we can!

@pvdz pvdz marked this pull request as draft July 28, 2020 10:03
@muescha
Copy link
Contributor

muescha commented Jul 28, 2020

should then the docs be updated to reflect the current state (with a deprecation warning that it would change in 3.0)?

@pvdz
Copy link
Contributor

pvdz commented Jul 29, 2020

It's been like this for so long that I would kind of suggest to leave it as is for now. But if you're set on updating them then you could add a note that we plan to eliminate this inconsistency in a future major bump.

# Conflicts:
#	packages/gatsby/src/schema/__tests__/run-query.js
@vladar vladar changed the title context.nodeModel.runQuery returns [] instead of null Feb 24, 2021
@kartikcho
Copy link
Contributor Author

Thanks for still working on getting this in @vladar, let me know if I can be of help in any way!

@vladar vladar marked this pull request as ready for review February 24, 2021 18:56
Copy link
Contributor

@vladar vladar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR and let's merge it, finally! 🎉

@vladar vladar merged commit 684ac0e into gatsbyjs:master Feb 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change If implemented, this proposed work would break functionality for older versions of Gatsby topic: GraphQL Related to Gatsby's GraphQL layer
5 participants