diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/Language/GraphQL.hs | 24 | ||||
| -rw-r--r-- | src/Language/GraphQL/AST/Encoder.hs | 11 | ||||
| -rw-r--r-- | src/Language/GraphQL/AST/Lexer.hs | 7 | ||||
| -rw-r--r-- | src/Language/GraphQL/Error.hs | 40 | ||||
| -rw-r--r-- | src/Language/GraphQL/Execute/Coerce.hs | 5 | ||||
| -rw-r--r-- | src/Language/GraphQL/Validate/Rules.hs | 6 | ||||
| -rw-r--r-- | src/Test/Hspec/GraphQL.hs | 4 |
7 files changed, 51 insertions, 46 deletions
diff --git a/src/Language/GraphQL.hs b/src/Language/GraphQL.hs index b64cf42..4f3e8d9 100644 --- a/src/Language/GraphQL.hs +++ b/src/Language/GraphQL.hs @@ -4,6 +4,28 @@ #ifdef WITH_JSON -- | This module provides the functions to parse and execute @GraphQL@ queries. +-- +-- The content of this module depends on the value of the __json__ flag, which +-- is currently on by default. This behavior will change in the future, the flag +-- will be switched off by default and then removed. +-- +-- This documentation is generated with the enabled __json__ flag and functions +-- described here support JSON and are deprecated. JSON instances are provided +-- now by an additional package, __graphql-spice__. To start using the new +-- package create __cabal.project__ in the root directory of your project with +-- the following contents: +-- +-- @ +-- packages: . +-- constraints: graphql -json +-- @ +-- +-- Then add __graphql-spice__ as dependency. +-- +-- The new version of this module defines only one function, @graphql@, which +-- works with the internal GraphQL value representation used by this lbirary. +-- Refer to @Language.GraphQL.JSON.graphql@ in __graphql-spice__ for the +-- function that accepts and returns JSON. module Language.GraphQL ( graphql , graphqlSubs @@ -23,6 +45,7 @@ import qualified Language.GraphQL.Validate as Validate import Language.GraphQL.Type.Schema (Schema) import Text.Megaparsec (parse) +{-# DEPRECATED graphql "Use graphql-spice package instead" #-} -- | If the text parses correctly as a @GraphQL@ query the query is -- executed using the given 'Schema'. graphql :: MonadCatch m @@ -31,6 +54,7 @@ graphql :: MonadCatch m -> m (Either (ResponseEventStream m Aeson.Value) Aeson.Object) -- ^ Response. graphql schema = graphqlSubs schema mempty mempty +{-# DEPRECATED graphqlSubs "Use graphql-spice package instead" #-} -- | 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'. diff --git a/src/Language/GraphQL/AST/Encoder.hs b/src/Language/GraphQL/AST/Encoder.hs index 0d448df..54967ea 100644 --- a/src/Language/GraphQL/AST/Encoder.hs +++ b/src/Language/GraphQL/AST/Encoder.hs @@ -11,6 +11,7 @@ module Language.GraphQL.AST.Encoder , directive , document , minified + , operationType , pretty , type' , value @@ -34,7 +35,7 @@ import qualified Language.GraphQL.AST.Document as Full -- Use 'pretty' or 'minified' to construct the formatter. data Formatter = Minified - | Pretty Word + | Pretty !Word -- | Constructs a formatter for pretty printing. pretty :: Formatter @@ -101,7 +102,7 @@ variableDefinition formatter variableDefinition' = in variable variableName <> eitherFormat formatter ": " ":" <> type' variableType - <> maybe mempty (defaultValue formatter) (Full.node <$> defaultValue') + <> maybe mempty (defaultValue formatter . Full.node) defaultValue' defaultValue :: Formatter -> Full.ConstValue -> Lazy.Text defaultValue formatter val @@ -294,6 +295,12 @@ nonNullType :: Full.NonNullType -> Lazy.Text nonNullType (Full.NonNullTypeNamed x) = Lazy.Text.fromStrict x <> "!" nonNullType (Full.NonNullTypeList x) = listType x <> "!" +-- | Produces lowercase operation type: query, mutation or subscription. +operationType :: Formatter -> Full.OperationType -> Lazy.Text +operationType _formatter Full.Query = "query" +operationType _formatter Full.Mutation = "mutation" +operationType _formatter Full.Subscription = "subscription" + -- * Internal between :: Char -> Char -> Lazy.Text -> Lazy.Text diff --git a/src/Language/GraphQL/AST/Lexer.hs b/src/Language/GraphQL/AST/Lexer.hs index ecefaf6..ab1f36f 100644 --- a/src/Language/GraphQL/AST/Lexer.hs +++ b/src/Language/GraphQL/AST/Lexer.hs @@ -58,6 +58,7 @@ import qualified Text.Megaparsec.Char.Lexer as Lexer import Data.Text (Text) import qualified Data.Text as T import qualified Data.Text.Lazy as TL +import Control.Monad (void) -- | Standard parser. -- Accepts the type of the parsed token. @@ -93,7 +94,7 @@ dollar = symbol "$" -- | Parser for "@". at :: Parser () -at = symbol "@" >> pure () +at = void $ symbol "@" -- | Parser for "&". amp :: Parser T.Text @@ -101,7 +102,7 @@ amp = symbol "&" -- | Parser for ":". colon :: Parser () -colon = symbol ":" >> pure () +colon = void $ symbol ":" -- | Parser for "=". equals :: Parser T.Text @@ -220,7 +221,7 @@ escapeSequence = do -- | Parser for the "Byte Order Mark". unicodeBOM :: Parser () -unicodeBOM = optional (char '\xfeff') >> pure () +unicodeBOM = void $ optional $ char '\xfeff' -- | Parses "extend" followed by a 'symbol'. It is used by schema extensions. extend :: forall a. Text -> String -> NonEmpty (Parser a) -> Parser a diff --git a/src/Language/GraphQL/Error.hs b/src/Language/GraphQL/Error.hs index 4e461f0..87ee702 100644 --- a/src/Language/GraphQL/Error.hs +++ b/src/Language/GraphQL/Error.hs @@ -15,16 +15,13 @@ module Language.GraphQL.Error , ResolverException(..) , Response(..) , ResponseEventStream - , addErr - , addErrMsg , parseError , runCollectErrs - , singleError ) where import Conduit import Control.Exception (Exception(..)) -import Control.Monad.Trans.State (StateT, modify, runStateT) +import Control.Monad.Trans.State (StateT, runStateT) import Data.HashMap.Strict (HashMap) import Data.Sequence (Seq(..), (|>)) import qualified Data.Sequence as Seq @@ -103,11 +100,9 @@ instance Exception ResolverException -- * Deprecated +{-# DEPRECATED runCollectErrs "runCollectErrs was part of the old executor and isn't used anymore" #-} -- | Runs the given query computation, but collects the errors into an error -- list, which is then sent back with the data. --- --- /runCollectErrs was part of the old executor and isn't used anymore, it will --- be deprecated in the future and removed./ runCollectErrs :: (Monad m, Serialize a) => HashMap Name (Schema.Type m) -> CollectErrsT m a @@ -117,40 +112,13 @@ runCollectErrs types' res = do $ Resolution{ errors = Seq.empty, types = types' } pure $ Response dat errors +{-# DEPRECATED Resolution "Resolution was part of the old executor and isn't used anymore" #-} -- | Executor context. --- --- /Resolution was part of the old executor and isn't used anymore, it will be --- deprecated in the future and removed./ data Resolution m = Resolution { errors :: Seq Error , types :: HashMap Name (Schema.Type m) } +{-# DEPRECATED CollectErrsT "CollectErrsT was part of the old executor and isn't used anymore" #-} -- | A wrapper to pass error messages around. --- --- /CollectErrsT was part of the old executor and isn't used anymore, it will be --- deprecated in the future and removed./ type CollectErrsT m = StateT (Resolution m) m - --- | Adds an error to the list of errors. -{-# DEPRECATED #-} -addErr :: Monad m => Error -> CollectErrsT m () -addErr v = modify appender - where - appender :: Monad m => Resolution m -> Resolution m - appender resolution@Resolution{..} = resolution{ errors = errors |> v } - -{-# DEPRECATED #-} -makeErrorMessage :: Text -> Error -makeErrorMessage s = Error s [] [] - --- | Constructs a response object containing only the error with the given --- message. -{-# DEPRECATED #-} -singleError :: Serialize a => Text -> Response a -singleError message = Response null $ Seq.singleton $ Error message [] [] - --- | Convenience function for just wrapping an error message. -{-# DEPRECATED #-} -addErrMsg :: (Monad m, Serialize a) => Text -> CollectErrsT m a -addErrMsg errorMessage = (addErr . makeErrorMessage) errorMessage >> pure null diff --git a/src/Language/GraphQL/Execute/Coerce.hs b/src/Language/GraphQL/Execute/Coerce.hs index 9bc6b10..4725d74 100644 --- a/src/Language/GraphQL/Execute/Coerce.hs +++ b/src/Language/GraphQL/Execute/Coerce.hs @@ -8,6 +8,11 @@ {-# LANGUAGE CPP #-} -- | Types and functions used for input and result coercion. +-- +-- JSON instances in this module are only available with the __json__ +-- flag that is currently on by default, but will be disabled in the future. +-- Refer to the documentation in the 'Language.GraphQL' module and to +-- the __graphql-spice__ package. module Language.GraphQL.Execute.Coerce ( Output(..) , Serialize(..) diff --git a/src/Language/GraphQL/Validate/Rules.hs b/src/Language/GraphQL/Validate/Rules.hs index d7cc395..8c3156b 100644 --- a/src/Language/GraphQL/Validate/Rules.hs +++ b/src/Language/GraphQL/Validate/Rules.hs @@ -54,7 +54,7 @@ import Data.HashMap.Strict (HashMap) import Data.HashSet (HashSet) import qualified Data.HashSet as HashSet import Data.List (groupBy, sortBy, sortOn) -import Data.Maybe (catMaybes, fromMaybe, isJust, isNothing, mapMaybe) +import Data.Maybe (fromMaybe, isJust, isNothing, mapMaybe) import Data.List.NonEmpty (NonEmpty(..)) import Data.Ord (comparing) import Data.Sequence (Seq(..), (|>)) @@ -1551,9 +1551,9 @@ valuesOfCorrectTypeRule = ValueRule go constGo toConst Full.Null = Just Full.ConstNull toConst (Full.Enum enum) = Just $ Full.ConstEnum enum toConst (Full.List values) = - Just $ Full.ConstList $ catMaybes $ toConstNode <$> values + Just $ Full.ConstList $ mapMaybe toConstNode values toConst (Full.Object fields) = Just $ Full.ConstObject - $ catMaybes $ constObjectField <$> fields + $ mapMaybe constObjectField fields constObjectField Full.ObjectField{..} | Just constValue <- toConstNode value = Just $ Full.ObjectField name constValue location diff --git a/src/Test/Hspec/GraphQL.hs b/src/Test/Hspec/GraphQL.hs index 5d812bf..a848c15 100644 --- a/src/Test/Hspec/GraphQL.hs +++ b/src/Test/Hspec/GraphQL.hs @@ -9,7 +9,7 @@ {-# LANGUAGE OverloadedStrings #-} -- | Test helpers. -module Test.Hspec.GraphQL +module Test.Hspec.GraphQL {-# DEPRECATED "Use graphql-spice package instead" #-} ( shouldResolve , shouldResolveTo ) where @@ -43,7 +43,7 @@ shouldResolve executor query = do _ -> expectationFailure "the query is expected to resolve to a value, but it resolved to an event stream" #else -module Test.Hspec.GraphQL +module Test.Hspec.GraphQL {-# DEPRECATED "Use graphql-spice package instead" #-} ( ) where #endif |
