use top-level await instead of async IIFE in graphql-codegen.ts#3398
use top-level await instead of async IIFE in graphql-codegen.ts#3398arkid15r merged 3 commits intoOWASP:mainfrom
Conversation
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings. WalkthroughReplaces an async IIFE export in Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested reviewers
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In `@frontend/graphql-codegen.ts`:
- Around line 5-15: Replace the top-level await fetch with an exported async
function: wrap the CSRF fetch logic inside "export default async function()"
(e.g., perform "const response = await fetch(`${PUBLIC_API_URL}/csrf/`, {
method: 'GET' })" inside that function), handle errors inside the function (log
the error and throw or return a rejected Promise instead of calling
process.exit), and return whatever configuration/value the GraphQL Codegen
consumer expects; update any references to response to use the function-local
variable (this file's top-level fetch and process.exit usage should be removed
and replaced by the async export).
- Around line 11-19: The catch block currently logs and calls process.exit(1)
for network errors while the response.ok branch throws an Error, causing
inconsistent behaviour; change the catch to accept the error (e.g., catch (err))
and rethrow a normalized Error (include the original err message) instead of
calling process.exit, so both network and HTTP failures throw an Error (keep the
existing throw in the response.ok branch) and let the top-level handler decide
exit behavior; update the catch to reference the same failure message format
used in the response.ok check and include the original error details.
✅ Actions performedFull review triggered. |
|
@coderabbitai full review |
✅ Actions performedFull review triggered. |
rudransh-shrivastava
left a comment
There was a problem hiding this comment.
Hey, nice work!
Just a small change:
There was a problem hiding this comment.
Let's keep it as a .ts file. I think removing the IIFE should resolve the Sonar Qube issue.
There was a problem hiding this comment.
@rudransh-shrivastava Okay, I've reverted back to .ts now 👍 , ready for review, but please take the look at Coderabbit suggestion, it seems to advise aaginst using top level await
3f39fe7 to
cf7a8a6
Compare
✅ Actions performedFull review triggered. |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@frontend/graphql-codegen.ts`:
- Around line 5-21: Replace the top-level await fetch logic with an exported
async factory function: wrap the existing fetch/response handling (the try/catch
around fetch and the response.ok check that produces csrfToken) inside export
default async function() and return the GraphQL Codegen config object from that
function (so the csrfToken variable is scoped inside the function and used to
build the returned config). Ensure you preserve the same error handling around
response and use (await response.json()).csrftoken to set csrfToken before
returning the config.
|
rudransh-shrivastava
left a comment
There was a problem hiding this comment.
Looks good to me!
kasya
left a comment
There was a problem hiding this comment.
@sameersharmadev nice work! 👍🏼



Proposed change
Resolves #3087

Replaces the async IIFE with top-level await in frontend/graphql-codegen.ts for improved readability and maintainability.
Verified by
make graphql-codegenPlease take a look at this suggestion before merging
Checklist
make check-testlocally: all warnings addressed, tests passed