From 93a04032886976b540f5fdb1417bd085a642f772 Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Wed, 3 Jun 2020 07:20:38 +0200 Subject: Resolve abstract types Objects that can be a part of an union or interface should return __typename as string. --- tests/Test/FragmentSpec.hs | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'tests/Test/FragmentSpec.hs') diff --git a/tests/Test/FragmentSpec.hs b/tests/Test/FragmentSpec.hs index 36e88b1..0737706 100644 --- a/tests/Test/FragmentSpec.hs +++ b/tests/Test/FragmentSpec.hs @@ -54,32 +54,38 @@ hasErrors _ = True shirtType :: Out.ObjectType IO shirtType = Out.ObjectType "Shirt" Nothing [] $ HashMap.fromList - [ ("size", Out.Field Nothing (Out.NamedScalarType string) mempty $ pure $ snd size) - , ("circumference", Out.Field Nothing (Out.NamedScalarType int) mempty $ pure $ snd circumference) - , ("__typename", Out.Field Nothing (Out.NamedScalarType string) mempty $ pure $ String "Shirt") + [ ("size", Out.Resolver sizeFieldType $ pure $ snd size) + , ("circumference", Out.Resolver circumferenceFieldType $ pure $ snd circumference) ] hatType :: Out.ObjectType IO hatType = Out.ObjectType "Hat" Nothing [] $ HashMap.fromList - [ ("size", Out.Field Nothing (Out.NamedScalarType string) mempty $ pure $ snd size) - , ("circumference", Out.Field Nothing (Out.NamedScalarType int) mempty $ pure $ snd circumference) - , ("__typename", Out.Field Nothing (Out.NamedScalarType string) mempty $ pure $ String "Hat") + [ ("size", Out.Resolver sizeFieldType $ pure $ snd size) + , ("circumference", Out.Resolver circumferenceFieldType $ pure $ snd circumference) ] +circumferenceFieldType :: Out.Field IO +circumferenceFieldType = Out.Field Nothing (Out.NamedScalarType int) mempty + +sizeFieldType :: Out.Field IO +sizeFieldType = Out.Field Nothing (Out.NamedScalarType string) mempty + toSchema :: Text -> (Text, Value) -> Schema IO toSchema t (_, resolve) = Schema { query = queryType, mutation = Nothing } where unionMember = if t == "Hat" then hatType else shirtType + typeNameField = Out.Field Nothing (Out.NamedScalarType string) mempty + garmentField = Out.Field Nothing (Out.NamedObjectType unionMember) mempty queryType = case t of "circumference" -> hatType "size" -> shirtType _ -> Out.ObjectType "Query" Nothing [] $ HashMap.fromList - [ ("garment", Out.Field Nothing (Out.NamedObjectType unionMember) mempty $ pure resolve) - , ("__typename", Out.Field Nothing (Out.NamedScalarType string) mempty $ pure $ String "Shirt") + [ ("garment", Out.Resolver garmentField $ pure resolve) + , ("__typename", Out.Resolver typeNameField $ pure $ String "Shirt") ] spec :: Spec -- cgit v1.2.3