summaryrefslogtreecommitdiff
path: root/tests/Language
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2023-02-24 17:14:43 +0100
committerEugen Wissner <belka@caraus.de>2023-02-24 17:14:43 +0100
commit3b0da4f3d75f2edf60a0a29a015aab1ae14338da (patch)
treefea135a06c471edece7e780289437eaba91172a1 /tests/Language
parentd83f75b3418d4f1caf4174e59464b50e385aac0e (diff)
downloadgraphql-3b0da4f3d75f2edf60a0a29a015aab1ae14338da.tar.gz
Fix resolvers returning a list in the reverse order
Diffstat (limited to 'tests/Language')
-rw-r--r--tests/Language/GraphQL/ExecuteSpec.hs28
1 files changed, 21 insertions, 7 deletions
diff --git a/tests/Language/GraphQL/ExecuteSpec.hs b/tests/Language/GraphQL/ExecuteSpec.hs
index c313df0..65033ae 100644
--- a/tests/Language/GraphQL/ExecuteSpec.hs
+++ b/tests/Language/GraphQL/ExecuteSpec.hs
@@ -66,8 +66,9 @@ queryType :: Out.ObjectType IO
queryType = Out.ObjectType "Query" Nothing []
$ HashMap.fromList
[ ("philosopher", ValueResolver philosopherField philosopherResolver)
- , ("genres", ValueResolver genresField genresResolver)
+ , ("throwing", ValueResolver throwingField throwingResolver)
, ("count", ValueResolver countField countResolver)
+ , ("sequence", ValueResolver sequenceField sequenceResolver)
]
where
philosopherField =
@@ -75,15 +76,22 @@ queryType = Out.ObjectType "Query" Nothing []
$ HashMap.singleton "id"
$ In.Argument Nothing (In.NamedScalarType id) Nothing
philosopherResolver = pure $ Object mempty
- genresField =
+ throwingField =
let fieldType = Out.ListType $ Out.NonNullScalarType string
in Out.Field Nothing fieldType HashMap.empty
- genresResolver :: Resolve IO
- genresResolver = throwM PhilosopherException
+ throwingResolver :: Resolve IO
+ throwingResolver = throwM PhilosopherException
countField =
let fieldType = Out.NonNullScalarType int
in Out.Field Nothing fieldType HashMap.empty
countResolver = pure ""
+ sequenceField =
+ let fieldType = Out.ListType $ Out.NonNullScalarType int
+ in Out.Field Nothing fieldType HashMap.empty
+ sequenceResolver = pure intSequence
+
+intSequence :: Value
+intSequence = Type.List [Type.Int 1, Type.Int 2, Type.Int 3]
musicType :: Out.ObjectType IO
musicType = Out.ObjectType "Music" Nothing []
@@ -344,14 +352,14 @@ spec =
in sourceQuery `shouldResolveTo` expected
it "gives location information for failed result coercion" $
- let data'' = Object $ HashMap.singleton "genres" Null
+ let data'' = Object $ HashMap.singleton "throwing" Null
executionErrors = pure $ Error
{ message = "PhilosopherException"
, locations = [Location 1 3]
- , path = [Segment "genres"]
+ , path = [Segment "throwing"]
}
expected = Response data'' executionErrors
- sourceQuery = "{ genres }"
+ sourceQuery = "{ throwing }"
in sourceQuery `shouldResolveTo` expected
it "sets data to null if a root field isn't nullable" $
@@ -375,6 +383,12 @@ spec =
sourceQuery = "{ philosopher(id: \"1\") { firstLanguage } }"
in sourceQuery `shouldResolveTo` expected
+ it "returns list elements in the original order" $
+ let data'' = Object $ HashMap.singleton "sequence" intSequence
+ expected = Response data'' mempty
+ sourceQuery = "{ sequence }"
+ in sourceQuery `shouldResolveTo` expected
+
context "queryError" $ do
let namedQuery name = "query " <> name <> " { philosopher(id: \"1\") { interest } }"
twoQueries = namedQuery "A" <> " " <> namedQuery "B"