Skip to content

make post default gql method#7713

Open
ganesh-bruno wants to merge 4 commits intousebruno:mainfrom
ganesh-bruno:fix/default-post-gql
Open

make post default gql method#7713
ganesh-bruno wants to merge 4 commits intousebruno:mainfrom
ganesh-bruno:fix/default-post-gql

Conversation

@ganesh-bruno
Copy link
Copy Markdown
Collaborator

@ganesh-bruno ganesh-bruno commented Apr 8, 2026

  • Make POST as a default method for gql req which user can change but while creating the default will be POST
Screen.Recording.2026-04-08.at.6.44.17.PM.mov

Summary by CodeRabbit

  • Bug Fixes
    • GraphQL requests now default to POST instead of GET for new requests.
    • Switching a request to GraphQL applies the POST method by default to avoid method/type mismatch.
    • Changing the request type to HTTP or gRPC now forces the HTTP method back to GET to ensure compatibility.
    • Selecting a WebSocket request type sets the request method to WS automatically.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 8, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 4aa3bfbe-482d-4eea-ad60-6acefc695476

📥 Commits

Reviewing files that changed from the base of the PR and between 364674f and 235ffaf.

📒 Files selected for processing (1)
  • packages/bruno-app/src/components/Sidebar/NewRequest/index.js
✅ Files skipped from review due to trivial changes (1)
  • packages/bruno-app/src/components/Sidebar/NewRequest/index.js

Walkthrough

Set NewRequest's requestMethod initial value to 'POST' when getRequestType(collectionPresets) returns 'graphql-request', otherwise 'GET'. Radio onChange handlers now force requestMethod after formik.handleChange for http-request ('GET'), grpc-request ('GET'), and ws-request ('ws'); graphql-request uses only formik.handleChange.

Changes

Cohort / File(s) Summary
NewRequest component
packages/bruno-app/src/components/Sidebar/NewRequest/index.js
initialValues.requestMethod is conditional: 'POST' when getRequestType(collectionPresets) === 'graphql-request', otherwise 'GET'. Updated radio onChange handlers to call formik.handleChange then set requestMethod for http-request ('GET'), grpc-request ('GET'), and ws-request ('ws'). graphql-request radio remains using only formik.handleChange.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

A radio flip, a seedling choice,
GraphQL posts gain a louder voice,
GETs restored where needed most,
WS whispers through the host,
Small changes, smooth the requester's voice. 🎉

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main change: making POST the default HTTP method for GraphQL requests.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
packages/bruno-app/src/components/Sidebar/NewRequest/index.js (1)

340-363: Consider resetting method to GET when switching back to HTTP.

The GraphQL radio now forces POST, but the HTTP radio (lines 340-348) still uses plain formik.handleChange. If a user selects GraphQL (sets method to POST) then switches back to HTTP, the method remains POST. This asymmetry may confuse users expecting a "clean slate."

For consistency, consider applying the same pattern to the HTTP radio:

♻️ Suggested change for HTTP radio
                     <input
                       type="radio"
                       id="http-request"
                       name="requestType"
                       value="http-request"
                       checked={formik.values.requestType === 'http-request'}
-                      onChange={formik.handleChange}
+                      onChange={(e) => {
+                        formik.handleChange(e);
+                        formik.setFieldValue('requestMethod', 'GET');
+                      }}
                       data-testid="http-request"
                     />
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/bruno-app/src/components/Sidebar/NewRequest/index.js` around lines
340 - 363, The HTTP radio input (id "http-request", name "requestType")
currently only calls formik.handleChange so if the user previously picked
GraphQL (which sets requestMethod to 'POST' in the graphql radio onChange), the
method remains POST; update the HTTP radio's onChange to call
formik.handleChange(e) and also call formik.setFieldValue('requestMethod',
'GET') so switching back to HTTP resets the method to GET.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/bruno-app/src/components/Sidebar/NewRequest/index.js`:
- Around line 340-363: The HTTP radio input (id "http-request", name
"requestType") currently only calls formik.handleChange so if the user
previously picked GraphQL (which sets requestMethod to 'POST' in the graphql
radio onChange), the method remains POST; update the HTTP radio's onChange to
call formik.handleChange(e) and also call formik.setFieldValue('requestMethod',
'GET') so switching back to HTTP resets the method to GET.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 079d4406-40ed-472f-b823-b92d34645244

📥 Commits

Reviewing files that changed from the base of the PR and between 3b502fd and cdc6663.

📒 Files selected for processing (1)
  • packages/bruno-app/src/components/Sidebar/NewRequest/index.js

@pull-request-size pull-request-size bot added size/S and removed size/XS labels Apr 8, 2026
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/bruno-app/src/components/Sidebar/NewRequest/index.js`:
- Around line 264-267: The WebSocket radio currently calls formik.handleChange
directly which leaves requestMethod set to 'POST' after switching from GraphQL;
update the WebSocket radio to use handleRequestTypeChange (or create a new
onChange handler) so that when request type is 'websocket' you call
formik.setFieldValue('requestMethod', 'ws') (or set it to 'ws' explicitly) to
mirror other WS creation paths and prevent newWsRequest from inheriting an HTTP
method; locate the radio input that currently uses formik.handleChange and
replace it with handleRequestTypeChange or a small wrapper that sets
requestMethod to 'ws'.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: b3a34f5b-2c9d-42d3-9db7-2c29fb2e2bc5

📥 Commits

Reviewing files that changed from the base of the PR and between cdc6663 and 61f956a.

📒 Files selected for processing (1)
  • packages/bruno-app/src/components/Sidebar/NewRequest/index.js

Copy link
Copy Markdown
Collaborator

@sanish-bruno sanish-bruno left a comment

Choose a reason for hiding this comment

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

PR Review

Found 3 issue(s): 1 major, 1 minor, 1 nit.

Summary

  • Major: The graphql-request radio button is missing the matching onChange handler, so switching from HTTP to GraphQL does not set the method to POST — this contradicts the PR description ("Switching a request to GraphQL applies the POST method by default").
  • Minor: The initial requestMethod only accounts for the graphql-request preset; ws-request presets will incorrectly start with GET and that value is forwarded to newWsRequest.
  • Nit: getRequestType(collectionPresets) is now called twice in initialValues.

value="grpc-request"
checked={formik.values.requestType === 'grpc-request'}
onChange={formik.handleChange}
onChange={(e) => {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Bug (Major): The graphql-request radio button (new line ~362) was not updated with the same pattern applied to HTTP/gRPC/WS. It still reads:

onChange={formik.handleChange}

This means when a user starts with the default http-request type (method GET) and then clicks the GraphQL radio, requestMethod is not switched to POST. The resulting request is created as GraphQL-type with method GET, which is exactly the method/type mismatch this PR set out to prevent and contradicts the PR description ("Switching a request to GraphQL applies the POST method by default").

Note: the actual issue is on line 362 (outside any diff hunk) — attached to this added block for visibility.

Suggested fix (apply to the graphql radio on line ~362):

onChange={(e) => {
  formik.handleChange(e);
  formik.setFieldValue('requestMethod', 'POST');
}}

requestType: getRequestType(collectionPresets),
requestUrl: collectionPresets.requestUrl || '',
requestMethod: 'GET',
requestMethod: getRequestType(collectionPresets) === 'graphql-request' ? 'POST' : 'GET',
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Bug (Minor): This ternary only handles the graphql-request preset. If a collection has presets.requestType === 'ws', getRequestType returns 'ws-request', but requestMethod is initialized to 'GET'. That value is then passed through to newWsRequest in onSubmit (see line 176), producing a WebSocket request whose method is GET instead of ws — the same mismatch the new radio onChange handler for ws-request is trying to prevent when the user switches types manually.

Suggested fix:

const defaultRequestType = getRequestType(collectionPresets);
const defaultRequestMethod =
  defaultRequestType === 'graphql-request' ? 'POST'
  : defaultRequestType === 'ws-request' ? 'ws'
  : 'GET';

// ...
initialValues: {
  // ...
  requestType: defaultRequestType,
  requestMethod: defaultRequestMethod,
  // ...
}

(grpc-request does not pass requestMethod to newGrpcRequest, so it does not need special handling, but hoisting defaultRequestType also removes the double call flagged in the nit below.)

requestType: getRequestType(collectionPresets),
requestUrl: collectionPresets.requestUrl || '',
requestMethod: 'GET',
requestMethod: getRequestType(collectionPresets) === 'graphql-request' ? 'POST' : 'GET',
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nit: getRequestType(collectionPresets) is now invoked twice in initialValues (once for requestType, once inside this ternary). Hoisting it to a local const just above the useFormik call keeps the two derived values in sync and avoids re-running the switch in getRequestType for no reason.

@sanish-bruno
Copy link
Copy Markdown
Collaborator

Follow-up: requestMethod is only consumed by http-request and graphql-request

After tracing how request.method is actually used for each type, I want to refine my earlier review. Two of the three onChange handlers added in this PR (grpc-request'GET', ws-request'ws') are dead writes — nothing downstream reads the value for those types. The only handler that matters is the one for http-request, and the only omission that matters is the missing one for graphql-request.

Evidence

gRPCrequest.method is not part of the model:

  • newGrpcRequest in packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js:1759-1760 does not destructure requestMethod, and the constructed item's request object has no method field.
  • All other callers (CreateTransientRequest/index.js:162, CreateUntitledRequest/index.js:92, utils/collections/emptyStateRequest.js:40) omit it.
  • Display: Sidebar/.../RequestMethod/index.js:11-14 hardcodes 'grpc' from item.type.

WebSocketrequest.method is written on creation, then ignored everywhere:

  • newWsRequest (actions.js:1911) does set request.method = requestMethod on the in-memory item.
  • But no serializer reads it:
    • packages/bruno-filestore/src/formats/yml/items/stringifyWebsocketRequest.ts never references method.
    • parseWebsocketRequest.ts never sets method on the returned Bruno item, so a ws request loaded from disk has request.method === undefined.
    • packages/bruno-lang/v2/src/bruToJson.js:580-584 — the ws { ... } block grammar has no method field. Only get/post/etc. produce a method.
  • No runtime reads it:
    • packages/bruno-requests/src/ws/ws-client.js — no method usage.
    • packages/bruno-electron/src/ipc/network/ws-event-handlers.js — no method usage.
    • The WS client dispatches purely off the URL scheme (ws:// / wss://).
  • Display: RequestMethod/index.js:13 hardcodes 'ws' from item.type.

HTTP / GraphQL — method is consumed:

  • Serialization: stringifyHttpRequest.ts:41, stringifyGraphQLRequest.ts:40 both write method (defaulting to 'GET' / 'POST').
  • Parsing: parseHttpRequest.ts:21, parseGraphQLRequest.ts:20 both read method.
  • Network: the HTTP runtime uses request.method to issue the outbound verb.

Impact on the PR

Radio onChange sets method Method is consumed for this type Handler needed?
http-request 'GET' yes (serialized + sent) yes
graphql-request (missing) yes (serialized as method: 'POST') yes — still the real bug
grpc-request 'GET' no (not in model, not serialized, not read) no — dead write
ws-request 'ws' no (stored on in-memory item only, never serialized, never read at runtime) no — dead write

So the grpc/ws handlers aren't wrong in behavior, but they imply those types need a method, which they don't. That uniform "every radio sets the method" pattern is probably part of why the GraphQL handler got missed during review — at a glance, all four radios look structurally similar.

Retracting one piece of my earlier review

My inline comment on line 114 ("ws-request preset will incorrectly start with GET and that value is forwarded to newWsRequest") is technically correct that the value is forwarded, but the follow-on claim ("producing a WebSocket request whose method is GET instead of ws") is not actually observable — the stored method is never persisted or read for ws. So the user-facing behavior is unchanged either way. Please disregard that part of the comment. The graphql bug is still real.

Suggested minimum-correctness patch

const DEFAULT_METHOD_BY_TYPE = {
  'http-request': 'GET',
  'graphql-request': 'POST',
  // grpc-request and ws-request intentionally omitted:
  // request.method is not part of their model / not serialized / not read at runtime.
};

// initialValues
requestMethod: DEFAULT_METHOD_BY_TYPE[getRequestType(collectionPresets)] || 'GET',

// single handler, reused:
const handleTypeChange = (type) => (e) => {
  formik.handleChange(e);
  const nextMethod = DEFAULT_METHOD_BY_TYPE[type];
  if (nextMethod) formik.setFieldValue('requestMethod', nextMethod);
};

// usage:
onChange={handleTypeChange('http-request')}
onChange={handleTypeChange('graphql-request')}   // this is the currently-missing case
onChange={handleTypeChange('grpc-request')}      // no-op for method, keeps symmetry
onChange={handleTypeChange('ws-request')}        // no-op for method, keeps symmetry

That encodes the real invariant (only HTTP and GraphQL carry a method) in one place and makes the graphql omission a compile-time-obvious gap rather than a copy-paste oversight.

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