dotansimha / dotansimha/graphql-code-generator-community
Generated files fail the angular es-lint rule - angular-eslint/prefer-inject
- Dominant language
- TypeScript
- Stars
- 137
- Forks
- 195
- Avg merge
- 6h 20m
- Merged PRs (30d)
- 16
Description
### Which packages are impacted by your issue?
@graphql-codegen/typescript-apollo-angular
### Describe the bug
Latest default es-lint rules for angular push for the use of `inject` over constructor DI. Angular do have a migration script for this `ng generate @angular/core:inject`. The generated files from the codegen script use constructor injection over `inject()`.
**This is applicable for angular apps version 14+ only**
Temporary workaround is to simply disable this for our generated `.ts` files with
```json
{
"files": [
"**/__generated__/**/*.ts"
],
"rules": {
"@angular-eslint/prefer-inject": "off"
}
}
```
**Fix**
Take the current generated ts file format:
```ts
constructor(apollo: Apollo.Apollo) {
super(apollo)
}
```
and make it more 'angular.'
```ts
import { Injectable, inject } from "@angular/core"
{...}
constructor() {
const apollo = inject(Apollo.Apollo);
super(apollo)
}
```
### Your Example Website or App
//
### Steps to Reproduce the Bug or Issue
1. Run codegen on any graphql file
2. Lint failing file generated
### Expected behavior
```ts
constructor() {
const apollo = inject(Apollo.Apollo);
super(apollo)
}
```
### Screenshots or Videos
_No response_
### Platform
- OS: MacOS
- NodeJS: 22
- `graphql` version: 16.10.*
- `@graphql-codegen/*` version(s): 4.0.*
### Codegen Config File
_No response_
### Additional context
_No response_
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.