Skip to content

GraphQL should allow updates of multiple relational levels. #5815

@martaver

Description

@martaver

Steps to reproduce the issue (command/config used to run Dgraph).

Using slash graphql, given the schema:

type Player {
  id: ID!
  title: String! @search(by: [fulltext])  
  parent: Player
  children: [Player] @hasInverse(field: parent)
}

Create a tree of Players, with parent/children edges. Let's add a root Player with two child Players:

mutation {
  addPlayer(input: [
    {
    title: "root",
    children: [
      {
        title: "A"
      },
      {
        title: "B"      
      }
    ]
  }
  ]) {
    player {
    	id
      title
      children {
      	id
        title
    	}
  }
  }
}

Now, I have a UI component in the front-end that can manipulate the tree, and I want to move the Player B to be a child of Player A. It restructured the tree, and gives me a new hierarchy, which I want to push to dgraph.

mutation SetPlayerTree($id: ID!, $children: [PlayerRef]) {
    updatePlayer(input: {
        filter: {
            id: [$id]
        }
        set: {
            children: $children
        }
    }) {
        player {
        id
        children {
            id
            children {
                id
            }
        }
    }
    }
}

With vars, where B has now been moved to be a child of A (replace the ids with whatever you got from your last query):

{
  "id": "0x4e22",
  "children": [{"id": "0x4e25", "children": [{"id": "0x4e26", "children": []}]}]
}

Expected behaviour and actual result.

I would expect the response to return the hierarchy root -> A -> B, however it returns root -> [A, B]:

{
  "data": {
    "updatePlayer": {
      "player": [
        {
          "id": "0x4e22",
          "children": [
            {
              "id": "0x4e25"
            },
            {
              "id": "0x4e26"
            }
          ]
        }
      ]
    }
  },
  "extensions": {
    "touched_uids": 17,
    "queryCost": 1
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/graphqlIssues related to GraphQL support on Dgraph.status/acceptedWe accept to investigate/work on it.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions