mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-18 21:12:09 +03:00
40617719ef
We only use these `Show` instances in error messages (where we call `show` explicitly anyway) and test cases (in which Hspec requires `Show a` for any `a` in an assertion). This removes the instance in favor of a custom `showQErr` function (which serializes the error to JSON). It is then used in certain error message production which previously called `show` on a `QErr`. There are two places where we serialize a QErr and then construct a new QErr from the resulting string. Instead, we modify the existing QErr to add extra information. An orphan `Show QErr` instance is retained for tests so that we can have nice test failure messages. This is preparation for future changes in which the error message within `QErr` will not be exposed directly, and therefore will not have a `Show` instance. That said, it feels like a sensible kind of cleanup anyway. PR-URL: https://github.com/hasura/graphql-engine-mono/pull/4897 GitOrigin-RevId: 8f79f7a356f0aea571156f39aefac242bf751f3a
29 lines
916 B
Haskell
29 lines
916 B
Haskell
module Hasura.GraphQL.Parser.MonadParseTest (spec) where
|
|
|
|
import Data.Aeson.Internal
|
|
import Hasura.Base.Error
|
|
import Hasura.Base.Error.TestInstances ()
|
|
import Hasura.GraphQL.Parser.Class.Parse
|
|
import Hasura.GraphQL.Parser.Monad
|
|
import Hasura.Prelude
|
|
import Test.Hspec
|
|
|
|
runParse' :: Parse () -> Either QErr ()
|
|
runParse' = runParse @_ @()
|
|
|
|
errorStr :: Text
|
|
errorStr = "oh no"
|
|
|
|
spec :: Spec
|
|
spec = do
|
|
describe "withKey" $ do
|
|
it "Path is empty when no keys added" $ do
|
|
let parser = parseError errorStr
|
|
expected = (err400 ValidationFailed errorStr) {qePath = mempty}
|
|
runParse' parser `shouldBe` Left expected
|
|
|
|
it "Path has two items in the order they were added" $ do
|
|
let parser = withKey (Key "dog") (withKey (Key "log") (parseError errorStr))
|
|
expected = (err400 ValidationFailed errorStr) {qePath = [Key "dog", Key "log"]}
|
|
runParse' parser `shouldBe` Left expected
|