Merge selection sets
This commit is contained in:
@ -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 "" "{ count number }"
|
||||
$ 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 "" "{ philosopher { firstName } philosopher { lastName } }"
|
||||
in actual `shouldBe` expected
|
||||
|
Reference in New Issue
Block a user