Update error messages for enum and union support
All checks were successful
Build / audit (push) Successful in 7s
Build / test (push) Successful in 7m16s
Build / doc (push) Successful in 7m5s

This commit is contained in:
Eugen Wissner 2024-07-17 09:37:29 +02:00
parent aa28bdd7fe
commit 16bcdca066
Signed by: belka
GPG Key ID: A27FDC1E8EE902C0

View File

@ -322,7 +322,7 @@ deriveFromGraphQL typeName = do
NewtypeD _ _ _ _ cons' _
| RecC dataConName varBangTypes <- cons' ->
withRecordConstructor dataConName varBangTypes
_ -> error "Only records with a single data constructor are supported"
_ -> error "Only input objects and enums are supported if all member types have a FromGraphQL instance"
where
enumMemberPattern (NormalC normalName []) =
let fromGraphQLF = conP (mkName "Type.Enum") [litP $ stringL $ nameBase normalName]
@ -376,7 +376,7 @@ deriveToGraphQL typeName = do
NewtypeD _ _ _ _ cons' _
| RecC dataConName varBangTypes <- cons' ->
withRecordConstructor dataConName varBangTypes
_ -> error "Only records with a single data constructor are supported"
_ -> error "Only objects, unions and enums are supported if all member types have a ToGraphQL instance"
where
conTName = conT typeName
collectEnumMemberNames (NormalC normalName []) = Just normalName
@ -397,7 +397,7 @@ deriveToGraphQL typeName = do
enumMemberPattern <$> enumMemberNames
| Just unionMembers <- traverse collectUnionMembers cons' =
unionMemberPattern <$> unionMembers
| otherwise = error "Enum member should be a normal constructor without parameters"
| otherwise = error "All data constructors should have either no parameters (Enum) or one parameter (Union)"
withRecordConstructor dataConName varBangTypes = do
fieldAliases <- traverse newFieldAliases varBangTypes
let fBody =