Skip to content

@recurse query not fetching entire subgraph from root node #2555

@danielmai

Description

@danielmai

Bug report

This issue comes from https://discuss.dgraph.io/t/modeling-a-tree-and-getting-a-subtree-from-a-node/3087.

Desktop:

  • OS: macOS High Sierra 10.13.6 (Running Dgraph via Docker)
  • Browser: Chrome
  • Dgraph Version: v1.0.7
  • Dgraph Client: Ratel/curl HTTP

Containerization:

  • Main Container Software: Docker v18.06.0-ce
  • Integration (if applicable): Docker for Mac
  • Dgraph TAG Version: v1.0.7

Describe the bug:

Running a query with @recurse doesn't return the expected subgraph results.

Steps to reproduce the behavior:

  1. Start a new Dgraph (1 Zero, 1 Server) running with default ports accessible via localhost.

  2. Run the following mutation:

    curl -i -XPOST -H 'X-Dgraph-CommitNow: true' -H 'X-Dgraph-MutationType: json' http://localhost:8080/mutate -d '{
      "set": [
        {
          "jungle": {
            "animals": {
              "lion": {
                "name": "Simba"
              },
              "elephant": {
                "name": "Ele"
              }
            },
            "birds":{
              "parrot": {
                "name": "Zuzu"
              },
              "chicken": {
                "name": "Chica"
              }
            }
          }
        }
      ]
    }'
    

    Response:

    {
      "data": {
        "code": "Success",
        "message": "Done",
        "uids": {
          "blank-0": "0x40",
          "blank-1": "0x39",
          "blank-2": "0x3a",
          "blank-3": "0x3b",
          "blank-4": "0x3c",
          "blank-5": "0x3d",
          "blank-6": "0x3e",
          "blank-7": "0x3f"
        }
      },
      "extensions": {
        "server_latency": {
          "parsing_ns": 21640,
          "processing_ns": 10257181
        },
        "txn": {
          "start_ts": 47,
          "commit_ts": 48,
          "lin_read": {
            "ids": {
              "1": 71
            }
          }
        }
      }
    }
  3. Run this query to double-check that the data mutation inserted the data as we expected:

    $ curl -s -XPOST http://localhost:8080/query -d '{
      parent as p(func: has(jungle)) {}
    
      me(func: uid(parent)) {
        uid
        expand(_all_) {
          uid
          expand(_all_) {
            uid
            expand(_all_) {
              uid
              name
            }
          }
        }
      }
    }' | jq '.'
    

    Response:

    {
      "data": {
        "p": [],
        "me": [
          {
            "uid": "0x40",
            "jungle": [
              {
                "uid": "0x39",
                "animals": [
                  {
                    "uid": "0x3a",
                    "lion": [
                      {
                        "uid": "0x3b",
                        "name": "Simba"
                      }
                    ],
                    "elephant": [
                      {
                        "uid": "0x3c",
                        "name": "Ele"
                      }
                    ]
                  }
                ],
                "birds": [
                  {
                    "uid": "0x3d",
                    "parrot": [
                      {
                        "uid": "0x3e",
                        "name": "Zuzu"
                      }
                    ],
                    "chicken": [
                      {
                        "uid": "0x3f",
                        "name": "Chica"
                      }
                    ]
                  }
                ]
              }
            ]
          }
        ]
      },
      "extensions": {
        "server_latency": {
          "parsing_ns": 34528,
          "processing_ns": 2238479,
          "encoding_ns": 750501
        },
        "txn": {
          "start_ts": 57,
          "lin_read": {
            "ids": {
              "1": 81
            }
          }
        }
      }
    }
    
  4. Add @recurse to the me query from Step 4 and see that the query isn't the same.

    $ curl -s -XPOST http://localhost:8080/query -d '{
      parent as p(func: has(jungle)) {}
    
      me(func: uid(parent)) @recurse {
        uid
        expand(_all_) {
          uid
          expand(_all_) {
            uid
            expand(_all_) {
              uid
              name
            }
          }
        }
      }
    }' | jq '.'
    

    Response:

    {
      "data": {
        "p": [],
        "me": [
          {
            "uid": "0x40",
            "jungle": [
              {
                "uid": "0x39"
              }
            ]
          }
        ]
      },
      "extensions": {
        "server_latency": {
          "parsing_ns": 45068,
          "processing_ns": 2554408,
          "encoding_ns": 456431
        },
        "txn": {
          "start_ts": 58,
          "lin_read": {
            "ids": {
              "1": 82
            }
          }
        }
      }
    }
    

Expected behavior:

The @recurse keyword recursively get the subgraph from the root node.

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bugSomething is broken.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions