Skip to content

fix(frontend): prefer top-level await over async IIFE in graphql-codegen config#3399

Closed
SuyashJain17 wants to merge 3 commits intoOWASP:mainfrom
SuyashJain17:fix/graphql-codegen-top-level-await
Closed

fix(frontend): prefer top-level await over async IIFE in graphql-codegen config#3399
SuyashJain17 wants to merge 3 commits intoOWASP:mainfrom
SuyashJain17:fix/graphql-codegen-top-level-await

Conversation

@SuyashJain17
Copy link
Contributor

@SuyashJain17 SuyashJain17 commented Jan 18, 2026

Proposed change

Resolves #3087

This PR refactors frontend/graphql-codegen.ts to address SonarCloud rule
typescript:S7785 by replacing the async IIFE pattern with top-level await.

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

  • Required: I followed the contributing workflow
  • Required: I verified that my code works as intended and resolves the issue as described
  • Required: I ran make check-test locally: all warnings addressed, tests passed
  • I used AI for code, documentation, tests, or communication related to this PR

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 18, 2026

Walkthrough

Replaces an async IIFE default export in frontend/graphql-codegen.ts with a named async function getCodegenConfig exported as default; CSRF fetch failures now throw Errors (including status/statusText) instead of returning early; removed immediate invocation and adjusted error propagation.

Changes

Cohort / File(s) Summary
GraphQL codegen entry
frontend/graphql-codegen.ts
Replaced exported async IIFE with a named async function getCodegenConfig exported as default; added explicit error throwing on CSRF fetch failure and non-OK responses; removed immediate invocation so function is no longer invoked at module load.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Suggested reviewers

  • kasya
  • arkid15r
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and specifically describes the main change: refactoring from async IIFE to top-level await pattern in graphql-codegen configuration.
Linked Issues check ✅ Passed The PR successfully addresses issue #3087 by replacing the async IIFE export pattern with a named async function declaration, improving code readability and aligning with modern ES module standards.
Out of Scope Changes check ✅ Passed All changes are directly scoped to the stated objective of refactoring the async IIFE pattern; no unrelated modifications were introduced.
Description check ✅ Passed The pull request description clearly relates to the changeset, explaining the refactor from async IIFE to top-level await in graphql-codegen.ts to resolve SonarCloud rule typescript:S7785.

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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
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: 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.

coderabbitai[bot]
coderabbitai bot previously approved these changes Jan 18, 2026
@sonarqubecloud
Copy link

Copy link
Collaborator

@arkid15r arkid15r left a comment

Choose a reason for hiding this comment

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

Did you even try to run it when marked
Required: I verified that my code works as intended and resolves the issue as described ?

@arkid15r
Copy link
Collaborator

#3398 looks more promising. closing this.

@arkid15r arkid15r closed this Jan 18, 2026
@SuyashJain17 SuyashJain17 deleted the fix/graphql-codegen-top-level-await branch January 18, 2026 18:47
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.

Prefer top-level await instead of async IIFE (Sonar S7785)

2 participants

Comments