Describe the bug
tsc --noUnusedLocals warn generated files because the files include unused imports when using fragment.
To Reproduce
Steps to reproduce the behavior:
$ 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
type Query {
articles: [Article!]!
}
type Article {
id: ID!
title: String!
body: String!
}
// ArticleListItem.tsx
export function ArticleListItem() { ... }
ArticleListItem.Fragment = gql`
fragment SimpleArticle on Article {
title
body
}
`
// ArticleList.tsx
import { ArticleListItem } from './ArticleListItem'
const GET_ARTICLES = gql`
query GetArticles {
articles {
...SimpleArticle
}
}
${ArticleListItem.Fragment}
`
codegen.yml config file: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:
@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.1typescript: 3.5.3Additional context
Fixed and available as alpha 1.6.2-alpha-aeb3f880.46, @mizdra can you please try it?
Fixed in 1.7.0
Using 1.7.0, my problem was resolved. Thank you!
Upgrading @graphql-codegen/* from v1.7.0 to v1.8.0, this problem occurs again. Can you check it?
Most helpful comment
Upgrading
@graphql-codegen/*from v1.7.0 to v1.8.0, this problem occurs again. Can you check it?