Graphql-code-generator: [near-operations-file] Import of main types sometimes added to queries where it isn't needed

Created on 10 Oct 2019  路  9Comments  路  Source: dotansimha/graphql-code-generator

Relates to #2137
This problem seems to be back in 1.8.1, or at least something related.

query {
  user {
    ...UserFragment
  }
}

Results in the Types import being added, even though it isn't used.

query {
  user {
    id
    ...UserFragment
  }
}

Also adds the Types import, but uses it.

This is problematic when typescript is configured to error on unused imports.

bug needs reproduction plugins

All 9 comments

Would love to see this solved, as we cannot use this preset with noUnusedLocals: true in tsconfig.json. Removing preResolveTypes: true also works.

Workaround I landed on (inspired by OP) is to duplicate a field from the fragment that uses Types (something optional, meaning Types.Maybe is used).

It's a bit tricky because it effects other use-cases. We are trying to find the actual specific use-cases that causes that.
@SimenB @mvestergaard can you please share a reproduction?

This was "fixed" for us by #4194 injecting usage of Types.Exact

This resurfaced for us, btw. We're back to adding dummy queries to work around it. I'll try to put together a reproduction

@SimenB sure, waiting for a reproduction. Thanks!

@dotansimha https://github.com/SimenB/codegen-extra-imports. Might be possible to reduce even more, but this is at least somewhat minimal

@dotansimha reopen this, or should I file a new issue?

@dotansimha reopen this, or should I file a new issue?

New issue :)

5094

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dotansimha picture dotansimha  路  3Comments

iamdanthedev picture iamdanthedev  路  3Comments

jagregory picture jagregory  路  3Comments

leebenson picture leebenson  路  3Comments

NickClark picture NickClark  路  3Comments