Graphql-code-generator: Unused imports in generated files with typescript-apollo-angular ^1.10.0

Created on 8 Jan 2020  路  4Comments  路  Source: dotansimha/graphql-code-generator

Describe the bug

Not really a bug, but an inconvenience that still prevents me from upgrading.
From versions ^1.10.0, I get this line at the top of my file:

import { MutationOptionsAlone, QueryOptionsAlone, SubscriptionOptionsAlone, WatchQueryOptionsAlone } from 'apollo-angular/types';

None of those imports are being used in the file. This conflicts with TypeScript rule noUnusedLocals (I think), which causes this error:

../lib.browser.{redacted}/graphql.generated.ts:8:1 - error TS6192: All imports in import declaration are unused.

8 import { MutationOptionsAlone, QueryOptionsAlone, SubscriptionOptionsAlone, WatchQueryOptionsAlone } from 'apollo-angular/types';
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This is a similar problem as in #1917, #1841, and probably more.

bug plugins waiting-for-release

Most helpful comment

All 4 comments

I think this was introduced here: https://github.com/dotansimha/graphql-code-generator/pull/3008.

It seems like the new imports here should only be added if sdkClass is true. It should probably also only import the types that are actually used, e.g. if you have sdkClass true but don't have any subscriptions, the current code will still import SubscriptionOptionsAlone and cause this error.

Thanks, @dotansimha! I tried your fix and it worked for me :thumbsup:

Fixed in v1.12.0

Was this page helpful?
0 / 5 - 0 ratings