dotansimha / graphql-code-generator-community

MIT License
119 stars 157 forks source link

Preset import-types not importing typescript-operations in all my files #103

Open pierre-lucas40 opened 3 years ago

pierre-lucas40 commented 3 years ago

Describe the bug I have a monorepo with a root codegen.yml including this:

generates:
  packages/api/src/types/common.ts:
    plugins:
      - 'typescript'
      - 'typescript-operations'
  packages/api/src/types/models.ts:
    preset: import-types
    presetConfig:
      typesPath: './common'
    plugins:
      - 'typescript-react-apollo'
      - 'fragment-matcher'
  packages/api/src/types/auth-models.ts:
    preset: import-types
    presetConfig:
      typesPath: './common'
    plugins:
      - 'typescript-graphql-request'
      - 'fragment-matcher'

In packages/api/src/types/models.ts, the operation's types are well imported from './common' (Types.InterfaceX) But in packages/api/src/types/auth-models.ts, the operation's types are not prefixed by 'Types.' so it doesn't find them... Why is there a difference between those 2 files please ? (If I only put the typescript's pluggin in the common file and let the typescript-operations in the specifics files, the types are well imported from common in both files...)

goodfile badfile

To Reproduce Steps to reproduce the behavior:

Generate types with 'typescript' and 'typescript-operations' pluggins in one file. Generate types with 'typescript-graphql-request' pluggin using "preset: import-types" and "presetConfig: typesPath: './path/to/common/file'"

Expected behavior To have my 'typescript-operations' types imported from my common file in both specific files ('Types.CommonType' instead of 'CommonType').

Environment:

Additional information I also tried to add config 'importOperationTypesFrom' for @graphql-codegen/typescript-graphql-request but that didn't generate anything different...

Thank you very much !

lanwin commented 3 years ago

I felt onto the same problem and looked up importOperationTypesFrom in the codebase. It seems typescript-graphql-request did not even use it. But I see usage in vue-apollo, react-apollo, react-query

dotansimha commented 3 years ago

@lanwin is right. Not all plugins support all flags and all combinations with presets. We are trying to track those and fix, so we might found another one :) I guess in this case, it's an issue only with typescript-graphql-request plugin, right?

lanwin commented 3 years ago

I guess in this case, it's an issue only with typescript-graphql-request plugin, right?

I dont use Preset but I would bet its the same issue. So 👍

jtieu-r7 commented 3 years ago

Any updates on this?

laspencer91 commented 8 months ago

Still needing this behavior!!!! Any updates?