haskell-graphql / graphql-api

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

Use newtypes in schema #151

Open jml opened 6 years ago

jml commented 6 years ago

I want to do something like this:

newtype Thingy = Thingy Text deriving (Eq, Ord, Show)

instance ToValue Thingy where
  toValue (Thingy x) = toValue x

type QueryRoot = Object "QueryRoot" '[]
  '[ Field "thingy" Thingy
   ]

rootHandler :: Handler IO QueryRoot
rootHandler = thingyHandler

thingyHandler :: Handler IO Thingy
thingyHandler = pure $ Thingy "content"

But this gives me the following warning:

[-Wdeferred-type-errors]
    • Couldn't match expected type ‘Handler IO Thingy’
                  with actual type ‘f0 Thingy’
      The type variable ‘f0’ is ambiguous
    • In the expression: pure $ Thingy "content"
      In an equation for ‘thingyHandler’:
          thingyHandler = pure $ Thingy "content"

I think this is because we don't have a HasResolver instance. It seems a bit odd that I, the user, would have to provide one.