-
Notifications
You must be signed in to change notification settings - Fork 32
How to construct a complex Object from Record? #217
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
So this is where I think something is wrong with how we do things in graphql-api, we don't have a way to automatically derive haskell records from/to graphql ASTs (hence my issue there: #211) To answer your question, you can't create a QuoteR, it's a simple "alias" to a GQLV.Object' GQLV.ConstScalar, this means in particular that this type is never embodied in your graphql server, it's just resolved in its handler but that's about it. The reason why it works this way is, as far as I understand it, that subtyping in haskell is hard and subtyping is very much the idea of graphql, the AST (graphql Values in this project) way of doing it is a way to solve the problem, but as of today it creates A. a lot of boilerplate to create a schema in the GQL DSL and with the classical haskell way and B. a weird understanding for the layperson beginning with the lib (as opposed to something like Deriving GQL automatically like aeson does it for json)... I wish we could define our schemas with plain haskell objects like:
But it's not possible in this lib (and seemingly won't be possible in the near future, but I might be missing something). |
@theobat - I understand that it's a simple alias, however I can't even seem to construct the alias above - shouldn't I be able to build a GQLV.Object' GQLV.ConstScalar that IS a QuoteR using the makeQuoteR function?, and likewise to wrap it with a GQLV.Object' that is a QuoteGQL? I feel like I'm missing something in the construction |
Well it's not even an alias, I was wrong (but it's the same problem for me, it's just worse than I thought) it's a schema definition, it's completely unrelated to the Object value that you constructed (which I tried to explain with my own words):
|
And by the way it seems like there's no constructor at all for the |
@theobat - thanks for confirming my suspicions, that there is no way to actually construct my type |
You are right @theobat - the only way to construct a result is via a handler. The idea at the time IIRC was that we only wanted to execute a resolver when required, e.g. imagine If you mostly care about convenience I think it'd be possible to write a generic resolver for records because we already have one for sum types to enum here: https://github.com/haskell-graphql/graphql-api/blob/master/src/GraphQL/Internal/API/Enum.hs#L113 |
I can't seem to construct a multi-field argument without several errors: Here's what I have so far:
makeQuoteGQL is failing to typeCheck with
Expected type: Maybe QuoteR
Actual type: Maybe (GQLV.Object' GQLV.ConstScalar)
How on Earth can I construct a QuoteR - I need to use the record type as an intermediary because GQLAPI.Object does not implement FromJSON
what am I missing for these more complex types?
The text was updated successfully, but these errors were encountered: