dotansimha / dotansimha/graphql-code-generator
Unused imports are generated when using fragment
- Dominant language
- TypeScript
- Stars
- 11.3k
- Forks
- 1.4k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 23
Description
**Describe the bug**
`tsc --noUnusedLocals` warn generated files because the files include unused imports when using fragment.
**To Reproduce**
Steps to reproduce the behavior:
- Sample repository: https://github.com/mizdra/graphql-code-generator-sample
```
$ git clone https://github.com/mizdra/graphql-code-generator-sample.git
$ cd graphql-code-generator-sample
$ yarn install
$ yarn run build:graphql
$ yarn run check:typecheck # tsc --noUnusedLocals
```
1. My GraphQL schema:
```graphql
type Query {
articles: [Article!]!
}
type Article {
id: ID!
title: String!
body: String!
}
```
2. My GraphQL operations:
```tsx
// ArticleListItem.tsx
export function ArticleListItem() { ... }
ArticleListItem.Fragment = gql`
fragment SimpleArticle on Article {
title
body
}
`
```
```tsx
// ArticleList.tsx
import { ArticleListItem } from './ArticleListItem'
const GET_ARTICLES = gql`
query GetArticles {
articles {
...SimpleArticle
}
}
${ArticleListItem.Fragment}
`
```
3. My `codegen.yml` config file:
```yml
overwrite: true
schema: schema.graphql
generates:
src/types.generated.ts:
- typescript
src/:
documents: 'src/**/*.{ts,tsx}'
preset: near-operation-file
presetConfig:
extension: .generated.tsx
baseTypesPath: types.generated.ts
plugins:
- typescript-operations
```
**Expected behavior**
Unused imports should be removed from generated files.
**Environment:**
- OS: macOS Mojave 10.14.6
- `@graphql-codegen/cli`: 1.6.1
- `@graphql-codegen/near-operation-file-preset`: 1.6.1
- `@graphql-codegen/typescript`: 1.6.1
- `@graphql-codegen/typescript-operations`: 1.6.1
- `typescript`: 3.5.3
- NodeJS: 12.4.0
**Additional context**
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.