Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enum containing space incorrectly generates GraphQL type #3993

Open
2 tasks done
sdemjanenko opened this issue Mar 31, 2024 · 0 comments
Open
2 tasks done

Enum containing space incorrectly generates GraphQL type #3993

sdemjanenko opened this issue Mar 31, 2024 · 0 comments

Comments

@sdemjanenko
Copy link

I recently switched a string field which was behaving as an enum to an actual enum type (hence why there are spaces, as I didn't change the value stored).

type ApplicationStatusEnum string

const (
	ApplicationStatusInProgress     ApplicationStatusEnum = "In progress"
	ApplicationStatusAccountCreated ApplicationStatusEnum = "Account created"
)

field.Enum("status").
	Values(
		string(ApplicationStatusInProgress),
		string(ApplicationStatusAccountCreated),
	).
	Default(string(ApplicationStatusInProgress)),

This results in the ent.graphql content

enum ApplicationStatus @goModel(model: ".../ent/application.Status") {
  In progress
  Account created
}

when I regenerated my GraphQL schema types on the frontend (using https://github.com/dotansimha/graphql-code-generator), I saw this change

/** ApplicationStatus is enum for the field status */
export enum ApplicationStatus {
	Account = 'Account',
	In = 'In',
	Created = 'created',
	Progress = 'progress'
}

It appears that the space separation is leading to 4 values of the enum when there should be 2. From what I can tell, the enum ApplicationStatus @goModel is wrong (in that it shouldn't have spaces).

  • The issue is present in the latest release.
  • I have searched the issues of this repository and believe that this is not a duplicate.

My Environment 🌎

Tech Version
Go 1.22.?
Ent 0.13.1
Database Postgres
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant