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

[RFC] Import enums in the browser #43

Closed
JustinVoitel opened this issue Jan 23, 2021 · 2 comments
Closed

[RFC] Import enums in the browser #43

JustinVoitel opened this issue Jan 23, 2021 · 2 comments

Comments

@JustinVoitel
Copy link

JustinVoitel commented Jan 23, 2021

It would be nice if genql would generate a object alongside the type definition for enums. This would enable to iterate over enums to easily display them in the browser

  1. Lets say I have a schema.graphql that looks something like this
...
enum UserRole {
  Admin
  Trusted
  Untrusted
  User
}
...
  1. Now genql would generate something like this for the enum in schema.ts:
...
export const UserRole: {
  Admin: 'Admin',
  User: 'User',
  Trusted: 'Trusted',
  Untrusted: 'Untrusted'
};

export type UserRole = (typeof UserRole)[keyof typeof UserRole]
...

instead of what its currently doing:

export type UserRole = 'Admin' | 'Trusted' | 'Untrusted' | 'User'
  1. This would enable me to do something like this client-side:
let userRole: UserRole = "Admin"

Object.values(UserRole).map(role => {
  console.log(role);
})

Very minimal but I hope you get the point ^^

Maybe make this feature configurable so its disabled by default ?
Please tell me what you think :)

@remorses
Copy link
Owner

Yes this is a good idea, in the meantime you can do this

1_f0QbU0nW73OubeQlFqDNNA

@GavinRay97
Copy link

Why about a regular Typescript enum?
It's nearly identical to:

export const UserRole: {
  Admin: 'Admin',
  User: 'User',
  Trusted: 'Trusted',
  Untrusted: 'Untrusted'
};

export type UserRole = (typeof UserRole)[keyof typeof UserRole]

image

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

3 participants