diff options
| author | Eugen Wissner <belka@caraus.de> | 2019-06-21 10:44:58 +0200 |
|---|---|---|
| committer | Eugen Wissner <belka@caraus.de> | 2019-06-21 10:44:58 +0200 |
| commit | 5e9bf9648d891591fcb1f0e1c7b250fb80b1ddc6 (patch) | |
| tree | 0654d194f22f695823c275f43e70eeea564c567b /Data/GraphQL.hs | |
| parent | ce169ecef2ff9530817e330df7584c96d6ca6fee (diff) | |
| download | graphql-5e9bf9648d891591fcb1f0e1c7b250fb80b1ddc6.tar.gz | |
Parse queries with megaparsec
Diffstat (limited to 'Data/GraphQL.hs')
| -rw-r--r-- | Data/GraphQL.hs | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/Data/GraphQL.hs b/Data/GraphQL.hs index dfe9362..c332b6c 100644 --- a/Data/GraphQL.hs +++ b/Data/GraphQL.hs @@ -3,10 +3,12 @@ module Data.GraphQL where import Control.Applicative (Alternative) -import Data.Text (Text) +import qualified Data.Text as T import qualified Data.Aeson as Aeson -import qualified Data.Attoparsec.Text as Attoparsec +import Text.Megaparsec ( errorBundlePretty + , parse + ) import Data.GraphQL.Execute import Data.GraphQL.Parser @@ -19,7 +21,7 @@ import Data.GraphQL.Error -- 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 :: (Alternative m, Monad m) => Schema m -> T.Text -> m Aeson.Value graphql = flip graphqlSubs $ const Nothing -- | Takes a 'Schema', a variable substitution function and text @@ -28,7 +30,7 @@ graphql = flip graphqlSubs $ const Nothing -- 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 :: (Alternative m, Monad m) => Schema m -> Subs -> T.Text -> m Aeson.Value graphqlSubs schema f = - either parseError (execute schema f) - . Attoparsec.parseOnly document + either (parseError . errorBundlePretty) (execute schema f) + . parse document "" |
