From d1953891029a71115ee572b7b3798072cbaf2ea8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matth=C3=ADas=20P=C3=A1ll=20Gissurarson?= Date: Sat, 12 Mar 2016 00:59:51 +0100 Subject: Added exception handling with Alternative constraint according to spec. --- Data/GraphQL.hs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'Data/GraphQL.hs') diff --git a/Data/GraphQL.hs b/Data/GraphQL.hs index 2da8a46..a2796ae 100644 --- a/Data/GraphQL.hs +++ b/Data/GraphQL.hs @@ -1,6 +1,6 @@ module Data.GraphQL where -import Control.Applicative (Alternative, empty) +import Control.Applicative (Alternative) import Data.Text (Text) @@ -11,10 +11,13 @@ import Data.GraphQL.Execute import Data.GraphQL.Parser import Data.GraphQL.Schema +import Data.GraphQL.Error + graphql :: (Alternative m, Monad m) => Schema m -> Text -> m Aeson.Value graphql = flip graphqlSubs $ const Nothing + graphqlSubs :: (Alternative m, Monad m) => Schema m -> Subs -> Text -> m Aeson.Value graphqlSubs schema f = - either (const empty) (execute schema f) + either parseError (execute schema f) . Attoparsec.parseOnly document -- cgit v1.2.3 From 61d6af777897d918decc0ab8ef6456e05fccbe7b Mon Sep 17 00:00:00 2001 From: solrun Date: Wed, 9 Mar 2016 01:15:46 +0100 Subject: Added documentation of functions and modules and included tutorial.lhs. --- Data/GraphQL.hs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'Data/GraphQL.hs') diff --git a/Data/GraphQL.hs b/Data/GraphQL.hs index a2796ae..a5dac4d 100644 --- a/Data/GraphQL.hs +++ b/Data/GraphQL.hs @@ -1,3 +1,6 @@ +-- | The module Data.GraphQl provides the +-- functions graphql and graphqlSubs to parse +-- and execute GraphQL queries. module Data.GraphQL where import Control.Applicative (Alternative) @@ -13,10 +16,19 @@ import Data.GraphQL.Schema import Data.GraphQL.Error +-- | graphql takes a schema and text representing a GraphQL request document. +-- If the text parses correctly as a GraphQl query +-- the query is executed according to the given schema. +-- Returns the response to the query wrapped in an Aeson.Value. graphql :: (Alternative m, Monad m) => Schema m -> Text -> m Aeson.Value graphql = flip graphqlSubs $ const Nothing - +-- | graphqlsubs takes in a schema, a substitution and text representing +-- a GraphQL request document. +-- If the text parses correctly as a GraphQl query +-- the substitution is applied to the query and +-- the query is then executed according to the given schema. +-- Returns the response to the query wrapped in an Aeson.Value. graphqlSubs :: (Alternative m, Monad m) => Schema m -> Subs -> Text -> m Aeson.Value graphqlSubs schema f = either parseError (execute schema f) -- cgit v1.2.3