graphql-api icon indicating copy to clipboard operation
graphql-api copied to clipboard

GraphQL.Resolver does NOT export DynamicUnionValue making refactoring impossible

Open cscalfani opened this issue 7 years ago • 1 comments

I'm trying to refactor out the commented section below into its own function.

type Man = Object "Man" '[] '[Field "name" Text, Field "canVote" Bool]
type Dog = Object "Dog" '[] '[Field "name" Text, Field "hatesCats" Bool]

type ManOrDog = Object "Animal" '[]
  '[Argument "num" Int32 :> Field "animal" (Union "ManOrDog" '[Man, Dog])]

manOrDog :: Int32 -> _
manOrDog num =
  if num `mod` 2 == 0
  then unionValue @Man $ pure (pure "Joe" :<> pure False)
  else unionValue @Dog $ pure (pure "Rover" :<> pure True)

pickAnimal :: Handler IO ManOrDog
pickAnimal = pure manOrDog
  -- where manOrDog num =
  --         if num `mod` 2 == 0
  --         then unionValue @Man $ pure (pure "Joe" :<> pure False)
  --         else unionValue @Dog $ pure (pure "Rover" :<> pure True)

According to the compiler, the _ is:

IO (GraphQL.Resolver.DynamicUnionValue (Union "ManOrDog" '[Man, Dog]) IO)

But DynamicUnionValue is NOT exported so this cannot be specified making the refactor impossible.

cscalfani avatar Feb 07 '18 23:02 cscalfani

Good catch. I'm doing some related work on this for #99. Will make sure I address it there.

jml avatar Feb 08 '18 07:02 jml