Skip to content

Should graphql's selection sets be subtypes or records in haskell (as opposed to JSON-like AST) ? #211

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

Open
theobat opened this issue Jan 4, 2019 · 0 comments

Comments

@theobat
Copy link
Contributor

theobat commented Jan 4, 2019

This is a bit hard to explain, but my idea is to spark a discussion about how much graphql-api could benefit from using a proper Record library in some way (it's not clear how to me yet).

So I recently realized that, an object definition in a graphql-api schema is never inhabited with a value per-say. Like, we cannot create a value out of nowhere for it:

type Plant = Object "Plant" '[]
  '[ Field "name" Text ]

-- this does not work =>
let test = Plant "Olala"
-- this does work, but we do not know it's a subtype of Plant though:
let (Just foo) = objectFromList [("name", toValue @Text "Olala")]

Of course we can create a resolver (that is a Handler in graphql-api) which can "sort of" create a graphql-api's Value's AST which will correspond to a "subtype" of Plant here.
Now this behavior is actually the very essence of graphql, so no problem. My point is, there should be a way to get back the fact that it's a Plant type, and a way to create an ad-hoc plant-type value. Probably the best way is to finalize the implementation of #192 . But I feel like this should be kept at the type level on haskell's side, and perhaps records or some kind of subtyping trick could do...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant