summaryrefslogtreecommitdiff
path: root/src/Language/GraphQL
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2021-05-11 07:11:47 +0200
committerEugen Wissner <belka@caraus.de>2021-05-11 07:11:47 +0200
commitf671645043b8d9e148ed96c3a26aa268ef0ff7b5 (patch)
tree717eb1a261163b82dbbe6af66505ad5e25634fd2 /src/Language/GraphQL
parent1af95345d21ecfaa0823cc5343d2ccc83c89d449 (diff)
downloadgraphql-f671645043b8d9e148ed96c3a26aa268ef0ff7b5.tar.gz
Remove unused QueryError.TransformationError
Diffstat (limited to 'src/Language/GraphQL')
-rw-r--r--src/Language/GraphQL/Execute.hs2
-rw-r--r--src/Language/GraphQL/Execute/Internal.hs7
-rw-r--r--src/Language/GraphQL/Execute/Subscribe.hs14
-rw-r--r--src/Language/GraphQL/Execute/Transform.hs25
4 files changed, 20 insertions, 28 deletions
diff --git a/src/Language/GraphQL/Execute.hs b/src/Language/GraphQL/Execute.hs
index 6e46d7c..ac8f954 100644
--- a/src/Language/GraphQL/Execute.hs
+++ b/src/Language/GraphQL/Execute.hs
@@ -33,7 +33,7 @@ execute :: (MonadCatch m, VariableValue a, Serialize b)
-> m (Either (ResponseEventStream m b) (Response b))
execute schema' operationName subs document =
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
executeRequest :: (MonadCatch m, Serialize a)
diff --git a/src/Language/GraphQL/Execute/Internal.hs b/src/Language/GraphQL/Execute/Internal.hs
index 792a758..7e4e4a9 100644
--- a/src/Language/GraphQL/Execute/Internal.hs
+++ b/src/Language/GraphQL/Execute/Internal.hs
@@ -14,7 +14,7 @@ module Language.GraphQL.Execute.Internal
import Control.Monad.Trans.State (modify)
import Control.Monad.Catch (MonadCatch)
import Data.Sequence ((|>))
-import Data.Text (Text)
+import qualified Data.Text as Text
import Language.GraphQL.Execute.Coerce
import Language.GraphQL.Error
( CollectErrsT
@@ -32,5 +32,6 @@ addError returnValue error' = modify appender >> pure returnValue
{ errors = errors |> error'
}
-singleError :: Serialize b => forall a. Text -> Either a (Response b)
-singleError message = Right $ Response null $ pure $ Error message [] []
+singleError :: Serialize b => forall a. String -> Either a (Response b)
+singleError message =
+ Right $ Response null $ pure $ Error (Text.pack message) [] []
diff --git a/src/Language/GraphQL/Execute/Subscribe.hs b/src/Language/GraphQL/Execute/Subscribe.hs
index 44be965..0a2a681 100644
--- a/src/Language/GraphQL/Execute/Subscribe.hs
+++ b/src/Language/GraphQL/Execute/Subscribe.hs
@@ -15,8 +15,6 @@ import Data.HashMap.Strict (HashMap)
import qualified Data.HashMap.Strict as HashMap
import qualified Data.List.NonEmpty as NonEmpty
import Data.Sequence (Seq(..))
-import Data.Text (Text)
-import qualified Data.Text as Text
import Language.GraphQL.AST (Name)
import Language.GraphQL.Execute.Coerce
import Language.GraphQL.Execute.Execution
@@ -32,7 +30,7 @@ subscribe :: (MonadCatch m, Serialize a)
=> HashMap Name (Type m)
-> Out.ObjectType m
-> Seq (Transform.Selection m)
- -> m (Either Text (ResponseEventStream m a))
+ -> m (Either String (ResponseEventStream m a))
subscribe types' objectType fields = do
sourceStream <- createSourceEventStream types' objectType fields
traverse (mapSourceToResponseEvent types' objectType fields) sourceStream
@@ -51,7 +49,7 @@ createSourceEventStream :: MonadCatch m
=> HashMap Name (Type m)
-> Out.ObjectType m
-> Seq (Transform.Selection m)
- -> m (Either Text (Out.SourceEventStream m))
+ -> m (Either String (Out.SourceEventStream m))
createSourceEventStream _types subscriptionType@(Out.ObjectType _ _ _ fieldTypes) fields
| [fieldGroup] <- OrderedMap.elems groupedFieldSet
, Transform.Field _ fieldName arguments' _ <- NonEmpty.head fieldGroup
@@ -70,21 +68,19 @@ resolveFieldEventStream :: MonadCatch m
=> Type.Value
-> Type.Subs
-> Out.Subscribe m
- -> m (Either Text (Out.SourceEventStream m))
+ -> m (Either String (Out.SourceEventStream m))
resolveFieldEventStream result args resolver =
catch (Right <$> runReaderT resolver context) handleEventStreamError
where
handleEventStreamError :: MonadCatch m
=> ResolverException
- -> m (Either Text (Out.SourceEventStream m))
- handleEventStreamError = pure . Left . Text.pack . displayException
+ -> m (Either String (Out.SourceEventStream m))
+ handleEventStreamError = pure . Left . displayException
context = Type.Context
{ Type.arguments = Type.Arguments args
, Type.values = result
}
--- This is actually executeMutation, but we don't distinguish between queries
--- and mutations yet.
executeSubscriptionEvent :: (MonadCatch m, Serialize a)
=> HashMap Name (Type m)
-> Out.ObjectType m
diff --git a/src/Language/GraphQL/Execute/Transform.hs b/src/Language/GraphQL/Execute/Transform.hs
index ebbe633..62e5b54 100644
--- a/src/Language/GraphQL/Execute/Transform.hs
+++ b/src/Language/GraphQL/Execute/Transform.hs
@@ -25,7 +25,6 @@ module Language.GraphQL.Execute.Transform
, QueryError(..)
, Selection(..)
, document
- , queryError
) where
import Control.Monad (foldM, unless)
@@ -71,8 +70,6 @@ data Selection m
| SelectionField (Field m)
-- | GraphQL has 3 operation types: queries, mutations and subscribtions.
---
--- Currently only queries and mutations are supported.
data Operation m
= Query (Maybe Text) (Seq (Selection m))
| Mutation (Maybe Text) (Seq (Selection m))
@@ -98,10 +95,19 @@ data QueryError
= OperationNotFound Text
| OperationNameRequired
| CoercionError
- | TransformationError
| EmptyDocument
| 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
= Int Int32
| Float Double
@@ -114,17 +120,6 @@ data Input
| Variable Type.Value
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
:: Maybe Full.Name
-> NonEmpty OperationDefinition