Skip to content

Can't define recursive or mutually recursive object types #5

@rndnoise

Description

@rndnoise

I ran into a snag when trying to define an object of type X that has a field with type X. This will not compile:

commentType :: ObjectType Unit Unit
commentType  = objectType
  "Comment"
  (Just "comment")
  { replies: Q.field' (Q.list commentType) -- "The value commentType is not defined here"
      (Just "replies")
      \_ ctx -> pure (Just []) }

It also doesn't seem possible to use Data.Lazy.fix to achieve this. However, there is a comment in graphql-91 that explains you can do this in JavaScript using a thunk, so I think another wrapper function around objectType that has the type of it's last argument as (Unit -> Record fields) might do the trick.

Metadata

Metadata

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions