forked from OSS/graphql-spice
Update error messages for enum and union support
This commit is contained in:
parent
aa28bdd7fe
commit
16bcdca066
@ -322,7 +322,7 @@ deriveFromGraphQL typeName = do
|
|||||||
NewtypeD _ _ _ _ cons' _
|
NewtypeD _ _ _ _ cons' _
|
||||||
| RecC dataConName varBangTypes <- cons' ->
|
| RecC dataConName varBangTypes <- cons' ->
|
||||||
withRecordConstructor dataConName varBangTypes
|
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
|
where
|
||||||
enumMemberPattern (NormalC normalName []) =
|
enumMemberPattern (NormalC normalName []) =
|
||||||
let fromGraphQLF = conP (mkName "Type.Enum") [litP $ stringL $ nameBase normalName]
|
let fromGraphQLF = conP (mkName "Type.Enum") [litP $ stringL $ nameBase normalName]
|
||||||
@ -376,7 +376,7 @@ deriveToGraphQL typeName = do
|
|||||||
NewtypeD _ _ _ _ cons' _
|
NewtypeD _ _ _ _ cons' _
|
||||||
| RecC dataConName varBangTypes <- cons' ->
|
| RecC dataConName varBangTypes <- cons' ->
|
||||||
withRecordConstructor dataConName varBangTypes
|
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
|
where
|
||||||
conTName = conT typeName
|
conTName = conT typeName
|
||||||
collectEnumMemberNames (NormalC normalName []) = Just normalName
|
collectEnumMemberNames (NormalC normalName []) = Just normalName
|
||||||
@ -397,7 +397,7 @@ deriveToGraphQL typeName = do
|
|||||||
enumMemberPattern <$> enumMemberNames
|
enumMemberPattern <$> enumMemberNames
|
||||||
| Just unionMembers <- traverse collectUnionMembers cons' =
|
| Just unionMembers <- traverse collectUnionMembers cons' =
|
||||||
unionMemberPattern <$> unionMembers
|
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
|
withRecordConstructor dataConName varBangTypes = do
|
||||||
fieldAliases <- traverse newFieldAliases varBangTypes
|
fieldAliases <- traverse newFieldAliases varBangTypes
|
||||||
let fBody =
|
let fBody =
|
||||||
|
Loading…
Reference in New Issue
Block a user