summaryrefslogtreecommitdiff
path: root/tests/Language/GraphQL/ExecuteSpec.hs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Language/GraphQL/ExecuteSpec.hs')
-rw-r--r--tests/Language/GraphQL/ExecuteSpec.hs47
1 files changed, 40 insertions, 7 deletions
diff --git a/tests/Language/GraphQL/ExecuteSpec.hs b/tests/Language/GraphQL/ExecuteSpec.hs
index d0e7a66..62c6f25 100644
--- a/tests/Language/GraphQL/ExecuteSpec.hs
+++ b/tests/Language/GraphQL/ExecuteSpec.hs
@@ -22,21 +22,54 @@ schema = Schema {query = queryType, mutation = Nothing}
queryType :: Out.ObjectType Identity
queryType = Out.ObjectType "Query" Nothing []
- $ HashMap.singleton "count"
- $ Out.Resolver countField
+ $ HashMap.singleton "philosopher"
+ $ Out.Resolver philosopherField
$ pure
- $ Int 8
+ $ Object mempty
where
- countField = Out.Field Nothing (Out.NonNullScalarType int) HashMap.empty
+ philosopherField =
+ Out.Field Nothing (Out.NonNullObjectType philosopherType) HashMap.empty
+
+philosopherType :: Out.ObjectType Identity
+philosopherType = Out.ObjectType "Philosopher" Nothing []
+ $ HashMap.fromList resolvers
+ where
+ resolvers =
+ [ ("firstName", firstNameResolver)
+ , ("lastName", lastNameResolver)
+ ]
+ firstNameResolver = Out.Resolver firstNameField $ pure $ String "Friedrich"
+ lastNameResolver = Out.Resolver lastNameField $ pure $ String "Nietzsche"
+ firstNameField = Out.Field Nothing (Out.NonNullScalarType string) HashMap.empty
+ lastNameField = Out.Field Nothing (Out.NonNullScalarType string) HashMap.empty
spec :: Spec
spec =
- describe "execute" $
+ describe "execute" $ do
it "skips unknown fields" $
let expected = Aeson.object
- ["data" .= Aeson.object ["count" .= (8 :: Int)]]
+ [ "data" .= Aeson.object
+ [ "philosopher" .= Aeson.object
+ [ "firstName" .= ("Friedrich" :: String)
+ ]
+ ]
+ ]
+ execute' = execute schema (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)
+ ]
+ ]
+ ]
execute' = execute schema (mempty :: HashMap Name Aeson.Value)
actual = runIdentity
$ either parseError execute'
- $ parse document "" "{ count number }"
+ $ parse document "" "{ philosopher { firstName } philosopher { lastName } }"
in actual `shouldBe` expected