Union as an input to GraphQL

Hello hello!

I’m using ‘dillonkearns/elm-graphl’ and I need to send deeply nested union type to my GraphQL backend. GraphQL, however, does not support unions as input types : /

Does anyone have a workaround or a suggestion for this situation?

I was thinking on passing the type as a scalar and then validate it in the backend somehow.

Now, considering that same type is first received from the backend, can I assume that elm-graphql has generated an encoder for that type? Can it be leveraged when sending that type back?

This has an example of a workaround https://github.com/graphql/graphql-spec/blob/master/rfcs/InputUnion.md#-problem-sketch

Pretty much sending a record with all possible union members as optional arguments

{ 
  cat: OptionArgument CatInput
  dog: OptionArgument DogInput
  snake: OptionArgument SnakeInput
}

And then figuring out what to use in the backend. Not a very nice solution unfortunatelly as you can send nonsensical inputs.

Thanx! Quite hard deciding which crappy approach should I take : )