Dgraph graphql - how to delete from list


(mfaiz0591) #1

Hello everyone, i tried out the latest https://graphql.dgraph.io/. Then, i encounter a problem when tried to remove from list.

the schema is:-

type User {
    id: ID!
    name: String!
    hobbies: [Hobby] @hasInverse(field: user)
}

type Hobby {
    id: ID!
    name: String!
    user: User! @hasInverse(field: hobbies)
}

add user:-

mutation {
    addUser(input: { name: "user1" }) {
        user {
            id
            name
            hobbies {
                id
                name
            }
        }
    }
}

result:-

{
  "data": {
    "addUser": {
      "user": {
        "id": "0x20",
        "name": "user1",
        "hobbies": []
      }
    }
  },
  "extensions": {
    "requestID": "a9170e7b-ffc3-4b3a-941c-01c059bdecb2"
  }
}

add hobby to user:-

mutation {
    addHobby(input: { name: "hobby1", user: { id: "0x20" } }) {
        hobby {
            id
            name
            user {
                id
                name
            }
        }
    }
}

result:-

{
  "data": {
    "addHobby": {
      "hobby": {
        "id": "0x23",
        "name": "hobby1",
        "user": {
          "id": "0x20",
          "name": "user1"
        }
      }
    }
  },
  "extensions": {
    "requestID": "e169ce99-75ec-425f-a0ad-5f7450cd88a0"
  }
}

then, delete back hobby:-

mutation {
    deleteHobby(filter: { ids: ["0x23"] }) {
        msg
    }
}

result:-

{
  "data": {
    "deleteHobby": {
      "msg": "Deleted"
    }
  },
  "extensions": {
    "requestID": "fb3dda46-da25-46ec-96c9-2c49e06eec7b"
  }
}

get back user data:-

{
  "data": {
    "getUser": {
      "id": "0x20",
      "name": "user1",
      "hobbies": [
        {
          "id": "0x23",
          "name": null
        }
      ]
    }
  },
  "extensions": {
    "requestID": "4af226a7-5b1c-47b7-b6ee-216ebf990a3a"
  }
}

as we can see, the hobby object remain in the user’s hobbies list. is this intended behaviour?

im actually expecting the result to be like this:-

  "data": {
    "getUser": {
      "id": "0x20",
      "name": "user1",
      "hobbies": []
    }
  }

so, is this possible to be done using dgraph graphql or not?
hope you guys can give me input on this matter. thank you


(Shekar Mantha) #2

Hi,

Thank you for the post. I will assign an engineer to look at this issue and try and get you a resolution promptly.


(Michael Compton) #3

Hi thanks for the detailed question.

There’s a couple of loose ends around mutations. Unfortunately, you’ve bumped into one of them. It should work as you suggest and will do within the next week or two - and definitely when we release GraphQL in an upcoming Dgraph release.

@Shekar there’s already a card on the board for this issue.


(mfaiz0591) #4

@michaelcompton @Shekar
Hi, thank you for replying to my question.
Im glad to hear that this problem will be fixed. Looking forward to the update :+1::+1: