Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unused imports are generated when using fragment #2416

Open
mizdra opened this issue Aug 21, 2019 · 4 comments
Open

Unused imports are generated when using fragment #2416

mizdra opened this issue Aug 21, 2019 · 4 comments
Labels

Comments

@mizdra
Copy link
Contributor

mizdra commented Aug 21, 2019

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

@dotansimha
Copy link
Owner

Fixed and available as alpha 1.6.2-alpha-aeb3f880.46, @mizdra can you please try it?

@dotansimha dotansimha added the waiting-for-release Fixed/resolved, and waiting for the next stable release label Aug 29, 2019
@dotansimha
Copy link
Owner

Fixed in 1.7.0

@mizdra
Copy link
Contributor Author

mizdra commented Sep 1, 2019

Using 1.7.0, my problem was resolved. Thank you!

@mizdra
Copy link
Contributor Author

mizdra commented Oct 4, 2019

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

@dotansimha dotansimha reopened this Oct 10, 2019
@dotansimha dotansimha removed the waiting-for-release Fixed/resolved, and waiting for the next stable release label Oct 10, 2019
@dotansimha dotansimha removed the bug label Jun 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants