Open theobat opened 6 years ago
No. This compiles and executes from master, both in CI and on my laptop.
Perhaps if you provided a minimal, reproducible set of steps which demonstrated the problem, along with a full error message we'd be in a better position to help (c.f. http://sscce.org/).
Hey, thanks for your answer, so here's what I did:
dependencies:
And merely copied/pasted the examples in Main.hs:
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE NoImplicitPrelude #-}
module Main (main) where
import Protolude hiding (Enum)
import qualified Data.Aeson as Aeson
import GraphQL
import GraphQL.API
import GraphQL.Resolver (Handler)
-- import GraphQL.Value.ToValue (toValue)
-- import GraphQL.Value.FromValue (FromValue)
import GraphQL.Value (FromValue, toValue)
data DogStuff = DogStuff { _toy :: Text, _likesTreats :: Bool } deriving (Show, Generic)
instance FromValue DogStuff
instance HasAnnotatedInputType DogStuff
instance Defaultable DogStuff where
defaultFor _ = Just (DogStuff "shoe" False)
type Query = Object "Query" '[]
'[ Argument "dogStuff" DogStuff :> Field "description" Text ]
root :: Handler IO Query
root = pure description
description :: DogStuff -> Handler IO Text
description (DogStuff toy likesTreats)
| likesTreats = pure $ "likes treats and their favorite toy is a " <> toy
| otherwise = pure $ "their favorite toy is a " <> toy
example :: Text -> IO Response
example = interpretAnonymousQuery @Query root
main :: IO ()
main = do
response <- example "{ description(dogStuff: {_toy: \"bone\", _likesTreats: true}) }"
putStrLn $ Aeson.encode $ toValue response
response' <- example "{ description }"
putStrLn $ Aeson.encode $ toValue response'
I did give you all the meaningful error from the compiler:
➜ haskell-api-test git:(master) ✗ stack build
helloworld-0.1.0.0: unregistering (local file changes: app/Main.hs)
helloworld-0.1.0.0: build (lib + exe)
Preprocessing library for helloworld-0.1.0.0..
Building library for helloworld-0.1.0.0..
Preprocessing executable 'helloworld-exe' for helloworld-0.1.0.0..
Building executable 'helloworld-exe' for helloworld-0.1.0.0..
[2 of 2] Compiling Main ( app/Main.hs, .stack-work/dist/x86_64-osx/Cabal-2.0.1.0/build/helloworld-exe/helloworld-exe-tmp/Main.o )
.../haskell-api-test/app/Main.hs:19:23: error:
Module ‘GraphQL.Value’ does not export ‘FromValue’
|
19 | import GraphQL.Value (FromValue, toValue)
| ^^^^^^^^^
.../haskell-api-test/app/Main.hs:19:34: error:
Module ‘GraphQL.Value’ does not export ‘toValue’
|
19 | import GraphQL.Value (FromValue, toValue)
| ^^^^^^^
And these errors go away when I replace these imports with the two lines I commented in the snippet above.
Thanks. That makes things much clearer.
The examples in master work with master. We have moved modules around since 0.3.0 and have not yet released it.
You can see the examples for 0.3.0 here: https://github.com/haskell-graphql/graphql-api/tree/v0.3.0/tests/Examples
In the examples folder the input object example use the following import statement which is not compiling:
Any idea what's going on ?