diff options
Diffstat (limited to 'src/Language/GraphQL')
| -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 |
5 files changed, 25 insertions, 44 deletions
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 |
