Skip to content

Referencing a object inside its own initializer, is there any problem? #178

Answered by hayes
wfelipe99 asked this question in Q&A
Discussion options

You must be logged in to vote

Just split up the ref and implement into 2 statements.

const ForumObject = builder.objectRef<Forum>('Forum');

ForumObject.implement({
  fields: (t) => ({
    ...
    children: t.field({
      type: [ForumObject], // << referencing its own
      nullable: true,
      resolve: async (parent) => await db.forum.findUnique({ where: { id: parent.id } }).children(),
    }),
    ...

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@wfelipe99
Comment options

Answer selected by wfelipe99
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants