Graphql-code-generator: Unused imports are generated when using fragment

Created on 21 Aug 2019  路  4Comments  路  Source: dotansimha/graphql-code-generator

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
  1. My GraphQL schema:
type Query {
  articles: [Article!]!
}
type Article {
  id: ID!
  title: String!
  body: String!
}
  1. My GraphQL operations:
// 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}
`
  1. My 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:

  • 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

bug plugins

Most helpful comment

Upgrading @graphql-codegen/* from v1.7.0 to v1.8.0, this problem occurs again. Can you check it?

All 4 comments

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?

Was this page helpful?
0 / 5 - 0 ratings