Skip to content

Guard resource and related-idea resolvers against blank references (prevents build crash) - #114

Open
eastagiletracker wants to merge 1 commit into
AllenCell:mainfrom
eastagiletracker:agile-board/guard-blank-relation-references
Open

Guard resource and related-idea resolvers against blank references (prevents build crash)#114
eastagiletracker wants to merge 1 commit into
AllenCell:mainfrom
eastagiletracker:agile-board/guard-blank-relation-references

Conversation

@eastagiletracker

Copy link
Copy Markdown

This PR proposes hardening the IdeaPost GraphQL resolvers so a blank resources or related_ideas reference 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

createIdeaPostResolver resolves an idea's resources and relatedIdeas by mapping every entry of the reference list straight through resourceQuery(name) / ideaPostQuery(name) into context.nodeModel.findOne(...). Those query builders return null for a blank/falsy name, and Gatsby's nodeModel.findOne opens with const { query = {} } = args (see gatsby/dist/schema/node-model.js), so a null argument throws TypeError: 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 sibling authors resolver already guards against this (.filter(Boolean)), and primaryContact does too (if (!query) return null) — resources and relatedIdeas were the two that didn't.

The fix filters out falsy reference names before the lookup in both resolvers, matching the existing authors handling. Genuine typos in non-empty reference names still surface through reporter.error exactly 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 a findOne stand-in that mirrors Gatsby's real destructuring contract:

$ npx vitest run gatsby/resolvers/test/resolvers.test.js
TypeError: Cannot read properties of null (reading 'query')
 ❯ gatsby/resolvers/resolvers.js:69:39   (resources)
 ❯ gatsby/resolvers/resolvers.js:26:39   (relatedIdeas)
 Test Files  1 failed (1)

After the change the same tests pass, and the full suite plus the type check are green (I ran yarn test and yarn typeCheck against a clean baseline first, so this adds no new failures):

$ yarn test
 ✓ gatsby/utils/test/gatsby-resolver-utils.test.js (9 tests)
 ✓ gatsby/resolvers/test/resolvers.test.js (2 tests)
 Test Files  2 passed (2)
      Tests  11 passed (11)

$ yarn typeCheck
Done in 1.50s.

The change is two .filter(Boolean) guards in gatsby/resolvers/resolvers.js plus a new gatsby/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.

board

If you'd rather not receive contributions like this, reply no-more-prs on 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

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.
@netlify

netlify Bot commented Aug 12, 2026

Copy link
Copy Markdown

👷 Deploy request for project-idea-board pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 432fe5e

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant