diff options
| author | Eugen Wissner <belka@caraus.de> | 2020-06-12 07:58:08 +0200 |
|---|---|---|
| committer | Eugen Wissner <belka@caraus.de> | 2020-06-12 07:58:08 +0200 |
| commit | e8c54810f8978b29e136ac0e1d91db8545a3f5f5 (patch) | |
| tree | d187ec8dfd7a56a4b76f8f44f7b7aad38eb0fe40 /tests/Language/GraphQL | |
| parent | c37b9c88b1f64d842ad837a18bfbe01026324abb (diff) | |
| download | graphql-e8c54810f8978b29e136ac0e1d91db8545a3f5f5.tar.gz | |
Merge selection sets
Diffstat (limited to 'tests/Language/GraphQL')
| -rw-r--r-- | tests/Language/GraphQL/ExecuteSpec.hs | 47 |
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 |
