@ -4,6 +4,7 @@ module Language.GraphQL.ErrorSpec
|
||||
) where
|
||||
|
||||
import qualified Data.Aeson as Aeson
|
||||
import qualified Data.Sequence as Seq
|
||||
import Language.GraphQL.Error
|
||||
import Test.Hspec ( Spec
|
||||
, describe
|
||||
@ -14,11 +15,6 @@ import Test.Hspec ( Spec
|
||||
spec :: Spec
|
||||
spec = describe "singleError" $
|
||||
it "constructs an error with the given message" $
|
||||
let expected = Aeson.object
|
||||
[
|
||||
("errors", Aeson.toJSON
|
||||
[ Aeson.object [("message", "Message.")]
|
||||
]
|
||||
)
|
||||
]
|
||||
let errors'' = Seq.singleton $ Error "Message." 0 0
|
||||
expected = Response Aeson.Null errors''
|
||||
in singleError "Message." `shouldBe` expected
|
||||
|
@ -47,28 +47,26 @@ spec :: Spec
|
||||
spec =
|
||||
describe "execute" $ do
|
||||
it "skips unknown fields" $
|
||||
let expected = Aeson.object
|
||||
[ "data" .= Aeson.object
|
||||
[ "philosopher" .= Aeson.object
|
||||
[ "firstName" .= ("Friedrich" :: String)
|
||||
]
|
||||
let data'' = Aeson.object
|
||||
[ "philosopher" .= Aeson.object
|
||||
[ "firstName" .= ("Friedrich" :: String)
|
||||
]
|
||||
]
|
||||
execute' = execute schema (mempty :: HashMap Name Aeson.Value)
|
||||
expected = Response data'' mempty
|
||||
execute' = execute schema Nothing (mempty :: HashMap Name Aeson.Value)
|
||||
actual = runIdentity
|
||||
$ either parseError execute'
|
||||
$ parse document "" "{ philosopher { firstName surname } }"
|
||||
in actual `shouldBe` expected
|
||||
it "merges selections" $
|
||||
let expected = Aeson.object
|
||||
[ "data" .= Aeson.object
|
||||
[ "philosopher" .= Aeson.object
|
||||
[ "firstName" .= ("Friedrich" :: String)
|
||||
, "lastName" .= ("Nietzsche" :: String)
|
||||
]
|
||||
let data'' = Aeson.object
|
||||
[ "philosopher" .= Aeson.object
|
||||
[ "firstName" .= ("Friedrich" :: String)
|
||||
, "lastName" .= ("Nietzsche" :: String)
|
||||
]
|
||||
]
|
||||
execute' = execute schema (mempty :: HashMap Name Aeson.Value)
|
||||
expected = Response data'' mempty
|
||||
execute' = execute schema Nothing (mempty :: HashMap Name Aeson.Value)
|
||||
actual = runIdentity
|
||||
$ either parseError execute'
|
||||
$ parse document "" "{ philosopher { firstName } philosopher { lastName } }"
|
||||
|
@ -361,4 +361,4 @@ testQuery q expected = runIdentity (graphql schema q) `shouldBe` expected
|
||||
|
||||
testQueryParams :: Aeson.Object -> Text -> Aeson.Value -> Expectation
|
||||
testQueryParams f q expected =
|
||||
runIdentity (graphqlSubs schema f q) `shouldBe` expected
|
||||
runIdentity (graphqlSubs schema Nothing f q) `shouldBe` expected
|
||||
|
Reference in New Issue
Block a user