dotansimha / dotansimha/graphql-code-generator-community

[near-operation-file] typesSuffix from baseTypesPath not taken into account.

Open
#125 4 comments 1 reaction 0 assignees View on GitHub
Dominant language
TypeScript
Stars
137
Forks
195
Avg merge
6h 20m
Merged PRs (30d)
16

Description

**Describe the bug**
Given you generate a types file with `typesSuffix` and use that file as `baseTypesPath` for the `near-operation-file` preset. Then it doesn't add the `typesSuffix` to the types imported from the original types file, resulting in an error.

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

[Code sandbox](https://codesandbox.io/s/friendly-currying-5hv00?file=/document.generated.ts)

Notice the error on line 40 in `document.generated.ts`.
1. My GraphQL schema:

```graphql
type Query {
user(id: ID!): User!
}

type User {
id: ID!
username: String!
email: String!
}
```

2. My GraphQL operations:

```graphql
query user {
user(id: 1) {
id
username
email
}
}
```

3. My `codegen.yml` config file:

```yml
schema: schema.graphql
documents: document.graphql
generates:
src/types.ts:
plugins:
- typescript
- typescript-operations
config:
typesSuffix: DTO
src/:
preset: near-operation-file
presetConfig:
baseTypesPath: types.ts
plugins:
- typescript
- typescript-operations
```

**Expected behavior**
Expected `document.generated.ts` to use the `typesSuffix` from `types.ts` when importing types from `types.ts`:
```typescript
import * as Types from './src/types';
Types.UserDTO
```
instead of:
```typescript
import * as Types from './src/types;
Types.User // Namespace '/src/types' has no exported member 'User'
```

**Environment:**

- OS: MacOS 11.3
- @graphql-codegen/add: 2.0.2,
- @graphql-codegen/cli: 1.21.4,
- @graphql-codegen/near-operation-file-preset: 1.18.0,
- @graphql-codegen/typescript: 1.22.0,
- @graphql-codegen/typescript-operations: 1.17.16,
- NodeJS: 14

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.