Skip to content

How to use both near-operation-file-preset and import-types-preset with typescript and react #3272

@millievn

Description

@millievn

I want to generate typing declear once in single file and other files just import its type from it when i start working with react,typescript and graphql

Although near-operation-file-preset generates a file per each operation file,every file repeats typing declear. And import-types-preset helps import types from file but it can not generate files like near-operation-file-preset .
One more thing is that near-operation-file-preset contains both types and components ,while splited to single file may be better i think.

What I want may look like this:

graphql
|--test1.graphql  // query and mutations
|--test1.generated.tsx  // components and hooks without types
|--test2.graphql  
|--test2.generated.tsx
|--types.ts   // types

But I find it's hard to work with both.

overwrite: true
schema: './schema.graphql'
documents: 'src/**/*.graphql'
generates:
  src/graphql/types.tsx:
    - typescript
  src/graphql/:
    preset:
      # near-operation-file
      import-types
    presetConfig:
      # extension: .generated.tsx
      # baseTypesPath: types.ts
      typesPath: types.ts
    plugins:
      - time:
        format: DD.MM.YY
        message: 'The file generated in: '
      - typescript
      - typescript-operations
      - typescript-react-apollo
    config:
      withHOC: true
      withHooks: true
      skipTypename: true

Does anyone can help me ?
Thanks a lot!

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/enhancementNew feature or requestpresetsRelated to Codegen presets

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions