Remove unused QueryError.TransformationError

This commit is contained in:
Eugen Wissner 2021-05-11 07:11:47 +02:00
parent 1af95345d2
commit f671645043
Signed by: belka
GPG Key ID: A27FDC1E8EE902C0
4 changed files with 20 additions and 28 deletions

View File

@ -33,7 +33,7 @@ execute :: (MonadCatch m, VariableValue a, Serialize b)
-> m (Either (ResponseEventStream m b) (Response b)) -> m (Either (ResponseEventStream m b) (Response b))
execute schema' operationName subs document = execute schema' operationName subs document =
case Transform.document schema' operationName subs document of case Transform.document schema' operationName subs document of
Left queryError -> pure $ singleError $ Transform.queryError queryError Left queryError -> pure $ singleError $ show queryError
Right transformed -> executeRequest transformed Right transformed -> executeRequest transformed
executeRequest :: (MonadCatch m, Serialize a) executeRequest :: (MonadCatch m, Serialize a)

View File

@ -14,7 +14,7 @@ module Language.GraphQL.Execute.Internal
import Control.Monad.Trans.State (modify) import Control.Monad.Trans.State (modify)
import Control.Monad.Catch (MonadCatch) import Control.Monad.Catch (MonadCatch)
import Data.Sequence ((|>)) import Data.Sequence ((|>))
import Data.Text (Text) import qualified Data.Text as Text
import Language.GraphQL.Execute.Coerce import Language.GraphQL.Execute.Coerce
import Language.GraphQL.Error import Language.GraphQL.Error
( CollectErrsT ( CollectErrsT
@ -32,5 +32,6 @@ addError returnValue error' = modify appender >> pure returnValue
{ errors = errors |> error' { errors = errors |> error'
} }
singleError :: Serialize b => forall a. Text -> Either a (Response b) singleError :: Serialize b => forall a. String -> Either a (Response b)
singleError message = Right $ Response null $ pure $ Error message [] [] singleError message =
Right $ Response null $ pure $ Error (Text.pack message) [] []

View File

@ -15,8 +15,6 @@ import Data.HashMap.Strict (HashMap)
import qualified Data.HashMap.Strict as HashMap import qualified Data.HashMap.Strict as HashMap
import qualified Data.List.NonEmpty as NonEmpty import qualified Data.List.NonEmpty as NonEmpty
import Data.Sequence (Seq(..)) import Data.Sequence (Seq(..))
import Data.Text (Text)
import qualified Data.Text as Text
import Language.GraphQL.AST (Name) import Language.GraphQL.AST (Name)
import Language.GraphQL.Execute.Coerce import Language.GraphQL.Execute.Coerce
import Language.GraphQL.Execute.Execution import Language.GraphQL.Execute.Execution
@ -32,7 +30,7 @@ subscribe :: (MonadCatch m, Serialize a)
=> HashMap Name (Type m) => HashMap Name (Type m)
-> Out.ObjectType m -> Out.ObjectType m
-> Seq (Transform.Selection m) -> Seq (Transform.Selection m)
-> m (Either Text (ResponseEventStream m a)) -> m (Either String (ResponseEventStream m a))
subscribe types' objectType fields = do subscribe types' objectType fields = do
sourceStream <- createSourceEventStream types' objectType fields sourceStream <- createSourceEventStream types' objectType fields
traverse (mapSourceToResponseEvent types' objectType fields) sourceStream traverse (mapSourceToResponseEvent types' objectType fields) sourceStream
@ -51,7 +49,7 @@ createSourceEventStream :: MonadCatch m
=> HashMap Name (Type m) => HashMap Name (Type m)
-> Out.ObjectType m -> Out.ObjectType m
-> Seq (Transform.Selection m) -> Seq (Transform.Selection m)
-> m (Either Text (Out.SourceEventStream m)) -> m (Either String (Out.SourceEventStream m))
createSourceEventStream _types subscriptionType@(Out.ObjectType _ _ _ fieldTypes) fields createSourceEventStream _types subscriptionType@(Out.ObjectType _ _ _ fieldTypes) fields
| [fieldGroup] <- OrderedMap.elems groupedFieldSet | [fieldGroup] <- OrderedMap.elems groupedFieldSet
, Transform.Field _ fieldName arguments' _ <- NonEmpty.head fieldGroup , Transform.Field _ fieldName arguments' _ <- NonEmpty.head fieldGroup
@ -70,21 +68,19 @@ resolveFieldEventStream :: MonadCatch m
=> Type.Value => Type.Value
-> Type.Subs -> Type.Subs
-> Out.Subscribe m -> Out.Subscribe m
-> m (Either Text (Out.SourceEventStream m)) -> m (Either String (Out.SourceEventStream m))
resolveFieldEventStream result args resolver = resolveFieldEventStream result args resolver =
catch (Right <$> runReaderT resolver context) handleEventStreamError catch (Right <$> runReaderT resolver context) handleEventStreamError
where where
handleEventStreamError :: MonadCatch m handleEventStreamError :: MonadCatch m
=> ResolverException => ResolverException
-> m (Either Text (Out.SourceEventStream m)) -> m (Either String (Out.SourceEventStream m))
handleEventStreamError = pure . Left . Text.pack . displayException handleEventStreamError = pure . Left . displayException
context = Type.Context context = Type.Context
{ Type.arguments = Type.Arguments args { Type.arguments = Type.Arguments args
, Type.values = result , Type.values = result
} }
-- This is actually executeMutation, but we don't distinguish between queries
-- and mutations yet.
executeSubscriptionEvent :: (MonadCatch m, Serialize a) executeSubscriptionEvent :: (MonadCatch m, Serialize a)
=> HashMap Name (Type m) => HashMap Name (Type m)
-> Out.ObjectType m -> Out.ObjectType m

View File

@ -25,7 +25,6 @@ module Language.GraphQL.Execute.Transform
, QueryError(..) , QueryError(..)
, Selection(..) , Selection(..)
, document , document
, queryError
) where ) where
import Control.Monad (foldM, unless) import Control.Monad (foldM, unless)
@ -71,8 +70,6 @@ data Selection m
| SelectionField (Field m) | SelectionField (Field m)
-- | GraphQL has 3 operation types: queries, mutations and subscribtions. -- | GraphQL has 3 operation types: queries, mutations and subscribtions.
--
-- Currently only queries and mutations are supported.
data Operation m data Operation m
= Query (Maybe Text) (Seq (Selection m)) = Query (Maybe Text) (Seq (Selection m))
| Mutation (Maybe Text) (Seq (Selection m)) | Mutation (Maybe Text) (Seq (Selection m))
@ -98,10 +95,19 @@ data QueryError
= OperationNotFound Text = OperationNotFound Text
| OperationNameRequired | OperationNameRequired
| CoercionError | CoercionError
| TransformationError
| EmptyDocument | EmptyDocument
| UnsupportedRootOperation | UnsupportedRootOperation
instance Show QueryError where
show (OperationNotFound operationName) = unwords
["Operation", Text.unpack operationName, "couldn't be found in the document."]
show OperationNameRequired = "Missing operation name."
show CoercionError = "Coercion error."
show EmptyDocument =
"The document doesn't contain any executable operations."
show UnsupportedRootOperation =
"Root operation type couldn't be found in the schema."
data Input data Input
= Int Int32 = Int Int32
| Float Double | Float Double
@ -114,17 +120,6 @@ data Input
| Variable Type.Value | Variable Type.Value
deriving (Eq, Show) deriving (Eq, Show)
queryError :: QueryError -> Text
queryError (OperationNotFound operationName) = Text.unwords
["Operation", operationName, "couldn't be found in the document."]
queryError OperationNameRequired = "Missing operation name."
queryError CoercionError = "Coercion error."
queryError TransformationError = "Schema transformation error."
queryError EmptyDocument =
"The document doesn't contain any executable operations."
queryError UnsupportedRootOperation =
"Root operation type couldn't be found in the schema."
getOperation getOperation
:: Maybe Full.Name :: Maybe Full.Name
-> NonEmpty OperationDefinition -> NonEmpty OperationDefinition