diff options
Diffstat (limited to 'src/Language/GraphQL.hs')
| -rw-r--r-- | src/Language/GraphQL.hs | 43 |
1 files changed, 21 insertions, 22 deletions
diff --git a/src/Language/GraphQL.hs b/src/Language/GraphQL.hs index 7ac08d7..c33eb95 100644 --- a/src/Language/GraphQL.hs +++ b/src/Language/GraphQL.hs @@ -5,32 +5,31 @@ module Language.GraphQL ) where import Control.Monad.IO.Class (MonadIO) -import qualified Data.Text as T - import qualified Data.Aeson as Aeson -import Text.Megaparsec (parse) - +import Data.List.NonEmpty (NonEmpty) +import qualified Data.Text as T +import Language.GraphQL.Error import Language.GraphQL.Execute import Language.GraphQL.Parser -import Language.GraphQL.Schema - -import Language.GraphQL.Error +import qualified Language.GraphQL.Schema as Schema +import Text.Megaparsec (parse) --- | 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 :: MonadIO m => Schema m -> T.Text -> m Aeson.Value +-- | If the text parses correctly as a @GraphQL@ query the query is +-- executed using the given 'Schema.Resolver's. +graphql :: MonadIO m + => NonEmpty (Schema.Resolver m) -- ^ Resolvers. + -> T.Text -- ^ Text representing a @GraphQL@ request document. + -> m Aeson.Value -- ^ Response. 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 :: MonadIO m => Schema m -> Subs -> T.Text -> m Aeson.Value -graphqlSubs schema f = - either parseError (execute schema f) +-- | If the text parses correctly as a @GraphQL@ query the substitution is +-- applied to the query and the query is then executed using to the given +-- 'Schema.Resolver's. +graphqlSubs :: MonadIO m + => NonEmpty (Schema.Resolver m) -- ^ Resolvers. + -> Schema.Subs -- ^ Variable substitution function. + -> T.Text -- ^ Text representing a @GraphQL@ request document. + -> m Aeson.Value -- ^ Response. +graphqlSubs schema f + = either parseError (execute schema f) . parse document "" |
