Dgraph graphql - how to delete from list

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

1 Like

Hi,

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

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.

@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:

An update on this issue would be awesome.
I noticed that on version v21.03.0 (dgraph/standalone) the issue is different but seems to be kind of related.
Based on the above example I can delete the Hobby easily, but once I’ve done so and query for Users the list is not empty but contains null values like this:

{
  "data": {
    "getUser": {
      "id": "0x20",
      "name": "user1",
      "hobbies": [
        {
          "id": "0x25",
          "name": "testid to show that other hobbies are displayed"
        },
        null
      ]
    }
  },
}

(which also throws this exception *“Non-nullable field ‘id’ (type String!) was not present in result from Dgraph. GraphQL error propagation triggered.” as my hobby id would look like this “id: String! @id)

1 Like

Interesting. Are you able to resolve this?
I am able to get the correct response on v21.03.0 (dgraph/standalone) using above given schema , query/mutations.
can you give the reproducible steps?

I am not sure if I should be happy or afraid :confused: .
I tried to reproduce the steps that I took with my more complex setup, but now everything works fine.
I now assume that it had something to do with my middleware, where I fixed a lot of bugs in the meantime. So not an issue of dgraph :smiley: .

1 Like

This topic was automatically closed after 6 days. New replies are no longer allowed.