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: Add helper function to get types of enums and scalars #44

Closed
kitten opened this issue Jan 28, 2024 · 1 comment · Fixed by #45
Closed

RFC: Add helper function to get types of enums and scalars #44

kitten opened this issue Jan 28, 2024 · 1 comment · Fixed by #45
Labels
future 🔮 An enhancement or feature proposal that will be addressed after the next release

Comments

@kitten
Copy link
Member

kitten commented Jan 28, 2024

Originally requested on Discord by @hazlad

Summary

One thing that I am missing is the ability to generate a string union type to represent all possible enum values - would this be something you'd consider adding to the library?

For example with the Pokemen example in the repo:

export type PokemonType = "Bug" | "Dark" | "Dragon" /* etc. */;

Proposed Solution

We should have a user accessible function, so, to keep things simple, a method on graphql, e.g. graphql.scalar() should be suitable.

This method should accept a scalar or enum name, and optionally a value, and should type check
said value against the allowable scalar/enum type.

The return type should be inferred to be the enum/scalar type (or a more exact one when a value is passed so ReturnType can be used to get the raw type.

Requirements

  • We must be able to get the raw return type
    • e.g. ReturnType<typeof graphql.scalar('PokemonType')>
  • We must be able to type check a value
    • e.g. graphql.scalar('Pokemontype', 'Bug')
@kitten kitten added the future 🔮 An enhancement or feature proposal that will be addressed after the next release label Jan 28, 2024
@kitten
Copy link
Member Author

kitten commented Jan 28, 2024

This is now supported in v1.2.0 via #45.

Documentation for this is found on the API reference docs page: graphql.scalar()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
future 🔮 An enhancement or feature proposal that will be addressed after the next release
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant