Selective drop data for a certain type

I have a bunch of types in my GraphQL schema, and I want to drop the data for one of those types to aid with my testing. There’s currently no way to do that.

Perhaps, this can be part of the visual schema editor.

1 Like

Sure there is :wink:

Say your type is User

mutation {
  deleteUser(filter: {}) {
    numUids
  }
}

Just pass an empty filter and it will delete all. Figured that out today actually.

4 Likes

Haha… that’s a nice trick too. It could run into problems at scale, but for smaller datasets it should be alright.

@michaelcompton do you limit the number of results on deleteType with empty filter?

Still, I think it should be part of the UI. I doubt most people would realize it on their own.

2 Likes

It could end up very bad too. Say a user who has access to delete data accidentally forgets to finish that filter before submitting the mutation. I would like this to be closed and error out and an actual drop all mutation somehow specifically

I think there’s two separate things here: one is adding a bit more functionality around schema updates (as mentioned in other posts), dropping data, removing a type, etc, and the other is a nice UI for that in Slash.

I think we’ll add some drop data options to /admin soon. I’d also like to have some other schema and data management bits in there. For example, there’s a difference between what my app users can do, and what I can do as the developer/admin, so I’d like some data management available through /admin. Maybe that could be a place where you could manage a type and all it’s data as a whole. I started an RFC around schema updates before I went on holidays. It’s worth finishing that off and maybe broadening the scope to include some other parts of data/schema management.

(side note: there’s no restrictions if you state deleting everything - that ends up as just a query on the type and delete what you find.)

One more thing that’s now coming up. I created a Stream: [String], then realized that I actually just need a string, no need for a list. So, I tried to change it to String, and I’m getting this error.

resolving updateGQLSchema failed because succeeded in saving GraphQL schema but failed to alter Dgraph schema - this indicates a bug in Dgraph schema generation. Please let us know : Issues · dgraph-io/dgraph · GitHub. Don’t forget to post your old and new schemas in the issue description.: Type can’t be changed from list to scalar for attr: [Tweets.stream] without dropping it first.

Now it has become even more important to allow dropping a field altogether.

Btw, can we remove all the URLs in error messages – it’s a bad idea. @pawan @vvbalaji

3 Likes

Yep, just like this:

2 Likes

Yes, there is a PR for this which would be merged to master today after CI passes.

1 Like

I’ve added this to a backlog. I’d assume you would like to drop

  1. A type
  2. An unused field in the type

We had to come up with this because the graphql endpoint kept refusing to delete our data in bulk for a given type.

Here is DQL for dropping a type. For illustration the type here will be Comments.

upsert {
  query {
    comments as var(func: eq(dgraph.type, "Comments"))
  }
  mutation {
    delete {
      uid(comments) * * .
    }
  }
}

Make sure you send it to the /mutate?commitNow=true endpoint as described in https://dgraph.io/docs/slash-graphql/advanced-queries/

2 Likes