Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions packages/bruno-app/src/components/Sidebar/NewRequest/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ const NewRequest = ({ collectionUid, item, isEphemeral, onClose }) => {
filename: '',
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.)

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.

curlCommand: ''
},
validationSchema: Yup.object({
Expand Down Expand Up @@ -343,7 +343,10 @@ const NewRequest = ({ collectionUid, item, isEphemeral, onClose }) => {
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"
/>
<label htmlFor="http-request" className="ml-1 cursor-pointer select-none">
Expand Down Expand Up @@ -374,7 +377,10 @@ const NewRequest = ({ collectionUid, item, isEphemeral, onClose }) => {
name="requestType"
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');
}}

formik.handleChange(e);
formik.setFieldValue('requestMethod', 'GET');
}}
data-testid="grpc-request"
/>
<label htmlFor="grpc-request" className="ml-1 cursor-pointer select-none">
Expand All @@ -389,7 +395,10 @@ const NewRequest = ({ collectionUid, item, isEphemeral, onClose }) => {
name="requestType"
value="ws-request"
checked={formik.values.requestType === 'ws-request'}
onChange={formik.handleChange}
onChange={(e) => {
formik.handleChange(e);
formik.setFieldValue('requestMethod', 'ws');
}}
data-testid="ws-request"
/>
<label htmlFor="ws-request" className="ml-1 cursor-pointer select-none">
Expand Down
Loading