Open harendra-kumar opened 6 years ago
@harendra-kumar For the specific error you mention there aren't any easy fixes. We're trying to constrain the type machinery as much as possible where we can but we don't have any way to hook into GHCs type inference messages to rewrite them to graphql-api terms.
If you have any ideas for how to fix PRs are more than welcome! Otherwise I think I'll close this as "not possible" if that's OK with you?
Actually, I just figured what I was looking for, it is already there. The above type signature can be written nicely using Handler
e.g.:
type GetResource = Object "GetResource" '[]
'[ Field "age" (Maybe Int32)
, Field "gender" (Maybe Text)
, Field "_acl" (Maybe GQLACLInfo)
]
buildResource :: Monad m => ResourceTable -> Handler m GetResource
buildResource rsrc = return
( getResInt32 (resourceTableResAge rsrc)
:<> getResText (resourceTableResGender rsrc)
:<> getResAcl (resourceTableRecordACL rsrc)
)
When I omit the the buildResource
signature in the above snippet I get the complex GHC generated type signature warning that I pasted when opening the issue. But I figure this is the way to write the signature. Maybe you can put this somewhere in the docs to make it clear how to write signatures, and what you need to do if you get that kind of warnings.
I am finding the type errors very cryptic and hard to fix, though once you get the hang of it, it becomes better. But when you are starting out with this library its a big pain.
Also, can there be a better way of writing type signatures, e.g. GHC prints this for one case: