How to recurse a block

I have the following schema types:

type Developer {
  id: String! @id
  name: String! @search(by: [exact])
  issues: [Issue] @hasInverse(field: developers)
  sprints: [Sprint] @hasInverse(field: developers)
  projects: [Project] @hasInverse(field: developers)
  mergeApproves: [MergeRequest] @hasInverse(field: approvedBy)
  mergesAssigned: [MergeRequest] @hasInverse(field: assignees)
  mergesAuthorOf: [MergeRequest] @hasInverse(field: author)
  mergesOfDeveloper: [MergeRequest] @hasInverse(field: mergeUser)
  mergesReviewed: [MergeRequest] @hasInverse(field: reviewers)  
}

type MergeRequest {
  id: String! @id
  title: String!
  state: String!
  project: Project
  approvedBy: [Developer] @hasInverse(field: mergeApproves)
  assignees: [Developer] @hasInverse(field: mergesAssigned)
  author: Developer 
  mergeUser: Developer
  reviewers: [Developer] @hasInverse(field: mergesReviewed)
}

What I would like to do is a recursion to find the ‘mergesReviewed’ of a Developer and then for that MergeRequest find ‘reviewers’.

My current query is this:

{
	parentMergeRequest(func: uid("0xc421")) {
    MergeRequest.title name
		assignee : MergeRequest.assignees {
      Developer.name name
      reviewerOf : Developer.mergesReviewed {
        	MergeRequest.title
        	mergeUid as uid
        }
    }
  }
  
 	childMergeRequest(func: uid(mergeUid)) @recurse {
        title : MergeRequest.title
        reviewerUid as MergeRequest.reviewers
	}	

  reviewerFunc(func: uid(reviewerUid))  {
  	Developer.name name
  }
}

I thought this would be as simple as having the childMergeRequest func as follows:

 	childMergeRequest(func: uid(mergeUid)) @recurse {
        title : MergeRequest.title
		MergeRequest.reviewers
	}

However, no detail of any MergeRequest.reviewers nodes is returned.

What my current query returns:

Thank you in advance for any help

1 Like

Does my question make sense? Or is it that plain obvious?

1 Like

I don’t think you need a @recurse block for that. I modified your query to also traverse the MergeRequest.reviewers predicate and show the developers name.

parentMergeRequest(func: uid("0xc421")) {
    MergeRequest.title name
		assignee : MergeRequest.assignees {
      Developer.name name
      reviewerOf : Developer.mergesReviewed {
        	MergeRequest.title
        	MergeRequest.reviewers {
                        Developer.name
                }
        }
    }
1 Like

Well that only gets me the first layer. Perhaps this will help explain:

If you look at the below query:

  originalMerge(func: uid("0xc421")) {
    MergeRequest.title name
		assignee : MergeRequest.assignees {
      Developer.name name
      Developer.mergesReviewed {
				MergeRequest.title name
        MergeRequest.reviewers {
					Developer.name name
          Developer.mergesReviewed {
						MergeRequest.title name
           	MergeRequest.reviewers {
							Developer.name name
              Developer.mergesReviewed {
								MergeRequest.title name
                MergeRequest.reviewers {
									Developer.name name
                  Developer.mergesReviewed {
										MergeRequest.title name
                  }
                }
              }
            }
          }
        }
      }
    }
  } 
}

You notice the repeating block of Developer.mergesReviewed → MergeRequest.reviewers. However, I would like to have this repeating section to recurse so I don’t have to manually define the depth.

Any ideas?

1 Like

Right, then you need the @recurse block. Try adding the Developer.mergesReviewed predicate to the block so it can also be traversed:

childMergeRequest(func: uid(mergeUid)) @recurse {
        reviewerUid as Developer.name
        MergeRequest.reviewers
        Developer.mergesReviewed

}	
1 Like