Skip to content
Merged
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
127 changes: 64 additions & 63 deletions frontend/graphql-codegen.ts
Copy link
Collaborator

@rudransh-shrivastava rudransh-shrivastava Jan 19, 2026

Choose a reason for hiding this comment

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

Let's keep it as a .ts file. I think removing the IIFE should resolve the Sonar Qube issue.

Copy link
Contributor Author

@sameersharmadev sameersharmadev Jan 19, 2026

Choose a reason for hiding this comment

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

@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

Original file line number Diff line number Diff line change
Expand Up @@ -2,76 +2,77 @@ import { CodegenConfig } from '@graphql-codegen/cli'

const PUBLIC_API_URL = process.env.PUBLIC_API_URL || 'http://localhost:8000'

export default (async (): Promise<CodegenConfig> => {
let response
let response: Response

try {
response = await fetch(`${PUBLIC_API_URL}/csrf/`, {
method: 'GET',
})
} catch {
/* eslint-disable no-console */
console.log('Failed to fetch CSRF token: make sure the backend is running.')
return
}
try {
response = await fetch(`${PUBLIC_API_URL}/csrf/`, {
method: 'GET',
})
} catch {
/* eslint-disable no-console */
console.log('Failed to fetch CSRF token: make sure the backend is running.')
process.exit(1)
}

if (!response.ok) {
throw new Error(`Failed to fetch CSRF token: ${response.status} ${response.statusText}`)
}
const csrfToken = (await response.json()).csrftoken
if (!response.ok) {
console.log(`Failed to fetch CSRF token: ${response.status} ${response.statusText}`)
process.exit(1)
}
const csrfToken = (await response.json()).csrftoken

return {
documents: ['src/**/*.{ts,tsx}', '!src/types/__generated__/**'],
generates: {
'./src/': {
config: {
avoidOptionals: {
// Use `null` for nullable fields instead of optionals
field: true,
// Allow nullable input fields to remain unspecified
inputValue: false,
},
defaultScalarType: 'any',
// Apollo Client always includes `__typename` fields
nonOptionalTypename: true,
// Apollo Client doesn't add the `__typename` field to root types so
// don't generate a type for the `__typename` for root operation types.
skipTypeNameForRoot: true,
},
// Order of plugins matter
plugins: ['typescript-operations', 'typed-document-node'],
preset: 'near-operation-file',
presetConfig: {
// This should be the file generated by the "typescript" plugin above,
// relative to the directory specified for this configuration
baseTypesPath: './types/__generated__/graphql.ts',
// Relative to the source files
folder: '../../types/__generated__',
const config: CodegenConfig = {
documents: ['src/**/*.{ts,tsx}', '!src/types/__generated__/**'],
generates: {
'./src/': {
config: {
avoidOptionals: {
// Use `null` for nullable fields instead of optionals
field: true,
// Allow nullable input fields to remain unspecified
inputValue: false,
},
defaultScalarType: 'any',
// Apollo Client always includes `__typename` fields
nonOptionalTypename: true,
// Apollo Client doesn't add the `__typename` field to root types so
// don't generate a type for the `__typename` for root operation types.
skipTypeNameForRoot: true,
},
'./src/types/__generated__/graphql.ts': {
config: {
scalars: {
// eslint-disable-next-line @typescript-eslint/naming-convention
Date: 'string | number',
// eslint-disable-next-line @typescript-eslint/naming-convention
DateTime: 'string | number',
JSON: 'Record<string, unknown>',
},
},
plugins: ['typescript'],
// Order of plugins matter
plugins: ['typescript-operations', 'typed-document-node'],
preset: 'near-operation-file',
presetConfig: {
// This should be the file generated by the "typescript" plugin above,
// relative to the directory specified for this configuration
baseTypesPath: './types/__generated__/graphql.ts',
// Relative to the source files
folder: '../../types/__generated__',
},
},
// Don't exit with non-zero status when there are no documents
ignoreNoDocuments: true,
overwrite: true,
schema: {
[`${PUBLIC_API_URL}/graphql/`]: {
headers: {
Cookie: `csrftoken=${csrfToken}`,
'X-CSRFToken': csrfToken,
'./src/types/__generated__/graphql.ts': {
config: {
scalars: {
// eslint-disable-next-line @typescript-eslint/naming-convention
Date: 'string | number',
// eslint-disable-next-line @typescript-eslint/naming-convention
DateTime: 'string | number',
JSON: 'Record<string, unknown>',
},
},
plugins: ['typescript'],
},
}
})()
},
// Don't exit with non-zero status when there are no documents
ignoreNoDocuments: true,
overwrite: true,
schema: {
[`${PUBLIC_API_URL}/graphql/`]: {
headers: {
Cookie: `csrftoken=${csrfToken}`,
'X-CSRFToken': csrfToken,
},
},
},
}

export default config
Loading