From 22d4a4e583d8075fc71cddc22566f41fc5a698dc Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Sun, 7 Jul 2019 06:31:53 +0200 Subject: Change the main namespace to Language.GraphQL --- src/Language/GraphQL.hs | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/Language/GraphQL.hs (limited to 'src/Language/GraphQL.hs') diff --git a/src/Language/GraphQL.hs b/src/Language/GraphQL.hs new file mode 100644 index 0000000..8ed29cf --- /dev/null +++ b/src/Language/GraphQL.hs @@ -0,0 +1,36 @@ +-- | This module provides the functions to parse and execute @GraphQL@ queries. +module Language.GraphQL where + +import Control.Monad (MonadPlus) + +import qualified Data.Text as T + +import qualified Data.Aeson as Aeson +import Text.Megaparsec ( errorBundlePretty + , parse + ) + +import Language.GraphQL.Execute +import Language.GraphQL.Parser +import Language.GraphQL.Schema + +import Language.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 :: MonadPlus m => Schema m -> T.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 :: MonadPlus m => Schema m -> Subs -> T.Text -> m Aeson.Value +graphqlSubs schema f = + either (parseError . errorBundlePretty) (execute schema f) + . parse document "" -- cgit v1.2.3