haskell-graphql / graphql-api

Write type-safe GraphQL services in Haskell
BSD 3-Clause "New" or "Revised" License
406 stars 35 forks source link

GraphQL.Resolver does NOT export DynamicUnionValue making refactoring impossible #165

Open cscalfani opened 6 years ago

cscalfani commented 6 years ago

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.

jml commented 6 years ago

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