Skip to content

fix: crash when saving empty GraphQL query in YAML collections - #6453

Merged
bijin-bruno merged 3 commits into
usebruno:mainfrom
sanjaikumar-bruno:fix/graphql-query-null-crash
Dec 18, 2025
Merged

bijin-bruno merged 3 commits into
usebruno:mainfrom
sanjaikumar-bruno:fix/graphql-query-null-crash

Conversation

@sanjaikumar-bruno

@sanjaikumar-bruno sanjaikumar-bruno commented Dec 18, 2025 •

Copy link
Copy Markdown
Contributor

BRU-2353

Saving a GraphQL request in YAML format with an empty query body crashes the app. The YAML parser sets query to null when the field is missing, and CodeMirror's setValue() expects a string, causing a crash.

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced consistency in how GraphQL requests handle empty or missing fields, ensuring more reliable query and variable processing.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai

coderabbitai Bot commented Dec 18, 2025 •

Copy link
Copy Markdown
Contributor

Caution

Review failed

The pull request is closed.

Walkthrough

This PR standardizes GraphQL field handling by converting undefined/null values to empty strings in both the UI component (GraphQLRequestPane) and the file format parser (parseGraphQLRequest.ts), along with adding a timing adjustment in test utilities.

Changes

Cohort / File(s) Summary
GraphQL defaults standardization
packages/bruno-app/src/components/RequestPane/GraphQLRequestPane/index.js, packages/bruno-filestore/src/formats/yml/items/parseGraphQLRequest.ts
Standardize default values for GraphQL query and variables from undefined/null to empty strings in both component retrieval and file format parsing
Test utility timing
tests/utils/page/actions.ts
Add 200ms delay after building common locators in createEnvironment before clicking environment selector, with TODO to replace with dynamic waiting

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

  • Verify empty string defaults don't break GraphQL parsing or validation logic downstream
  • Check the TODO comment in test utilities regarding replacement of waitForTimeout with dynamic waiting logic
  • Confirm consistency of empty string vs undefined/null handling across related GraphQL code paths

Possibly related PRs

Suggested reviewers

  • helloanoop
  • lohit-bruno
  • naman-bruno

Poem

✨ Empty strings where nulls once lived,
GraphQL fields now standardized,
From UI to parser, consistency thrives—
No more undefined in these skies! 🚀

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title directly describes the main fix: preventing crashes when saving empty GraphQL queries in YAML collections, which aligns with the changeset's purpose of handling undefined/empty GraphQL variables across multiple components.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 43dd855 and 1b356e5.

📒 Files selected for processing (1)
  • tests/utils/page/actions.ts (1 hunks)

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/bruno-app/src/components/RequestPane/QueryUrl/index.js (1)

147-159: Inconsistent behavior with HTTP paste handler.

The GraphQL paste handler always dispatches variables (even when empty string), while the HTTP paste handler at line 276 only dispatches non-empty, non-whitespace variables. Consider applying the same trim check here for consistency.

🔎 Apply this diff for consistent handling:
 let variables = request.body.graphql.variables || '';
-if (variables) {
+if (variables && variables.trim()) {
   try {
     variables = JSON.parse(variables);
   } catch (error) {
     // Keep variables as-is if JSON parsing fails
   }
+  dispatch(updateRequestGraphqlVariables({
+    itemUid: item.uid,
+    collectionUid: collection.uid,
+    variables: variables
+  }));
 }
-dispatch(updateRequestGraphqlVariables({
-  itemUid: item.uid,
-  collectionUid: collection.uid,
-  variables: variables
-}));
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5e6444b and 43dd855.

📒 Files selected for processing (3)
  • packages/bruno-app/src/components/RequestPane/GraphQLRequestPane/index.js (1 hunks)
  • packages/bruno-app/src/components/RequestPane/QueryUrl/index.js (2 hunks)
  • packages/bruno-filestore/src/formats/yml/items/parseGraphQLRequest.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{js,jsx,ts,tsx}

📄 CodeRabbit inference engine (CODING_STANDARDS.md)

**/*.{js,jsx,ts,tsx}: Use 2 spaces for indentation. No tabs, just spaces
Stick to single quotes for strings. For JSX/TSX attributes, use double quotes (e.g., )
Always add semicolons at the end of statements
No trailing commas
Always use parentheses around parameters in arrow functions, even for single params
For multiline constructs, put opening braces on the same line, and ensure consistency. Minimum 2 elements for multiline
No newlines inside function parentheses
Space before and after the arrow in arrow functions. () => {} is good
No space between function name and parentheses. func() not func ()
Semicolons go at the end of the line, not on a new line
Names for functions need to be concise and descriptive
Add in JSDoc comments to add more details to the abstractions if needed
Add in meaningful comments instead of obvious ones where complex code flow is explained properly

Files:

  • packages/bruno-app/src/components/RequestPane/GraphQLRequestPane/index.js
  • packages/bruno-filestore/src/formats/yml/items/parseGraphQLRequest.ts
  • packages/bruno-app/src/components/RequestPane/QueryUrl/index.js
🧠 Learnings (1)
📚 Learning: 2025-12-17T21:41:24.730Z
Learnt from: naman-bruno
Repo: usebruno/bruno PR: 6407
File: packages/bruno-app/src/components/Environments/ConfirmCloseEnvironment/index.js:5-41
Timestamp: 2025-12-17T21:41:24.730Z
Learning: Do not suggest PropTypes validation for React components in the Bruno codebase. The project does not use PropTypes, so reviews should avoid proposing PropTypes and rely on the existing typing/validation approach (e.g., TypeScript or alternative runtime checks) if applicable. This guideline applies broadly to all JavaScript/JSX components in the repo.

Applied to files:

  • packages/bruno-app/src/components/RequestPane/GraphQLRequestPane/index.js
  • packages/bruno-app/src/components/RequestPane/QueryUrl/index.js
🧬 Code graph analysis (2)
packages/bruno-app/src/components/RequestPane/GraphQLRequestPane/index.js (1)
packages/bruno-cli/src/runner/prepare-request.js (1)
  • get (1-1)
packages/bruno-filestore/src/formats/yml/items/parseGraphQLRequest.ts (1)
packages/bruno-converters/src/insomnia/insomnia-to-bruno.js (1)
  • graphql (9-9)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: SSL Tests - Linux
  • GitHub Check: SSL Tests - Windows
  • GitHub Check: SSL Tests - macOS
  • GitHub Check: Playwright E2E Tests
  • GitHub Check: CLI Tests
  • GitHub Check: Unit Tests
🔇 Additional comments (3)
packages/bruno-filestore/src/formats/yml/items/parseGraphQLRequest.ts (1)

32-33: LGTM! Consistent default handling.

Defaulting GraphQL query and variables to empty strings prevents null/undefined issues downstream and aligns with the frontend changes.

packages/bruno-app/src/components/RequestPane/GraphQLRequestPane/index.js (1)

48-50: LGTM! Consistent default value.

The empty string default for variables aligns with the backend changes and ensures the GraphQLVariables component receives a string value.

packages/bruno-app/src/components/RequestPane/QueryUrl/index.js (1)

276-276: LGTM! Robust whitespace check.

The trim check properly guards against empty or whitespace-only variables before dispatching.

@bijin-bruno
bijin-bruno merged commit 1cc117c into usebruno:main Dec 18, 2025
@coderabbitai coderabbitai Bot mentioned this pull request Jan 1, 2026
5 of 6 tasks
maxenceleblanc pushed a commit to maxenceleblanc/curly_cats2 that referenced this pull request Jul 20, 2026
…uno#6453)

* fix: ensure GraphQL variables are handled correctly in multiple components

* fix: reverted some changes

* chore: temp fix for tests

---------

Co-authored-by: Bijin A B <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants