diff options
Diffstat (limited to 'docs/tutorial/tutorial.lhs')
| -rw-r--r-- | docs/tutorial/tutorial.lhs | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/docs/tutorial/tutorial.lhs b/docs/tutorial/tutorial.lhs index d017ddd..edaf7f2 100644 --- a/docs/tutorial/tutorial.lhs +++ b/docs/tutorial/tutorial.lhs @@ -12,20 +12,19 @@ We have written a small tutorial to help you (and ourselves) understand the grap Since this file is a literate haskell file, we start by importing some dependencies. > {-# LANGUAGE OverloadedStrings #-} -> {-# LANGUAGE LambdaCase #-} > module Main where > > import Control.Monad.IO.Class (liftIO) -> import Control.Monad.Trans.Except (throwE) > import Data.Aeson (encode) > import Data.ByteString.Lazy.Char8 (putStrLn) +> import Data.HashMap.Strict (HashMap) +> import qualified Data.HashMap.Strict as HashMap > import Data.List.NonEmpty (NonEmpty(..)) > import Data.Text (Text) > import Data.Time (getCurrentTime) > > import Language.GraphQL > import qualified Language.GraphQL.Schema as Schema -> import Language.GraphQL.Trans (ActionT(..)) > > import Prelude hiding (putStrLn) @@ -36,8 +35,8 @@ example from [graphql.js](https://github.com/graphql/graphql-js). First we build a GraphQL schema. -> schema1 :: NonEmpty (Schema.Resolver IO) -> schema1 = hello :| [] +> schema1 :: HashMap Text (NonEmpty (Schema.Resolver IO)) +> schema1 = HashMap.singleton "Query" $ hello :| [] > > hello :: Schema.Resolver IO > hello = Schema.scalar "hello" (return ("it's me" :: Text)) @@ -66,14 +65,13 @@ returning For this example, we're going to be using time. -> schema2 :: NonEmpty (Schema.Resolver IO) -> schema2 = time :| [] +> schema2 :: HashMap Text (NonEmpty (Schema.Resolver IO)) +> schema2 = HashMap.singleton "Query" $ time :| [] > > time :: Schema.Resolver IO -> time = Schema.scalarA "time" $ \case -> [] -> do t <- liftIO getCurrentTime -> return $ show t -> _ -> ActionT $ throwE "Invalid arguments." +> time = Schema.scalar "time" $ do +> t <- liftIO getCurrentTime +> return $ show t This defines a simple schema with one type and one field, which resolves to the current time. @@ -126,8 +124,8 @@ This will fail Now that we have two resolvers, we can define a schema which uses them both. -> schema3 :: NonEmpty (Schema.Resolver IO) -> schema3 = hello :| [time] +> schema3 :: HashMap Text (NonEmpty (Schema.Resolver IO)) +> schema3 = HashMap.singleton "Query" $ hello :| [time] > > query3 :: Text > query3 = "query timeAndHello { time hello }" |
