dotansimha / dotansimha/graphql-code-generator

typescript-resolvers mappers do not take emitLegacyCommonJSImports: false into account

Open
#9,277 3 comments 3 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
11.3k
Forks
1.4k
Avg merge
1d 1h
Merged PRs (30d)
23

Description

### Which packages are impacted by your issue?

@graphql-codegen/typescript-resolvers

### Describe the bug

Once generating ESM compatible output, imports in Typescript are needed to resolve to .js.
Using `@graphql-codegen/typescript-resolvers` with `mappers` doesn't write the imports correctly, even having `emitLegacyCommonJSImports: false` configured

### Your Example Website or App

https://the-guild.dev/graphql/codegen

### Steps to Reproduce the Bug or Issue

1. Go to https://the-guild.dev/graphql/codegen
2. add this codegen.yml:
```yml
generates:
resolvers.ts:
config:
emitLegacyCommonJSImports: false
mappers:
User: ./models#UserDbObject
Chat: ./models#ChatModel
plugins:
- typescript
- typescript-resolvers
```
3. see the resolvers.ts being generated with this import:
```typescript
import { UserDbObject, ChatModel } from './models';
```

### Expected behavior

resolvers.ts shall be generated with this import:
```typescript
import { UserDbObject, ChatModel } from './models.js';
```

### Screenshots or Videos

_No response_

### Platform

- OS: Linux
- NodeJS: 18.15.0
- `graphql` version: 16.6.0
- `@graphql-codegen/typescript` version: 3.0.3
- `@graphql-codegen/typescript-resolvers` version: 3.2.0

### Codegen Config File

_No response_

### Additional context

Workaround:
```yml
generates:
resolvers.ts:
config:
emitLegacyCommonJSImports: false
mappers:
User: ./models.js#UserDbObject
Chat: ./models.js#ChatModel
plugins:
- typescript
- typescript-resolvers
```

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.