dotansimha / dotansimha/graphql-code-generator

import-types-preset prefixes all types (react-apollo)

Open
#3,105 1 comment 3 reactions 0 assignees View on GitHub
kind/enhancement presets
Dominant language
TypeScript
Stars
11.3k
Forks
1.4k
Avg merge
1d 1h
Merged PRs (30d)
23

Description

**Describe the bug**

It clearly seems to be related to https://github.com/dotansimha/graphql-code-generator/issues/2742. But as the OP says it should be resolved, I made the decision to create a new issue.

When I migrate from 1.7.0 to 1.9.1, all types in the generated graphql.tsx are prefixed with 'Types' (default value of presetConfig.importTypesNamespace).

Before, only my own types were prefixed but not the generated types (**Query, **QueryVariables).

**To Reproduce**
Steps to reproduce the behavior:

1. My GraphQL schema:

```graphql
type FinancialPeriod {
id: ID!
startDate: String!
endDate: String!
duration: Int!
incomeStatement: IncomeStatement!
tva: Tva!
}
```

2. My GraphQL operations:

```graphql
query FinancialPeriods($structureId: ID!) {
financialPeriods(structureId: $structureId) {
...financialPeriodFields
}
}
```

3. My `codegen.yml` config file:

```yml
overwrite: true
schema: '../gateway/schema/schema.graphql'

react-plugins: &react-plugins
- add: |
/* tslint:disable */
/* eslint-disable */
- typescript-operations
- typescript-react-apollo

config:
scalars:
JSON: '{ [key: string]: any }'
generates:
packages/types/src/generated/types.ts:
plugins:
- typescript
packages/app/src/generated/graphql.tsx:
documents: packages/app/src/**/*.graphql
config:
withHooks: true
withMutationOptionsType: true
withComponent: false
withHOC: false
preset: import-types
presetConfig:
typesPath: '@fa-metier/types'
plugins: *react-plugins
packages/admin/src/generated/graphql.tsx:
documents: packages/admin/src/**/*.graphql
config:
withHooks: true
withMutationOptionsType: true
withComponent: false
withHOC: false
preset: import-types
presetConfig:
typesPath: '@fa-metier/types'
plugins: *react-plugins
```

**Expected behavior**

**Environment:**

- OS:
- `@graphql-codegen/...`:
- NodeJS:

**Additional context**

"@graphql-codegen/cli": "^1.9.1",

"@graphql-codegen/plugin-helpers": "^1.9.1",

"@graphql-codegen/import-types-preset": "^1.9.1",

"@graphql-codegen/introspection": "1.9.1",

"@graphql-codegen/near-operation-file-preset": "^1.9.1",

"@graphql-codegen/typescript": "1.9.1",

"@graphql-codegen/typescript-operations": "1.9.1",

"@graphql-codegen/typescript-react-apollo": "1.9.1",

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.