How can I clear a list field?
Schema:
type Foo {
items: [String!]!
}
I want to delete all items from that list without the need to reference them explicitly.
How can I clear a list field?
Schema:
type Foo {
items: [String!]!
}
I want to delete all items from that list without the need to reference them explicitly.
This should do the job
{
"set": [
{
"test_list": ["a", "b", "cd"]
}
]
}
{
delete {
<0x9c69> <test_list> * .
}
}
where 0x9c69 is the uid of insert mutation.
Thank you. I don’t want to use dql though.
{
"delete": {
"uid": "0x9c6a",
"test_list": null
}
}
According to docs
All edges for a predicate emanating from a single node can be deleted at once (corresponding to deleting S P *
):
Again, thank you.
But I think you miss the point here. I’m asking about GraphQL not DQL
You mean the generated HTTP GraphQL API?
yes.
It should be:
mutation {
updateFoo(input: {
filter: { has: items }
remove: { items: null }
}) {
numUids
foo {
items
}
}
}
But that is currently erroring out with
mutation updateFoo failed because Dgraph execution failed because Got unsupported type for list: Foo.items
What is working is set it to a single item being an empty string:
mutation {
updateFoo(input: {
filter: { has: items }
remove: { items: [""] }
}) {
foo {
items
}
}
}
Interestingly though, if you are using enums, you cannot provide an empty string, hence no way to remove all without specifically providing all possible values. Alternatively, you could create a custom mutation to do this with lambda and DQL, but that seems out of place for something that should be basic CRUD.
I remember that in the past this mutation would completely delete the corresponding field. I.e. afterwards items
was set to null
(although this is not possible as per schema definition).
Anyhow, thank you for pointing out that is is a bug. I agree.
What’s the difference between that and this? :
mutation {
deleteFoo(filter: { has: items }) {
msg
foo {
items
}
}
}
I thought remove just removed the link, not the actual nodes?
J
In the OP, the items
are not edges to nodes, rather they are string predicate values in a list. In your code, you are deleting the entire node whereas the OP is about deleting a predicate list from a node while keeping the node itself. This would have been clearer if the example was not so minimal and Foo had other predicates/edges
Is this bug being tracked?
I’m trying to update the a list as you suggested here, but I got this error
In my case, Foo.items is a list of another type, something like this:
type Foo {
items: [FooItem!]
}
type FooItem {
bar: String
baz: String!
}
@mrjn @chewxy @aman-bansal @dmai
Can we have an update on this (and all the other bugs pointed out in the forum) ?
Seriously, it’s getting really annoying. No updates on any GraphQL bugs from your side since 7 months. Is Dgraph dead and should we switch to other databases with active development instead?
I know this might not be the place, but I also want to put pressure on the general state of transparency about development. I’ve been jumping back and forth about choosing DGraph, because I really don’t see what is currently worked on in terms of Dgraph features and bugs. This has been stated in the Roadmap Post as well.