Guard resource and related-idea resolvers against blank references (prevents build crash) - #114
Open
eastagiletracker wants to merge 1 commit into
Conversation
The resources and relatedIdeas resolvers mapped every entry in an idea's
reference list straight through resourceQuery()/ideaPostQuery() into
nodeModel.findOne(). Those builders return null for a blank/falsy name, and
findOne() destructures its argument (`const { query = {} } = args`), so a null
argument throws a TypeError and fails the build. An empty row left in a Decap
CMS list widget is enough to trigger this.
Filter out falsy reference names before the lookup, matching how the authors
resolver already handles the same situation. Genuine typos in non-empty names
still surface via reporter.error as before. Adds Vitest coverage for both
resolvers.
👷 Deploy request for project-idea-board pending review.Visit the deploys page to approve it
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR proposes hardening the
IdeaPostGraphQL resolvers so a blankresourcesorrelated_ideasreference can no longer crash the Gatsby build. We include this PR work along with a full history of your repo at https://eastagiletracker.com/projects/241. You can sign in with your GitHub ID to claim ownership of the project.What this fixes
createIdeaPostResolverresolves an idea'sresourcesandrelatedIdeasby mapping every entry of the reference list straight throughresourceQuery(name)/ideaPostQuery(name)intocontext.nodeModel.findOne(...). Those query builders returnnullfor a blank/falsy name, and Gatsby'snodeModel.findOneopens withconst { query = {} } = args(seegatsby/dist/schema/node-model.js), so anullargument throwsTypeError: Cannot read properties of null (reading 'query')and fails the build. An empty row left behind in a Decap CMS list widget is enough to trigger it. The siblingauthorsresolver already guards against this (.filter(Boolean)), andprimaryContactdoes too (if (!query) return null) —resourcesandrelatedIdeaswere the two that didn't.The fix filters out falsy reference names before the lookup in both resolvers, matching the existing
authorshandling. Genuine typos in non-empty reference names still surface throughreporter.errorexactly as before, so no diagnostics are lost — only empty rows are skipped.How I verified it
Reproduced on your current
main(b89254a) with a focused test that drives the resolver with a blank entry, using afindOnestand-in that mirrors Gatsby's real destructuring contract:After the change the same tests pass, and the full suite plus the type check are green (I ran
yarn testandyarn typeCheckagainst a clean baseline first, so this adds no new failures):The change is two
.filter(Boolean)guards ingatsby/resolvers/resolvers.jsplus a newgatsby/resolvers/test/resolvers.test.js; it is additive and backward-compatible — valid references resolve exactly as before.How this was managed
We imported your issues, pull requests and milestones into a live agile board (97 stories, 3 labels) and used it to track this work. This specific change is the story at https://eastagiletracker.com/projects/241/stories/130961, and the full board is at https://eastagiletracker.com/projects/241.
If you'd rather not receive contributions like this, reply
no-more-prson this pull request and we won't open any further ones on your repositories.Lawrence W. Sinclair
CEO / East Agile
linkedin.com/in/lwsinclair/
eastagile.com