Connecting all nodes

Hello everyone, I have the following structure (schema):

uri: string .
        domain: string .
        created_at: datetime .
        references: [uid] .
        root: bool @index(bool) .

My task is to get one graph where all available nodes would be connected and come from one root node.
I am using the following query:

{
  results(func: has(uri)) @recurse(depth: 1000, loop: true) {
    uid
    root
    uri
    references
  }
}

With such a request, I get many graphs with their “references”, but I would like all of them to be connected into one.
What is the best query for this? And is this possible with the current structure?

I can’t see your structure based on the schema or the query. I think you should have a “root” entity that is a parent of all the others. Show a JSON format of your structure.

[
{
"uid": "_:https://google.com/",
"references": [
            {
                "uid": "_:https://youtube.com",
                "uri": "https://youtube.com",
                "domain": "youtube.com",
                "root": false
            }, 
            ...
],
"uri": "https://google.com/",
"domain": "google.com",
"root": true
}, 
...
]

I get I need a graph if my structure is hierarchical, but is it possible to make it have such a structure?

I still don’t get it right, but answering your question. Anything is possible in Graph DBs. The problem is to understand our needs and fit this in the Query lang.

Following your JSON. I would say that this query bellow is okay.

{
  results(func: has(root), first: 1) @recurse(depth: 1000, loop: true) {
    uid
    uri
    references
    domain
  }
}

But it would be better to have a target instead of using has func.

results(func: eq(domain, "google.com")) @filter(has(root)) @recurse(depth: 1000, loop: true) {

So, in this case, "google.com" will be a unique node on your graph view, and the nodes on the edge “references” will be its children. Is that what you wish?

I apologize, I do not speak English very well, so I can not explain myself clearly.
This is almost what I need, but with such a request, I only get the children of the root node, and I also want to get the children of the children, etc. I got the result I wanted when my data structure was hierarchical, but it was no longer possible to use it, so I had to switch to a linear structure, the example of which I gave above.
Perhaps, to make it clearer, I need a graph of links in which I could calculate pagerank.
Below I attach the result of your query, where only the root node has children, but not its children:Снимок экрана 2020-09-09 в 22.44.41

humm, so you wanna a tree on the Graph view. Feels like this is an issue with Ratel right? Can you share the result (the JSON one) from this PrintScreen?

Recurse can give you the nested children, but I think Ratel isn’t showing it. Not sure. Your data result should clarify.

Json looks like the graph view :frowning:

Do these entities have references too?

yes

I will review your issue again.

I partially understand that, you want to make a query that will show “dangling nodes” and then connect them later to a “root” node? In that case, you could do this using Upsert Block. But you need to create constraints. To not end up connecting absolutely everything on the same “Root”.

Yeah, this phrase seems to corroborate with my assumption.

No problem at all. I also do not speak very well.

This seems to be a second thing. It seems to me that you want a query that returns a tree, but to have a tree all entities need to be connected by an edge. Otherwise, there is no relationship.

So, you need edges that interconnect them.

Is it using another edge? cuz if it was the edge “reference” it would appear as a child of a child of a child(nesting).