I’m trying to implement a GraphQL custom resolver using DQL to recurse nodes (as I believe so far is the only way to have recurse feature in GraphQL).
However it is just returning only the first child node. If I run same code in DQL it works correctly. I tried to follow custom resolver guidelines in the docs, but no success. I’ve also tried to find similar question or references for this but couldn’t find any.
Info:
Dgraph v21.12.0, Deployed in kubernetes with dgraph/dgraph docker image.
Schema added to /admin/schema :
type TestDto @generate(
query: {
get: true,
query: true,
password: false,
aggregate: true
},
mutation: {
add: false,
update: false,
delete: false
},
subscription: false
) {
mrId: String! @search(by: [hash])
targetObjects: [TestDto]
}
type Query {
queryTestDtoSubtree(mrId: String!): [TestDto] @custom(dql: """
query q($mrId: string!) {
var(func: eq(TestDto.mrId, $mrId)) @recurse(depth: 300, loop: false) {
descendants as TestDto.targetObjects
}
queryTestDtoSubtree(func: uid(descendants)) {
mrId: TestDto.mrId
}
}
""")
}
Mutation (will create tree as as mrId: mynodeid1 → mrId: mynodeid2 → mrId: mynodeid3)
{
set {
_:x <TestDto.mrId> "mynodeid1" .
_:x <dgraph.type> "TestDto" .
_:y <TestDto.mrId> "mynodeid2" .
_:y <dgraph.type> "TestDto" .
_:z <TestDto.mrId> "mynodeid3" .
_:z <dgraph.type> "TestDto" .
_:x <TestDto.targetObjects> _:y .
_:y <TestDto.targetObjects> _:z .
}
}
GraphQL query using custom resolver:
{
queryTestDtoSubtree(mrId: "mynodeid1") {
mrId
}
}
Returns only first child node:
"queryTestDtoSubtree": [
{
"mrId": "mynodeid2"
}
]
But if run similar query with DQL:
var(func: eq(TestDto.mrId, "mynodeid1")) @recurse(depth: 300, loop: false) {
descendants as TestDto.targetObjects
}
queryTestDtoSubtree(func: uid(descendants)) {
mrId: TestDto.mrId
}
returns recursive results correctly:
{
"queryTestDtoSubtree": [
{
"mrId": "mynodeid2"
},
{
"mrId": "mynodeid3"
}
]
}
Maybe there is limitations with recurse in GraphQL?
Or maybe I’m missing some directive or formatting?
Thanks!!
Cristiano.