Graphql-code-generator: Unused imports generated

Created on 9 May 2019  路  4Comments  路  Source: dotansimha/graphql-code-generator

Describe the bug

My team is currently generating hooks with no components nor HOCs when no mutations or subscriptions are implemented. We have found an issue where import * as ReactApollo from 'react-apollo' is generated in the file but is not being used, therefore gets flagged by Typescript noUnusedLocals

To Reproduce
Steps to reproduce the behavior:

  • Have 1 or multiple queries but no mutations or subscriptions
  • Only generate Hooks
  1. My codegen.yml config file:
documents: src/apollo/**/!(schema).graphql
overwrite: true
generates:
  src/apollo/index.tsx:
    schema: src/apollo/**/schema.graphql
    plugins:
      - add: /* THIS IS A GENERATED FILE - DO NOT MODIFY */
      - add: /* eslint-disable */
      - typescript
      - typescript-operations
      - typescript-react-apollo
    config:
      gqlImport: graphql-tag.macro
      withComponent: false
      withHooks: true
      withHOC: false

Expected behavior
Unused imports should not be generated.

Environment:

  • OS: MacOS Mojave 10.14.2
  • @graphql-codegen/...: 1.1.3
  • NodeJS: v10.15.2
bug plugins waiting-for-release

All 4 comments

Hi @bpallares ! Thank you for reporting this.

It seems like you are getting this error because of TypeScript configuration, and it seems like it's not possible to ignore specific files (https://github.com/Microsoft/TypeScript/issues/12913).

@ardatan can you please take a look and see why those imports are being generated?

@bpallares Could you confirm if it works correctly with the following canary version?

@graphql-codegen/typescript-react-apollo => 1.1.4-alpha-de90829b.24+de90829b

@ardatan It works correctly with the canary version provided!

Fixed in 1.2.0.

Was this page helpful?
0 / 5 - 0 ratings