Skip to content

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

Open
@theobat

Description

@theobat

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...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions