graphql-code-generator-community icon indicating copy to clipboard operation
graphql-code-generator-community copied to clipboard

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

Open pierre-lucas40 opened this issue 5 years ago • 6 comments

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:

  • OS: macOS 11.0.1
  • NodeJS: 14.15.1
  • "@graphql-codegen/fragment-matcher": "2.0.1", "@graphql-codegen/import-types-preset": "1.18.1", "@graphql-codegen/introspection": "1.18.1", "@graphql-codegen/typescript": "1.19.0", "@graphql-codegen/typescript-graphql-files-modules": "1.18.1", "@graphql-codegen/typescript-graphql-request": "2.0.3", "@graphql-codegen/typescript-operations": "1.17.12", "@graphql-codegen/typescript-react-apollo": "2.2.1":

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 !

pierre-lucas40 avatar Dec 17 '20 19:12 pierre-lucas40

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

lanwin avatar Dec 18 '20 08:12 lanwin

@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?

dotansimha avatar Dec 23 '20 14:12 dotansimha

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 👍

lanwin avatar Dec 23 '20 15:12 lanwin

Any updates on this?

jtieu-r7 avatar Sep 07 '21 22:09 jtieu-r7

Still needing this behavior!!!! Any updates?

laspencer91 avatar Mar 12 '24 22:03 laspencer91

Need this too, please give us an update.

pjean-dev avatar Jan 03 '25 08:01 pjean-dev