Children of node not available in lambda field resolver

Hi,
I’m new to Dgraph and have an issue with getting the values of a relationship. I want to count the amount of children a node has in a lambda function (I know that this is possible without lambda, but this will later be extended with another calculation based on that count) but the children of my node are not available via the parent parameter.
Is this by design and is there a way to achieve this without using graphql/dql in the resolver function?

Thanks!

It’s a bit hard to say what you are trying to achieve without an example. I assume you have something like this

type Parent {
  id: ID!
  children: [Child!]!
}

type Child {
  id: ID!
}

If you want to extend the feature of aggregate queries, you might want to look into custom field resolvers, which give you access to the parent node.

A custom field example could look like so

type Parent {
  id: ID!
  children: [Child!]! @lambda
}

type Child {
  id: ID!
}

and in your lambda

const children = async ({parent: {children}}) => {
  // do some math
  return number;
}

self.addMultiParentGraphQLResolvers({
    "Parent.children": children
})

Hope this helps! :raised_hands:

1 Like