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

Is there a way to read-in the type of user input (Union Type) #191

Closed
EdmundsEcho opened this issue Jul 15, 2018 · 0 comments
Closed

Is there a way to read-in the type of user input (Union Type) #191

EdmundsEcho opened this issue Jul 15, 2018 · 0 comments

Comments

@EdmundsEcho
Copy link

EdmundsEcho commented Jul 15, 2018

I have a Union type defined in GraphQL. Is there a way to define a AnnotatedInputType that pattern matches based on the the specific type provided by the user? I'm now using three optional Arguments, one for each of the types in my Union. It seems clunky, but works. Thanks for letting me know.

Update 1

In the starwars tests, the code instantiates human using a case statement that pattern matches

... \case ->
[Argument "episode" (ValueInt n)] -> ... fromIntegral n
[Argument "episode" (ValueEnum "NEWHOPE")] -> ... 
...
_ -> empty

How does this approach play out in the latest iteration of the library?

Update 2

The GraphQL specification does not currently support a Union Type for an Input Object. However, it turns out I'm in good company regarding this question. There is an open RFC to discuss the benefits of implementing the feature in the specification. Here is a link.

In the meantime, there are several alternative approaches. One of them being, as the currently library allows, is to use several Arguments each with a unique field name, with optional input, one for each input type.

- E

@EdmundsEcho EdmundsEcho changed the title Is there a way to read-in the type of user input Is there a way to read-in the type of user input (Union Type) Aug 3, 2018
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