2016-03-09 01:15:46 +01:00
|
|
|
-- | The module Data.GraphQl provides the
|
|
|
|
-- functions graphql and graphqlSubs to parse
|
|
|
|
-- and execute GraphQL queries.
|
2016-02-05 12:32:35 +01:00
|
|
|
module Data.GraphQL where
|
|
|
|
|
2016-03-12 00:59:51 +01:00
|
|
|
import Control.Applicative (Alternative)
|
2016-02-05 12:32:35 +01:00
|
|
|
|
|
|
|
import Data.Text (Text)
|
|
|
|
|
|
|
|
import qualified Data.Aeson as Aeson
|
|
|
|
import qualified Data.Attoparsec.Text as Attoparsec
|
|
|
|
|
|
|
|
import Data.GraphQL.Execute
|
|
|
|
import Data.GraphQL.Parser
|
|
|
|
import Data.GraphQL.Schema
|
|
|
|
|
2016-03-12 00:59:51 +01:00
|
|
|
import Data.GraphQL.Error
|
|
|
|
|
2016-03-09 01:15:46 +01:00
|
|
|
-- | 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.
|
2016-02-05 12:32:35 +01:00
|
|
|
graphql :: (Alternative m, Monad m) => Schema m -> Text -> m Aeson.Value
|
2016-02-15 14:25:15 +01:00
|
|
|
graphql = flip graphqlSubs $ const Nothing
|
|
|
|
|
2016-03-09 01:15:46 +01:00
|
|
|
-- | 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.
|
2016-02-15 14:25:15 +01:00
|
|
|
graphqlSubs :: (Alternative m, Monad m) => Schema m -> Subs -> Text -> m Aeson.Value
|
|
|
|
graphqlSubs schema f =
|
2016-03-12 00:59:51 +01:00
|
|
|
either parseError (execute schema f)
|
2016-02-15 14:25:15 +01:00
|
|
|
. Attoparsec.parseOnly document
|