dotansimha / dotansimha/graphql-code-generator

enumValues defined as objects create a `null` ResolverType in @graphql-codegen/visitor-plugin-common 5.6.0

Open
#10,204 0 comments 0 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/visitor-plugin-common

### Describe the bug

Using config for enums like:

```
enumValues: {
ReviewStatus: {
{
PREVIEW: 'preview',
FULL: 'full',
DISCARDED: 'discarded',
}
}
}
```

generates a resolver type for the enum of type `null`. E.g.

```typescript
// ...
export type ResolverTypes = {
// ...
ReviewStatus: null;
// ...
}
```

I suspect [this commit](https://github.com/dotansimha/graphql-code-generator/commit/09cb7d3335c3e5416c2658bced1735395c2e3524) is the culprit and that the logic should probably be something like

```typescript
const isExternalFile = !!this.config.enumValues[typeName].sourceFile;
prev[typeName] = isExternalFile
? this.convertName(this.config.enumValues[typeName].typeIdentifier, {
useTypesPrefix: false,
useTypesSuffix: false,
})
: (this.config.enumValues[typeName].sourceIdentifier || this.convertName(this.config.enumValues[typeName].typeIdentifier));
```

### Your Example Website or App

none

### Steps to Reproduce the Bug or Issue

See description above

### Expected behavior

The enum resolverType should be the enum, and not null.

### Screenshots or Videos

_No response_

### Platform

- OS: macOS
- NodeJS: 22
- `@graphql-codegen/visitor-plugin-common` version(s): 5.6.0

### Codegen Config File

_No response_

### Additional context

_No response_

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.