summaryrefslogtreecommitdiff
path: root/Data/GraphQL.hs
diff options
context:
space:
mode:
authorDanny Navarro <j@dannynavarro.net>2016-03-15 14:02:34 +0100
committerDanny Navarro <j@dannynavarro.net>2016-03-15 14:02:34 +0100
commit77853b17ae1197ba075ccc68df2a949dffc97092 (patch)
tree6e8385c5522ea92e4be314493c244c0ec043c568 /Data/GraphQL.hs
parentd8a731fe30ce800ac8347a902f38373d6cf689b2 (diff)
parent61d6af777897d918decc0ab8ef6456e05fccbe7b (diff)
downloadgraphql-77853b17ae1197ba075ccc68df2a949dffc97092.tar.gz
Merge branch 'all-improvements'
This adds general API documentation, a tutorial and error handling.
Diffstat (limited to 'Data/GraphQL.hs')
-rw-r--r--Data/GraphQL.hs18
1 files changed, 16 insertions, 2 deletions
diff --git a/Data/GraphQL.hs b/Data/GraphQL.hs
index 2da8a46..dfe9362 100644
--- a/Data/GraphQL.hs
+++ b/Data/GraphQL.hs
@@ -1,6 +1,7 @@
+-- | This module provides the functions to parse and execute @GraphQL@ queries.
module Data.GraphQL where
-import Control.Applicative (Alternative, empty)
+import Control.Applicative (Alternative)
import Data.Text (Text)
@@ -11,10 +12,23 @@ import Data.GraphQL.Execute
import Data.GraphQL.Parser
import Data.GraphQL.Schema
+import Data.GraphQL.Error
+
+-- | 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 as an @Aeson.@'Aeson.Value'.
graphql :: (Alternative m, Monad m) => Schema m -> Text -> m Aeson.Value
graphql = flip graphqlSubs $ const Nothing
+-- | Takes a 'Schema', a variable substitution function 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 as an @Aeson.@'Aeson.Value'.
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