Filter doesn't work

Good explanation @rajas.

And to add this use case to your list of reasons:

  1. You are filtering an edge that removes all results from a required edge.

I think the reason is better explained:

You most likely have Credentials for other Users. In your query in the top level you are getting all Credentials and then on the edge forUser you you getting a filtered set only for one User.

This throws an error because the forUser is a required edge !. You could easily resolve this by removing the ! on the line forUser: User!, but I don’t think that is exactly what you want as that would allow Credentials to be added that were not for any User. Also I think what you really want is not “All Credentials including the forUser if it is for ‘orch’”, but rather “All of the Credentials for a specific User”

So the remedy to get the data wanted without the error message is to flip the query upside down. It will get the same data. “All of the Credentials for a specific User”

{
  getUser(username: "orch") {
    username
    hasCredentials {
      accessKey
    }
  }
}

I have a feature request floating around here somewhere for this same error that would allow DGraph to remove the node throwing the error and return the data minus the error row. Essentially using @cascade(fields: ["forUser"]) (or whatever the syntax should be.)

2 Likes