fix(frontend): prefer top-level await over async IIFE in graphql-codegen config#3399
fix(frontend): prefer top-level await over async IIFE in graphql-codegen config#3399SuyashJain17 wants to merge 3 commits intoOWASP:mainfrom
Conversation
WalkthroughReplaces an async IIFE default export in Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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 71-74: The catch block that logs "Failed to fetch CSRF token..."
leaves the exported config undefined; modify the catch inside the async
initialization so it re-throws the caught error (or throw a new Error that wraps
the original) instead of only console.logging, ensuring the failure surfaces
rather than exporting undefined from the module (look for the catch near the
CSRF fetch and the exported config variable).
- Around line 5-8: Top-level await in the current module (the use of await when
fetching CSRF and the top-level variable config) breaks graphql-codegen 6.1.1;
refactor by replacing the module-level await and variable with an exported async
function (export default async function()) that performs the fetch to
`${PUBLIC_API_URL}/csrf/`, builds and returns the CodegenConfig object (do not
return undefined on fetch failure—either throw or return a sane default config),
and move all logic currently in the top-level try/catch into that function so
graphql-codegen's jiti loader can evaluate it correctly.
|
arkid15r
left a comment
There was a problem hiding this comment.
Did you even try to run it when marked
Required: I verified that my code works as intended and resolves the issue as described ?
|
#3398 looks more promising. closing this. |



Proposed change
Resolves #3087
This PR refactors
frontend/graphql-codegen.tsto address SonarCloud ruletypescript:S7785by replacing the async IIFE pattern with top-levelawait.The change improves readability and aligns the configuration with modern ES
module standards, while avoiding unnecessary async wrapper functions.
This is a refactor-only change; no functional or behavioral changes are intended.
Checklist
make check-testlocally: all warnings addressed, tests passed